Turtle Power

Thanks to this great website, I’ve been having some more fun with Python.  I’m now in the chapter on Recursion, which introduces Python’s Turtle module. Turtle is an implementation of Logo, a language I remember playing with happily in my younger years. What you can do with it in Python is quite amazing sometimes.  There are some demo scripts that come pre-installed, and can be accessed this way:

python -m turtledemo

I’ve still not wrapped my head around the more complex ones, but the Sierpinski example in the tutorial is a nice start. I learned from their example and wrote my own (fairly similar) version. The result looks pretty nice:

sierpinski

A couple of weeks back I wouldn’t have been able to come up with something like this at all, so I’m pretty happy with what I’ve learned so far.

Below is the script. Just pasting it in a python3 prompt should suffice.

Tagore on critics

The manner in which literary analysis is engaged with in our country is completely uneducated. There’s no point in hearing: ‘I liked it’ or ‘I didn’t like it’. That only gives you a particular person’s opinion; it doesn’t give you the truth of that opinion. If that opinion comes from somebody who is sufficiently capable of appreciation or experienced in literary affairs then even that might make you think a little. But just any person’s opinion has no value at all. Our country lacks good reviewing skills—and the primary reason is that the people of our country do not have an intimate acquaintance with literature.

Flask trial run on PythonAnywhere

I felt it was about time I got into the web development side of Python, having learned enough of it to be dangerous. Since I moved my site to a PaaS, I wanted a quick and dirty alternative Python host that was easy to set up and use. Enter PythonAnywhere. This seemed to fit my immediate needs, as the site provides web-based bash, python and ipython shells for free users. They support both Python 2 and 3, so I went with the latter.

Next up, Flask. Their quickstart tutorial was what I used as a baseline. It seemed easier to start with than heavier alternatives like Django. Although the tutorial covers a minimal blog, I was able to make enough tweaks to it to get what I wanted.

Finally, a purpose. My wife is about a month away from delivering our first baby (oh let it be a girl, please :) ), so I decided to make a simple site where the two of us could enter names that we wanted, for both genders. Each entry is equivalent to a blog post in the Flask tutorial, so the underlying code remained largely the same. It was easy enough to add the rest of the parts I needed. Here then is what it ended up looking like, and here’s a screenshot if I end up taking down the site later:

babynames

PythonAnywhere turned out to be a great experience. The founders were friendly enough to exchange a couple of mails directly, which was a fresh change from the noreply@website.com welcome mails that other sites favour. Getting the site up from my local test setup was a simple matter of ftp’ing a tar file over and extracting it.

Overall it took me less than half a day to get everything up, and another few hours of tweaking to add cute pictures and stuff.

Gunman Clive Review

This is probably the best bang for buck on the eShop right now. For $2 you get a short, sweet platformer with a great look.

Source: google play

Source: google play

I don’t have too much time to spend on long, padded games (Hello Unchained Blades), and Gunman Clive ended just where it should have. Although occasionally hard, this game keeps the controls simple (only Jump and Shoot), and uses weapon power-ups and the odd new platform mechanic to spice things up.

Recommendation: Buy Buy BUY.

Hints: For that annoying mushroom jump: hit jump as soon as you Clive’s hand descending.

How I reduced 40+ seconds from my Fedora’s boot time

My laptop has run Fedora for some time now and I like it a lot. Since it’s pretty old, I’ve always forgiven the painfully slow boot time it had. After upgrading to Fedora 20 (Heisenbug), I decided to see if I could do something about it. Turns out I certainly could.

Analysis

The first step was to understand what was slowing down the booting most. systemd-analyze is a nice tool for this. I ran it like this:
systemd-analyze plot >~arun/plot.svg
And it gave me this neat graph:

Unnecessary services

There’s a lot of stuff there that I’m not familiar with. Rather than going through each in order, I decided to wipe out a bunch of unneeded services in one go (found in this detailed guide). So:
for i in abrt.service auditd.service avahi-daemon. bluetooth.* dev-hugepages.mount dev-mqueue.mount fedora-configure.service fedora-loadmodules.service fedora-readonly.service ip6tables.service  irqbalance.service mcelog.service rsyslog.service sendmail.service sm-client.service sys-kernel-config.mount sys-kernel-debug.mount; do systemctl mask $i; done

Dynamic Firewall

Firewalld seemed slow for me as well, and I didn’t need a dynamic firewall for my simple uses. I replaced it with good old iptables like this:
systemctl mask firewalld.service
systemctl enable iptables.service
systemctl enable ip6tables.service

The mask option is similar to (but stronger than) disable, and permanently disables the service. The default iptables rules disallow all incoming connections so I did not need further tweaks here.

Plymouth

plymouth-quit-wait-service was the next long culprit I tackled. This turned out to be a bug where plymouth was trying to load a non-existent file. The 25th comment in the link is what I used to work around it.

Journald

