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:

  1. Variables – test
  2. Strings and integers – test
  3. Multi-line strings – test
  4. Doubles and booleans – test
  5. String interpolation – test
  6. Constants – test
  7. Type annotations – test
  8. Simple types: Summary – test

In Day 2, we covered the following topics:

  1. Arrays – test
  2. Sets – test
  3. Tuples – test
  4. Arrays vs sets vs tuples – test
  5. Dictionaries – test
  6. Dictionary default values – test
  7. Creating empty collections – test
  8. Enumerations – test
  9. Enum associated values – test
  10. Enum raw values – test
  11. Complex types: Summary – test

In Day 3, we covered:

  1. Arithmetic Operators – test
  2. Operator overloading – test
  3. Compound assignment operators – test
  4. Comparison operators – test
  5. Conditions – test
  6. Combining conditions – test
  7. The ternary operator – test
  8. Switch statements – test
  9. Range operators – test
  10. Operators and conditions summary – test

In Day 4, we covered:

  1. For loops – test
  2. While loops – test
  3. Repeat loops – test
  4. Exiting loops – test
  5. Exiting multiple loops – test
  6. Skipping items – test
  7. Infinite loops – test
  8. Looping summary – test

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:

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.