Undef'd statement

Notes of a coder

Emacs keybindings for IPython Notebook and Firefox

IPython Notebook is fantastic. It provides a nice interactive Python session and runs beautifully in browsers.

I’m an Emacs user and like to use Ctrl key combinations for all cursor movement. I find that for non-code text fields, I have no problem switching to the Windows-style keyboard shortcuts. But when I’m editing code, my brain insists on the same keybindings I’m used to in Emacs.

Read more...

Programming hierarchical deterministic Bitcoin wallets in Python

Hierarchical deterministic wallets are a fascinating concept with lots of potential uses. One interesting application is the ability to have a public/private wallet key pair for generating Bitcoin addresses in a deterministic way. The exact same addresses for receiving bitcoins can be generated with both the public wallet key and the private wallet key. However, the corresponding private keys for spending bitcoins can only be generated using the private wallet key.

In his blog post On BIP0032 and Bitcoin Deterministic Wallets, Richard Kiss, the author of the pycoin Python library, shows how to generate and use a HD wallet using the command line tools provided by pycoin. For a detailed description and specification of HD wallets, see BIP 0032.

In this blog post, I’ll explain how HD wallets would be applied for accepting payments on-line, and walk through some of the required steps in Python using pycoin. I’ll use IPython Notebook as the programming environment.

Read more...

Collaborative coding in the browser

These are my notes for researching options available for collaborative coding using the web browser as a platform.

I researched these some time in 2011–2012, so the information might not be up-to-date. I’ll come back and revise at some point. And add some screenshots.

Read more...

How to search for code now that Google Code Search is dead?

On 2011-10-14, in a blog post titled “A fall sweep” on the official Google blog, Bradley Horowitz announced Google Code Search to be shut down on 2012-01-15. Apologies, some explanation and links to alternatives were provided in the thread Code Search Shutdown on Google Groups.

I decided to review alternatives in a real-world situation. Facing with the task of creating a fairly complex custom Django template tag, I first wanted to see some examples of tags involving handling of dates and times.

To find such source code, I came up with these keywords which must exist in modules I’m interested in:

django import datetime template Context Library Node TemplateSyntaxError render parser token

Here’s a run-down of all the code search engines and related tools I could find.

Read more...

Log analysis with Python using the logtools package

Our Solr server which runs on top of Tomcat had an out of memory crash. I browsed through the logs and noticed bursts of org.apache.solr.core.SolrDeletionPolicy onInit lines just before the crash and on the previous night. I couldn’t find a clear explanation of what they are and wanted to have a better look at when and how frequently they occur.

Quick googling for log analysis tools found Adam Ever-Hadani’s logtools Python package which turned out to follow familiar Unix conventions and do a great job summarizing our logs.

Read more...

My Nginx configuration for Tinkerer

On my desktop, my blog is in the ~/blog directory. I rsync the contents of the ~/blog/blog/html/ directory into ~/undefd.kaihola.fi on the server. Here’s the corresponding Nginx configuration:

server {
        listen 80;
        server_name     undefd.kaihola.fi;
        root            /home/akaihola/undefd.kaihola.fi;
        default_type    'text/html';
        index           index.html;
}

Using Dingus for unit testing Python code

So you want to unit test just one function or method and mock everything it refers to.

What if your code calls the open built-in function and you need to mock that out? Turns out Michael Foord’s Mock library provides a trick to achieve this, and you can use that together with Gary Bernhardt’s Dingus:

from dingus import Dingus, DingusTestCase
from mock import patch
from mymodule import myfunction

class MyTestCase(DingusTestCase(myfunction)):
    def test_that_it_works(self):
        with patch('mymodule.open', Dingus(), create=True):
            result = myfunction()

Installing Puppet

So you want to install and use Puppet.

On Ubuntu 9.04

sudo apt-get install ruby rubygems libopenssl-ruby
export RUBYOPT=rubygems
gem install facter puppet

on Debian Etch/Lenny clients

apt-get install ruby rubygems libopenssl-ruby
gem install facter puppet
export RUBYOPT=rubygems
/var/lib/gems/1.8/gems/puppet-0.25.1/bin/puppetd --waitforcert 60 --test

puppetmaster

apt-get install ruby rubygems libopenssl-ruby
gem install facter puppet
export RUBYOPT=rubygems
/var/lib/gems/1.8/gems/puppet-0.25.1/bin/puppetmasterd --mkusers
mkdir -p /etc/puppet/manifests
cd /etc/puppet
git init

Latex indexing traps

When using the docindex (or, actually, docidx2e) package instead of the index package, \index{} macros need to be protected when used inside subfloat captions:

\subfloat[word\protect\index{word}]

Also, the index is printed using the \PrintIndex command instead of \printindex.

Using nose with Django

django-noserun

http://www.djangosnippets.org/snippets/1390/

Did not run any tests.

nose-django (nose plugin)

http://www.assembla.com/wiki/show/nosedjango

Doesn’t use transactions -> slow