## Tuesday, January 12, 2016

### Displaying python output with GeekTool

Living in Michigan, we are often hit with snow storms that cause us conditions to be too dangerous for driving to school.  These 'snowdays' are great, and every morning when the possibility of a snowday is present, I will often find myself checking our local news website to see if our schools name appears.  This often involves refreshing the website every few minutes (or even seconds! #fingercrossed) during the crucial minutes before I need to take a shower and get in the car or get back into bed.

So the other day when I was doing some web-scraping programming, the idea occurred to me to automate this process, so that I don't have to keep pressing refresh.  So I wrote a little python program that opened up the website, searched the html code for Kent county schools, and outputted the results.  This was the hard part, and one I'm not prepared to fully explain today.

Once I got the program printing what I wanted, I opened up GeekTool.  GeekTool is a mac program that allows you to display words, bits of code, website data, computer data, images, etc. on the background of your desktop.  You'll have to see for yourself various things it can do.

Anyhow, creating a shell geeklet with the following code will cause that python program to run and its output to show up on the computers desktop:
python ~/Documents/script/webscraper.py
In this case, webscaper.py was the name of the program I created -- but you could put the name of any python program there. Then one of the options you can set in GeekTool is how often this program refreshes itself, so I set mine for 60sec. The results:
For a half-hour this morning I sat and read the Bible, sipping coffee, and every 60secs or so looked up and watched as the list populated itself and grew automatically.  And, since you're reading this, eventually I did see my school's name pop up.  Unfortunately, the coffee had done its work and I couldn't fall back asleep.

By the way, the picture of the radar was also self refreshing -- every 300 seconds (5 minutes) GeekTools would fetch the image url, download the image and update my background.

Apart from being able to be lazier than normal on a snowday morning, I will say there was an additional benefit to all this work.  By fetching it this way, I actually found out about my snowday 2 minutes faster than I would have otherwise (we receive text messages from remind), and my background was always a few schools ahead of the website the normal way through a browser and many schools ahead of perusing the website through their mobile app.

Next steps are to get my computer to check for my school, and automatically turn my alarm on/off based on whether the name shows up....

### Accessing Python Functions in Quicksilver

Over the last two years, I have been programming a lot with Python.  I have developed a lot of functions to do various mathematical tasks. For instance, I have a function that takes a number and spits out a list of its factors:
factors(30) = [1, 2, 3, 5, 6, 10, 15, 30]

And I have another that gives me the prime factorization of a number:
primefactorization(400) = [2, 2, 2, 2, 5, 5]

These have been very helpful as I have created other programs, and as I have participated in the EulerProject -- a set of mathematical challenges that typically require the user to create a program that helps solve them.  As I try to complete more and more challenges, my collection of useful functions grows and grows.

Recently, I have tried to find a way to access these functions more quickly.  Previously, I would have to find them in the correct program file, open it up, tweak it a little bit to call the function with the specifics of what I was looking for, and then run the program.  Annoyingly many steps, in my opinion, and usually hard enough to deter me from using my own work and find an answer another way, or give up entirely.

However, I found a way to use Quicksilver to access these functions, inspired by a friends QuicksilverPythonTodoList program. He uses Quicksilver, as I do, to easily find and open programs and files on the mac, to move and copy files, to create qr codes, to search google, and many other things.  And he uses it to call up a python program and add items to a todo list by a simple keyboard command.  By pressing Cmd-Space, period, typing his todo item, pressing tab, and enter, quicksilver automatically opens up the correct python program, enters in the correct input, the python script runs which updates a text file, which is automatically saved and displayed on his background via GeekTool. All in the background, instantly (practically), at the press of a few simple buttons.  I wanted that too, for my mathematical functions.

So I gathered all my functions into one python module which I called euler.py and reading Brian's post on adding custom actions to quicksilver I set out to enable this for myself.  It took three steps, which I'll outline for you if you're interested yourselves:

Step 0: Install quicksilver and learn how to use the period to enter text entry mode
1. Create a python module that has any desired functions all in one place.  Take note of the file name and path as you will need it later. Mine was ~/Documents/script/euler.py
2. Use terminal to access that file and call up a function.  I had to use a -c switch with python to access my functions.  Something like:
python -c "import euler; print euler.factors(30)"
This is essentially a two-line program that imports my list of functions, and calls one of them specifically.
3. Write an applescript file that calls this terminal command.  In order for quicksilver to recognize it, you'll need to save this applescript file in ~/Library/Application Support/QuickSilver/Actions and then restart QS.  I created an applescript named DoMath.
Now I can access my files by the following keystrokes:
cmd space, period, type my functions name, tab, type domath, enter.

Having a heavy interest in cryptography, I also took many of the functions I wrote to encipher and decipher messages and set it up to be done the same way.  So now:
cmd space, period, CaesarShift("hello world") tab encoder instantly produces Khoor zruog.

I have one improvement I'd like to do -- but not sure how to quite yet.  I'd like to be able to have it save the results to the clipboard automatically.  I'm sure that's possible with an additional tweak of the DoMath and Encoder applescripts -- but that's a learning project for another day.

## Wednesday, June 24, 2015

### Factoring Puzzles

Here are a few examples of factoring puzzles:
Here's the same set up for factoring a trinomial.

Factoring with a > 1 is not much harder, when students remember to find factors of ac that add up to b. Those become the insides of this table, and factoring out GCF's leads to the outsides, and the final factors.

Worksheet - Table Puzzles (Multiplication)
Worksheet - Table Puzzles (Factoring)

My recorded lessons for these ideas can be found here:
Lesson 5a: Factoring Quadratic Expressions into Binomials
Lesson 5b: Table Puzzles (and Dividing Polynomials)
Lesson 5c: Factoring Trinomials

## Friday, June 12, 2015

### Inserting mathematical equations using Latex into Blogger posts

To enter in equations in Blogger posts, try copying the following code into HTML mode at the beginning of your post:

<script type="text/x-mathjax-config">   MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\$','\$']]}}); </script> <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"> </script>

Then switch to compose mode and you can type equations using latex surrounded by single dollar signs and the equations will display properly when published.  For instance, I typed the following:

  Einstein's famous equation was $E=mc^2$.
The definition of a derivative is $\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$.
The definition of a derivative is $$\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$$



And this is what displayed:
Einstein's famous equation was $E=mc^2$.
The definition of a derivative is $\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$.
The definition of a derivative is $$\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$$

It appears single dollar signs are for inline equations and double dollar signs are separate centered equations.

I am not an expert in latex, blogger, or html.  I published this article more for my own future reference then as an instruction manual for everyone else, so you can complain in the comments that it didn't work for you if you'd like, but I'm not going to be able to help you fix it.  I learned this information primarily through Steve Holden's Blog.

## Tuesday, December 30, 2014

### New Years Goals Jar

It's that time again!  During the last week of last year, my wife and I set up a bowl and a set of papers similar to the picture above.  Then, any time during the week that either of us had any inspiration, dreams, or goals for things to accomplish during the year, we wrote them down. On New Years Day (or sometime close to then) we had a date night and read through all of them together.  Some of them were simple, some were outrageous, some were jokes, some quite serious.  It was a great hour of conversation (in Burger King... classy I know!).

Here are a few of the goals we set at the beginning of last year that we've met (or attempted) as a result of our conversation that day:
• Budget each month: It has been so helpful to come together twice a month to get on the same plan about money. As a month comes to a close, we are able to look at what we've spent or not -- save for Christmas, etc. Without this, it would have been impossible to...
• Buy a bed for the girls room
• Send out Christmas Cards
• Buy a freezer to have freezer-meals (didn't quite accomplish, but should occur early in 2015)

• Create a CD: One of my favorite accomplishments of 2014 was finally recording a CD of my own music, written for our church. By using garage band, I was able to layer together several tracks worth of vocals and guitars and self-produce the CD: Oaks of Righteousness, which you can download for free.

• Concert:  Another goal of ours was to host a concert of our favorite family-oriented songs, which we were able to do in July. Belding offered us a spot on their Thursday night "Music in the Park" series, where we were able to perform a set of country songs.

• Start Recycling
• "Bread"-ruary:  Our initial dream was to simply go one month with only creating fresh bread - not buying any. After successfully going through February, we continued on into March, and now ten months later, still make our own bread each week. I don't think it's saved us any money, but it sure tastes good, and with an electric Breadmaker, it's not time consuming either.
• Have a garage sale
• Not have another kid (YET): I hesitated to even include this, but with couples all around us expecting in 2015, and this being such a publicly stated goal in our small groups and circle of friends, I was afraid if I left it out people might think we were making an announcement or something.  The exact wording of the goal was "Enter and leave 2014 with two kids", a sort of joke that we wouldn't lose any kids along the way either.  I'm happy to say that despite Carrie picking up more hours at the library and also 8 hours a week at church, I haven't lost any kids in the extra hours of daddy-daughter time.
Granted, there were some goals on the list that haven't been accomplished. They won't automatically become goals for next year, as I think it's important to reevaluate and dream again.  But overall, the process of dreaming together as husband and wife was valuable last year, and one we are planning to do this year too.  Eventually, I hope the whole family will get involved too.

What do you hope to accomplish in 2015?

## Monday, December 29, 2014

### Physics of Bandaloop Dancer

The other day, I was shown a video of one of the most exciting looking things I've seen in some time:

The group of dancers is called Bandaloop and among other things, they dance on the sides of buildings and cliffs by being attached via rappelling ropes. The long ropes keep them from falling, and allow them to make incredible leaps with long hang times.  A video interviewing the founder says some days, from tall buildings, she can get jumps with hangtimes of 9 seconds or more.

My first reaction to the video was "WOW! I wanna do that!".  My second reaction was "What's the physics behind that?  Nine second hangtimes? Really?!"

Since I can't try that anytime too soon, I must instead attempt to describe the physics behind them. Here are the pictures I drew on the side of the napkin:

I didn't have lots of data to go on, so I initially estimated that the Length of the ropes (L) might be approximately 30m, and if harnessed at the center of the body, that puts x at approximately 1m.  At best jump, I estimated approximately 5m out from the building. Since the sin of the angle θ is x/L, the inverse sine of 1/30 and 5/30 suggests that θ ranges between 2 to 10 degrees. At angles this small, sin(θ) and tan(θ) are nearly identical, suggesting that y and L are nearly identical too, and I'll be interchanging them occasionally. This is not true as the rope gets smaller -- so relatively tall buildings and tall cliffs are important.

Next I drew a free body diagram of the forces acting on the dancers as they are away from the building.  There are primarily two forces acting on the dancer -- Weight pulling the dancer down, and tension in the ropes pulling the dancer at angle θ up and in toward the building.  That angled force I broke into components Tx acting in towards the building, and Ty acting to counteract the dancers weight.  Because the ropes are so long, the height of the dancer doesn't change significantly, and since the dancer isn't really moving much vertically, we can say that the forces are balanced vertically.  That is, W = Ty. Since W = mg, this means Ty = mg.

Horizontally, the forces aren't balanced, and so whenever the dancer is in the air, there is a portion of the tension Tx which acts to pull the dancer back in toward the building. This unbalanced force is a net force, and so we can write another equation: Fnet = Tx. Since Fnet = ma, this means Tx = ma.

Finally, Tx and Ty are related to the angle by the tangent relationship, such that tan(θ) = Tx/Ty, and after multiplying, Tx = Ty*tan(θ).

After a few substitutions and a little division, we find a formula for the acceleration inwards toward the building that the dancers feel:
\begin{align*} T_x &=T_ytan(\theta ) \\ \frac{ma}{m} &= \frac{mgtan(\theta)}{m} \\ a &= tan(\theta)*g \end{align*}
It's surprisingly simple and clean -- the acceleration the dancers feel is just a multiple of gravity. Since θ ranges from 2 to 10 degrees, the dancers feel acceleration toward the building ranging between approximately 1/30th to 1/6th that of normal gravity.  For comparisons sake, the acceleration of gravity on the moon is about a 1/6th of that on earth, which according to my rough estimates is about the most that the dancers would feel inward toward the building on their most extreme jumps. Most of the time they are just a meter or two away from the the wall they are feeling much lower attraction toward earth.

Put another way, the dancers feel approximately 1/30th of their "weight" inward toward the wall, so a 120lb dancer might feel only 4 lbs of forces inward. Imagine how easy it would be to jump if you only weighed 4 lbs, but had the strength of a professional dancer!

Which suggests a different approach to this problem. Let's figure out how far out from the building a dancer ought to be able to get, assuming they can jump "off the wall" with as much speed as they can normally jump off the ground.... Assuming that a person can normally jump to a height of 0.5 meters under typical gravitational acceleration of -9.8 m/s/s, we can use the "no time" formula:
\begin{align*} v_f^2 &= v_0^2+2a(\Delta s) \\ 0 &= v_0^2+2(-9.8)(0.5) \\ v_0 &= \sqrt{2(9.8)(0.5)} &\approx 3 m/s \\ \end{align*}
They would have to jump at a velocity of approximately 3 m/s, yielding a hang time of approximately:
\begin{align*} v_f &= v_0-at \\ -3 &= 3-(9.8)t \\ t &= \frac{-6 m/s}{-9.8 m/s^2} &\approx .6 sec \\ \end{align*}
Leaping with the same initial speed (3 m/s) off the side of the building with an acceleration of 1/6th of gravity as these dancers feel would allow them hang times of 6 times as much:
\begin{align*} v_f &= v_0-at \\ -3 &= 3-(\frac{9.8}{6})t \\ t &= \frac{-6 m/s}{\frac{-9.8}{6} m/s^2} &\approx 3.7 sec \\ \end{align*}

Not quite the 9 seconds claimed in the video, but more on that later.  Substituting half of this time (because the maximum height occurs halfway into the trip) into the kinematics equation allows us to calculate the maximum "height" off the buildings this dancer could reach:
\begin{align*} s_f &= s_0+v_0t+\frac{1}{2}at^2 \\ s_f &= 1+3(1.75)+\frac{1}{2}(\frac{-9.8}{6})(1.75)^2 &\approx 4m \\ \end{align*}
That's pretty close to the 5m I estimated from the video.

Now the hangtime of 3.7 seconds is far less then the the claimed 9 seconds of hangtime, and even my closer observation of the video suggests a few jumps were more than 5 seconds long. One way to get more hangtime is to jump with more speed - something that's quite possible with stronger and trained legs. Remember I started with someone able to jump 0.5 meters -- and I'm sure a strong dancer could leap higher.

Another reason the kinematics equations don't give us enough hangtime is that the acceleration is not constantly 1/6th that of gravity -- often it's way less than that even! Smaller accelerations, like those felt close to the building when θ is small, would increase hangtime significantly. Unfortunately, I've forgotten the formulas for how to deal with accelerations that aren't constant -- although I'm sure a few google searches could refresh me.

Either way, the Bandaloopers certainly can experience tremendous "jumps" due to the low horizontal forces they have to fight on their rotated worlds, and simple first-year physics concepts help reveal why.

Now, perhaps someday I'll be able to actually try it for myself.

### Lesson Planning with Google Calendar

I've done lesson planning about a dozen different ways in my 10 years of teaching - and my favorite and current way of planning is by using the Calendar application. As you can see in the picture, each activity for a given day is one of the pink boxes that shows up. In these boxes (technically they are "events") I can write as little or as much detail as I want.  Typically I just write a little bit: "Notes on Solving by Quadratic Formula" for instance. For assignments I write something simple like "Assign: Pg 189 #1, 2, 10-26evens" or "Assign: Worksheet - Multiplication".

These calendars are super easy to move items around, copy from year to year, assign over multiple days, etc. I have created four Google calendars, one for each class that I teach. These Google calendars then can be embedded into my class website.  Then students and parents can know at a glance what were studying not only this week, but they can look forward to days when they may be gone, or look back to days they've missed.  I have had on more than one occasion students who have come in after being sick and instead of asking "did I miss anything" they hand me their homework which they found on the calendar.

Whenever possible, I put links to helpful material into these events as well. This was the biggest challenge, but something a little html knowledge proves handy for. To add a link to something, you double click on the event and type into the "Add a note" section. You may type text descriptions with more details here and students will be able to read these by clicking for more details on their calendars.  Adding URL's sounds easy at first, but unfortunately, simply pasting a link into the "Add URL" section doesn't work. Perhaps this will be fixed someday? A work around that allows a clickable link to appear on the student end of things is to use a little HTML code. Copy and paste following code snippit:
<a href = "URLgoeshere">Text goes here</a>
One thing to look out for is to make sure that your computer doesn't turn " into "smart quotes" -- because then the links won't work. I had to turn "smart quotes" off in system preferences. In addition to downloadable worksheets as assignments, I include links to quizlet vocabulary practice, math practice websites like ThatQuiz, or videos of my lessons whenever they are available.  A colleague of mine records every lesson every day, and since this year we share Algebra 2 together, I include links to her videos on youtube. I tell the students that if they don't like the way I explain something, or if they need another explanation, they can check the calendar and find Mrs. Straayer's videos.

One last plug for planning with google calendars is that students and parents can subscribe to them, and then they can have them show up on either their computers or phones. Anytime I make an update, they will have access to the most up to date plans.  This is really convenient when a snow day or something arises -- I can simply cut and paste today's events to tomorrow.  I have mine connected to my phone so I can either see what's coming up from anywhere -- or add a note or link or change something from everywhere on my phone.