Finally  there was one long pause that I didn’t understand (from the 15th to the 38th second in that graph). After some digging I discovered this weird snippet in journalctl’s output:
Dec 09 11:55:25 oroboros systemd[1]: Starting Trigger Flushing of Journal to Persistent Storage…
Dec 09 11:55:25 oroboros systemd[1]: Starting Tell Plymouth To Write Out Runtime Data…
Dec 09 11:55:25 oroboros systemd[1]: Starting Security Auditing Service…
Dec 09 11:55:25 oroboros systemd[1]: Starting Recreate Volatile Files and Directories…
Dec 09 11:55:26 oroboros systemd-journal[197]: Allowing system journal files to grow to 2.9G.
Dec 09 11:56:10 oroboros systemd-journal[197]: Forwarding to syslog missed 57 messages.

The snippet is from an earlier boot but the  massive gap between the two messages at the end seemed indicative of the problem I was looking for. Subsequent digging revealed that journalctl was storing messages dating back several months, and had really grown in size:
journalctl –disk-usage
Journals take up 947.2M on disk.

My fix was to switch the Storage setting to volatile in /etc/systemd/journald.conf:
Storage=volatile

Since then I have reverted it to the Auto setting it had earlier, and kept saner values of 100MB each for the parameters SystemMaxUse and SystemMaxFileSize. 

Result

The final graph now looks like this:

A noticeable improvement :) 
 

The flow of time..

(pic source: wallbase)

I ended 2013 well, by finishing The Legend of Zelda: Ocarina of Time for the first time in my life. This was actually the first retail game I got for my 3DS two years back. Although I liked it then, I struggled quite a bit and gave up some time at the Goron section (as young Link). I didn’t quite get a hang of the exploration, the weird save structure, and so on. A few years back, on my DS Lite, I had stopped playing Phantom Hourglass for similar reasons.

Now, two years later, having played quite a few other games, I seem to have become better adjusted. This time round I had a ball. Every bit was as enoyable as a ton of fans have said. I can see now why it constantly hovers at the top of the All Time Great lists.

Playing (and finishing) it was probably the best gaming experiences I’ve had. I ended up buying Link’s Awakening a week later from the eShop, and also plan to get back to Phantom Hourglass.

Favourite moment: Lots. But the exquisite music gets a special mention. Zelda’s lullaby is now my phone’s ringtone.

Fetch unique words in a web page (in 7 lines of Python)

I got a chance to enroll for some Python training at work and had a nice time with it. I’ve tried getting into other languages myself before, and this has been my freshest experience so far. The three days of training were enough to show me how insanely easy it is to get productive in Python.

A quick example we saw was to:

  • Get the contents of a web page, and
  • Find all the unique words in it.
This simple example introduces the usage of lists, sets, modules and loops. The code looks like this:

import urllib2
words=[]
for line in urllib2.urlopen(‘http://slashdot.org’):
    words.extend(line.split(‘ ‘))
print ‘number of words is’, len(words)
uniq=set(words)
print ‘number of unique words is’, len(uniq)
That’s it! The whole job takes only eight lines. Running it gives an output like this:
C:Python27mypy>19.py
number of words is 13297
number of unique words is 3672

The first line imports the urllib2 module. 
The next line initializes an empty list.
The third line is where most of the magic happens. A for loop iterates over a list returned by urllib2 when we ask it to open Slashdot’s home page. For each line, we split the content into individual words and append it to our list.
That gives us all the words in the page, which we print.
Python supports a set data structure that we copy this list to, which ends up removing recurring elements automatically (since sets support only unique elements).
And that’s it, we’re done. Of course there is always more to do beyond this (such as in not counting html tags), but this was probably my favourite example from the course that captured how easy it was to get seemingly complicated tasks done in Python.

Self-hosted Read-It-Later alternative

I was addicted to Pocket for a few months because of how well it fit into my reading habits. It had an elegant extension that basically allowed you to click-and-forget while all the magic happened in the background. The service filters all the trash from a page (typically a long article curated by the likes of The Browser and Longform) and neatly synchronizes content with other endpoints (my Android tablet and phone in my case). This was great for my evening commute back home because I’d usually have half a dozen or so interesting articles to read in a neat, clean page.

My very addiction to the service is what led me to explore other alternatives. Poche is the one I discovered and eventually settled with. It works just like Pocket as far as the content display goes, the major selling point being its open source nature. The devs have come up with a hosted solution for those who don’t run their own servers. Although saving and displaying work similar to the alternatives, sync does not. Your articles will still be in your poche but the android app will not cache them offline as of now.


I’ve been running their self hosted version for more than a month and it has become a part of my daily routine now. I highly recommend supporting the devs for coming up with a great open source alternative in a niche that was largely proprietary until now.

Got a new VPS

I’ve noticed I’ve been pretty bored these past few months, and the most noticeable culprit has been the VPS that I stopped using some time back. I used to enjoy installing and trying out new web applications and servers. So I decided to get another one. This time I went with an OpenVZ server instead of Xen, and the provider I picked was Iniz, who I came across in this roundup at LowEndBox. The server is pretty neat, with 2GB RAM and 100GB of disk space. I’ve decided to go with CentOS, since I like Fedora/RedHat already.


It’s been a day since it was provisioned, and I feel the old skills returning: securing ssh, configuring iptables, installing postgres, setting up cron jobs, and so on. This blog will (as usual) probably be wiped out or moved to something on the server. Other webservices that I’ve been using (NewsBlur, Pinboard) will also probably move to self hosted equivalents (TTRSS, Shaarli).