This is pretty cool!
Monthly Archives: February 2019
100 Days of Swift
Paul Hudson (@twostraws) is hosting a 100 Days of Swift in which he provides short videos, quizzes and assignments to walk you through an introduction to Swift. He actually started some time ago, I think on Feb 1, 2019, but I’m just getting started now and have completed Day 4!
In Day 1, we covered the following topics:
- Variables – test
- Strings and integers – test
- Multi-line strings – test
- Doubles and booleans – test
- String interpolation – test
- Constants – test
- Type annotations – test
- Simple types: Summary – test
In Day 2, we covered the following topics:
- Arrays – test
- Sets – test
- Tuples – test
- Arrays vs sets vs tuples – test
- Dictionaries – test
- Dictionary default values – test
- Creating empty collections – test
- Enumerations – test
- Enum associated values – test
- Enum raw values – test
- Complex types: Summary – test
In Day 3, we covered:
- Arithmetic Operators – test
- Operator overloading – test
- Compound assignment operators – test
- Comparison operators – test
- Conditions – test
- Combining conditions – test
- The ternary operator – test
- Switch statements – test
- Range operators – test
- Operators and conditions summary – test
In Day 4, we covered:
Exec-php WordPress Plugin and PHP 7 Fix
I recently upgraded the version of PHP used on our hosting service to 7.1, as the Elementor plugin requires at least version 7 to run now. This had the side effect of breaking the Exec-php plugin (version 4.9) I use to allow PHP code to run in posts and pages. It manifested itself with the following error message:
Parse error: syntax error, unexpected ‘new’ (T_NEW) in
It appears you can no longer assign a class in PHP version 7 using the ‘&’ symbol and Exec-php makes extensive use of this. Here’s an example:
$GLOBALS['g_execphp_manager'] =& new ExecPhp_Manager();
I went through all of the instances and removed the & symbol using BBEdit and it now runs correctly.
Thanks to the CodeCave blog for this insight!
Using Python to Calculate Transmission Probabilities for Multilayer Structures
I’m currently taking the second Quantum Mechanics for Scientists and Engineers course online from Stanford. They are both great courses taught by David Miller. The second course is looking more at applications and the third week’s topic was optical absorption by semiconductors.
Once we worked through all the physics and algebra, it was presented that these types of calculations are very easy to code and Professor Miller provided a program to calculate the transfer matrix and transmission probabilities for multilayer structures. The code he provided was for Matlab (and also for Mathcad). I have Octave, basically an open source version of Matlab, running on my Mac, so I was able to run the code provided. Mathcad is only available on Windows and installing Octave on a Mac can be a bit cumbersome, so I wanted to create a solution that could easily be run on any platform and work on my Python coding skills, which are pretty dismal.
It took a couple of days to port the Matlab code to Python but I got it running, the challenge being complex numbers in Numpy. Then a little more time to figure out Jupyter Notebooks, as my original code ran straight Python on my desktop. Here’s a link to my notebook running on Google’s Colaboratory:
https://colab.research.google.com/drive/1aMV8ZYSfhraMMVnF_KiVhHFJXnMzWZnN
This link is view only, but you can easily download the code and run it in your own notebook, which will allow you to change the parameters, like the potentials, effective masses, etc. If you do run this one, you should get a graph that looks like this:
I did not attempt to make the code as efficient as possible, the goal was simply to get it to work. Comments and feedback are welcome.