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:

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.

Setting the To value: cell in Excel’s Goal Seek to a Cell Reference

Sadly, it took awhile to “figure” this out. I was trying to solve a set of equations in Excel. I had one equation in one cell, say B1, that had a dependency on the value in A1. I had the second equation in cell C1 that also has a dependency on A1. I wanted to set cell B1 equal to CELL C1 by changing cell A1. You can’t do this with Excel’s Goal Seek feature, the To value: has to be a number.

The solution of course, was to create a third cell, D1, with the formula “= B1 – C1”. When those two cells are equal, as I wanted, D1 = 0. So now you can ask Goal Seek to solve the set of equations by setting cell D1 to value 0 by changing cell A1.

Yay!

pydotplus on macOS

I’ve been playing around with SciKit-Learn’s decision tree regression function. In one of the examples I was working on, they provided a demo script to print out a jpg of the decision tree. Cool! Unfortunately, my system didn’t have pydotplus installed. I’m using Anaconda, so issuing the following command took care of that issue:

conda install -c conda-forge pydotplus

However, when attempting to run again, this produced and error stating that the GraphViz executable could not be found. Ugh. Luckily, a quick trip to Homebrew took care of that issue:

brew install graphviz

Voila!

Move to Trash Deletes Immediately

I had this issue when I first updated to macOS Mojave. To solve it, I performed the following command in Terminal:

sudo rm -Ri ~/.Trash
[enter your password]

Then, Log out. Log back in. Move to Trash now works as expected.
Note: You can implement Delete Immediately… by holding down Option-Command-Delete.

NBA 2018 Bracket

Okay, the NBA bracket challenge has a horrible interface! As a reminder for future years, don’t use this! Go with ESPN or someone else. Having said that, here’s my NBA bracket. I think it shows my picks except for the Blazers, who got their asses swept by the Pelicans, so zero points there! Amazing that was the series with a sweep.

Go Warriors!