The power of simple python scripting is one of the themes of this blog, and now I can show a great practical example.
I needed to create something that looks like this:
This is a simple HTML table with some CSS. But trying to write it in HTML would result in a lot of copy-pasting of stuff that looks like this:
That’s a lot of boring and error prone copy-pasting. And I’ll need to create lots of these in the coming months.
OK, so I need to write a script that will turn this:
Into the correct HTML.
It’s actually really easy:
It’s a small command-line tool that knows how to create an empty .py file for a canvas with the correct template, and knows how to read a .py file as a python file (since this is for self-use only I’m fine with no security at all, otherwise reading it as a python file would be very unwise) and do some preprocessing and some search-and-replacin’ to get the right thing into an HTML template.
I needed to be able to control how many notes to have in a row, so I added parsing of a space at the beginning of a note caption to mean “newline before this”. I needed to write many similar notes for “customer segments” – so I used the fact that the canvas definition file is in python to just write some python that generates it:
“customers”: [x + ” Fans” for x in [“Comics”, “RPG”, ” MTG”, “Anime”]] + [” Gamers”],
And that’s all there is to it. One of my students could write this in ten minutes. From now on, something that I will be doing every day will take a few minutes less.
I started exercising my idea muscles a few days ago.
Every day I think of 10 startup ideas and develop one into a business model. Some will be published here.
Lets begin with the first example – geekar, an Augmented Reality-enhanced retail, in the most early-adopter industry I know: geeks. geekar will sell comic books, tabletop roleplaying sourcebooks, board games, trading card games, manga, anime, computer games and so on.
I was holding up on posting until I can say more about PythonForAll (it’s not that I didn’t get out of the building, just that it’s becoming a bit more serious so I can’t publish things before they are final) but I just have to write about this:
For a long time I’ve wanted to code a screensaver showing matrix code, just like the gajillion clones you can already find on the internet, but instead of showing random characters, this one would capture (“sniff”) network packets and show them in encoded form.
The theory is that if you watch this long enough, you’ll begin to “see through the code” – at first, you’ll learn to decode the characters into numbers, and at more advanced stages you’ll learn to parse the network protocols intuitively. I have many reasons to believe this:
I’ve seen people learning languages and musical instruments (and experienced it myself)
I’ve heard that one of the Samba developers can decode raw NBNS packets in his head (one of the most horrible encodings I’ve seen, see here 1.3.1)
I knew someone who could synchronize a dial-up modem with his voice
Today I saw this HN thread and was reminded of this idea. I decided that the time had come. A night of work later, an alpha version exists and the main feature works well:
You can get it on github. If you are not experienced with compiling linux software, I advise you to wait for a more user friendly release. Drop a comment saying you’re interested, it will motivate me to create one.
There’s work to do on friendliness of installation and on shininess of visualization. Other than that it’s complete. Python and Cairo rock!