Use Python bytecode to solve puzzler

Learning Python Internals Recently I stumbled upon this wonderful set of videos on Python interpreter internals. (Thanks to Philip Guo for creating them and thanks to Michael Kennedy (@mkennedy) and his Talk Python to me show that brought this on my radar) I’ve been using Python for about ten years but I’ve never really truly been able to understand how the interpreter works, nor was I familiar with the Python virtual machine or the bytecode.

Use Python bytecode to solve puzzler

Learning Python Internals Recently I stumbled upon this wonderful set of videos on Python interpreter internals. (Thanks to Philip Guo for creating them and thanks to Michael Kennedy (@mkennedy) and his Talk Python to me show that brought this on my radar) I’ve been using Python for about ten years but I’ve never really truly been able to understand how the interpreter works, nor was I familiar with the Python virtual machine or the bytecode.

Use Python's sys.settrace() for fun and for profit

The itch to scratch Everyone in the software industry knows Kent Beck, the pioneers of extreme programming and test-driven development and the co-author of JUnit. One of his lesser known project was JUnitMax, which aims to reduce the time developers have to wait while tests are running. One of the ideas behind that is that when code changes, only the test cases that exercise the code need to be run, instead of running the entire suite.

Realtime notification delivery using rabbitmq

Our company has “hack-off” days once a while, where we developers get to choose whatever we would like to work on and present it to the entire company by the end of the day. I have been hearing this websocket buzz for a while now and would like to build something interesting with it. WebSocket Websocket is a persistent bi-directional connection between the browser and the server. With websocket, web browser can post message to the server, but what’s more interesting is that the server is able to push messages to the client (browser).

Use Python decorator to curry functions

It’s been a while since the last time I wrote about Python. This morning, I was listening to a podcast on my way to work. They were discussing functional programming and dynamic languages…I learned Python before I went into Computer Science, and then I learned about functional programming and through learning of Scala and Clojure, my functional programming concepts have been enriched. As I was listening, it suddenly appeared to me that there isn’t a way in Python to curry a function.

Enable Auto-complete in a PDB session

EDIT: 2012-06-19 There are so many other much better options now that renders recipe obsolete. See pdb++ or ipdb

Pretty simple actually…Just put the following code in ~/.pdbrc and then you can use the Tab key during a PDB session to see the available attributes of the current context.

import rlcompleter
pdb.Pdb.complete=rlcompleter.Completer(locals()).complete

Hexspeak and Generator

EDIT: 2011-04-21 While browsing my old blog posts, I found the code here can be greatly improved. Here it is: def words(): with open('/usr/share/dict/words', 'r') as f: return (x.strip().upper() for x in f.readlines()) MAPPING = {'A':'A', 'B':'B', 'C':'C', 'D':'D', 'E':'E', 'F':'F', 'O':'0', 'S':'5', 'I':'1'} def main(): is_hexword = lambda word: all(ch in MAPPING for ch in word) for word in filter(is_hexword, words()): print word, "\t", ''.join(MAPPING.get(ch, ch) for ch in word) if __name__ == '__main__': main() So, it’s a relatively slow day at work, and I’ve been “stumbling upon” on Wikipedia when I found this: