git: Pushing to a Remote Branch with a Different Name

Normally when I do a push in git I do something like git push origin master, which really means push from the local branch named master to the remote branch named master. If you want to push to a remote branch with a different name than your local branch, separate the local and remote names with a colon:

git push origin local-name:remote-name
git: Pushing to a Remote Branch with a Different Name

ipythonblocks – A Visual Tool for Practicing Python

Learning to program and learning the basics of control flow can be tricky business for novices. I wanted to make something that provided immediate, visual feedback to students as they practice things like for loops and if statements so they can see precisely what their code is (or isn’t) doing. So I wrote ipythonblocks.

The IPython Notebook makes it possible to display rich representations of Python objects using HTML (among other things). That allowed me to make a Python object whose representation in the Notebook is a colored table. Students can index into the table to change the color properties of individual table cells and then immediately display their changes.

With ipythonblocks instructors can give coding problems like ‘turn every block in the third column red’ or ‘turn every blue block green’ and by displaying their blocks students can see right away whether their code is having the desired effect.

Check out the demo notebook to see ipythonblocks in action.

ipythonblocks – A Visual Tool for Practicing Python

Decode

This week I was in a job interview and one of my interview questions turned into a pretty interesting puzzle. I was asked the following question:

Assume a character encoding a = 1, b = 2, c = 3, … , z = 26. Given a string of numbers (e.g. '123456'), figure out how many different ways that string could be decoded.

I didn’t arrive a complete solution in the few minutes I had during the interview but I kept thinking about it afterwards because I couldn’t shake the feeling there was really a math problem here, not just a programming problem.

The difficult part of this challenge is figuring out how many decodings there are when there are overlapping possible groupings of numbers. For example, the string '111' can be decoded as ['1', '1', '1']['11', '1'], or ['1', '11']. I never figured out a formula for calculating the number of decodings but by manually figuring out the number of decodings for the strings '1''11''111''1111''11111''111111', etc. I noticed that the number of decodings follow the Fibonacci sequence starting with 1, 2, 3, 5, 8…! Unfortunately I don’t have a good explanation for why that is the case. (Though it makes gut level sense in the way the Fibonacci sequence is a sum of everything that has come before.) Please leave a comment if you can explain this!

So, my strategy for solving this problem follows these basic steps:

  1. Break the given string down into substrings such that each substring is one digit, '10' or '20', or cannot be broken down further because it has an unknown number of possible decodings. These substrings can be considered independently for the purposes of this problem.
    • For example, '956' becomes ['9', '5', '6'] and '121956' becomes ['1219', '5', '6'].
  2. For each substring figure out the number of decodings. For single digits, '10', and '20' this is just 1. For other substrings this is the Nth value in the Fibonacci series 1, 2, 3, 5, 8… where N is the length of the substring.
  3. Multiply together all of the number of decodings for the individual substrings to get the number of of decodings for the original string of numbers.

You can see my code for this solution here: http://nbviewer.ipython.org/3831343/ (raw notebook).

Decode

What’s In My Stack?

This is a response to a post on the Software Carpentry blog: What’s In Your Stack?

My development setup is pretty simple:

  • Sublime Text 2 with a few plugins
  • git, GitHub, and bitbucket
  • Subversion and Trac (only at work)
  • IPython notebook
  • NumPy, SciPy, and matplotlib (mostly at work)
  • Chrome for debugging web stuff
  • bash and the usual shell utilities

It should go without saying that I’m using all of this to work on Python. And a little  JavaScript comes in for web apps.

What’s in your stack?

What’s In My Stack?