Vim indent text objects for Coffeescript and Python
Do you write a lot of Coffeescript, Python, Jade templates, Haskell, or any other language that uses indentation? If you are like me, you may be sad to find out that your trusty ciB does not work anymore in Vim. ciB is “change inside block” which only matches inside () and {}. This is no good when we are dealing with languages like Python that use indentation instead of curly braces for block structures.
Luckily there is a plugin that adds this functionality:
Once you install this you can use vii or vai to see how it works. Use cii to change an entire indentation block.
Here’s a quick screencast to see how it works:
Good luck and happy Vimming!
Iteratee Hello World
This entire blog post is in literate Haskell, you can clone it from the gist to try it out:
git clone git://gist.github.com/1571444.git iteratee-hello-world
This is the simplest example of an Iteratee that I could think of. It simply reads from an stdin/file Enumerator and spits it out to an stdout Iteratee. The stream is transformed to uppercase characters using an Enumeratee.
I put this together to figure out how to apply the Iteratee abstraction in everyday situations, hopefully this will serve as a jump off point for people looking to learn about Iteratees.
Using Haskell’s QuickCheck to generate random test data
QuickCheck is a random testing library written in Haskell and is typically used for fuzz testing code. The main typeclass provided by QuickCheck is the Arbitrary typeclass. When you make one of your data types an instance of this typeclass (by implementing the arbitrary function) you can generate random samples of those data types
I recently needed a way to generate a large number of Serial numbers of a specific format, QuickCheck turned out to be perfect for this.
I started out by creating a new data type representing my serial number:
data Serial = Serial String Int
The String represents a random prefix (eg. “ABC”), and the Int represents some number which could represent the order number, etc. Implementing show allows me to easily convert this data type to a string:
instance Show Serial where
show (Serial prefix number) = prefix ++ show number
Now to generate Serials we implement Arbitrary for our Serial type:
instance Arbitrary Serial where
arbitrary = do
prefix <- vectorOf 3 $ elements ['A'..'Z']
number <- choose (10000, 99999)
return $ Serial prefix number
The magic happens during the call to arbitrary. arbitrary returns the type Gen Serial which represents a computation that generates a random Serial. Gen is a Monad, so that allows us to use do notation to build our generating computation.
The first line in our do block is a call to elements, which chooses a single element out of a list of elements. The vectorOf 3 says to apply this generator 3 times and assign it to prefix. As you can probably guess by now this generates a random string of length 3 with random characters between ‘A’ and ‘Z’.
The second line in the do block is a call to choose which chooses a single value between a range of values.
Finally we return our serial with the generated prefix and number.
We can now generate a list of random serials by using unGen:
serialGen :: Int -> [Serial]
serialGen seed = unGen arbitrary (mkStdGen seed) 9999999
Some data from this function:
LWQ74236
IZK97057
MTT84566
FBL91704
OUX61740
GFX20409
SGO76263
SXE22215
JNH61151
ZQY93980
Naturally you can apply this method to any data type you can think of, the Gen Monad is a great DSL for generating random test data!
The full program:
F# CSV Parsing with FParsec
I needed a .NET CSV parser for work, and since I don’t trust most .NET code I find online I wrote one in F# with FParsec!
This handles both quoted and unquoted cells. It even supports escaped characters (including commas)!
For example,
CODE, EN, FR
HOME_DESCRIPTION, Hello\, welcome to our site!, Bonjour\, bienvenue sur notre site
Will parse to:
[
["CODE", "EN", "FR"],
["HOME_DESCRIPTION", "Hello, welcome to our site!", "Bonjour, bienvenue sur notre site"]
]
You can even mix them if you want:
"CODE", "EN", "FR"
HOME_DESCRIPTION, Hello\, welcome to our site!, "Bonjour, bienvenue sur notre site"
This will parse to the same thing
It even handles cases where there are quotes inside unquoted cells!
Since we’re using FParsec, if the parse fails it will tell you exactly where and why. Here is an excerpt from one of my test cases that fails when there’s a comma missing:
Error in Ln: 4 Col: 19
SOME_CODE,"Herp\,"Derp
^
Expecting: end of file, newline or ','
Have fun!
Irssi notifications with notify.io
Ever wanted more powerful notification capabilities inside of
irssi?
If you use irssi and you’re like me, you might have a setup similar to
this:
irssi on home desktop or server inside of a screen session
This is an ideal setup for me since it allows me to shell into my box at home
from various locations. A lot of the time the IRC ports are blocked so ssh +
screen + irssi gets around that.
One things sorely lacking is message notifications, specifically when your name
is mentioned in the channel or when you receive a private message. There are a
few plugins that will email you alerts when you’re away but what I was really
looking for was growl notifications.
The best service for doing this is something called
notify.io. Not only will it forward growl notifications to
desktop clients, but you also have the option to send prowl notifications to your iOS
devices, jabber, sms, and email.

I’ve put together a small irssi script that does just this! notify-io.pl
listens for private messages and channel mentions, and forwards them to your
notify.io account!
Installation
The first thing you’ll need to do is get an account at
notify.io
Download the notify-io.pl script from the github
page
Install the script to ~/.irssi/scripts/autorun
Run the command /set notify_io_api_key <key> where <key> is your
notify.io api key (retrieved from the settings panel on the notify.io website)
Run the command /set notify_io_email <email> with the notify.io email
registered with the account
That’s it! Enjoy.
Static Factorial in Clay
Meta programming in Clay is very intuitive:
Here’s the same thing in C++:
The cool thing about this is that you can have both runtime and compile time (static) overloads at the same time.
Have a function that you can turn into a compile time operation? Simply add an overload that takes a static value and do your custom logic.
Compile-time meta programming is truly a first class citizen in Clay.
Thanks to qx on #clay for showing me how to do this
Print-friendly lesswrong Sequences
I have started to convert The Sequences over at lesswrong.com to print and ebook ready formats such as epub and PDF. You can get them on my github page:
https://github.com/jb55/lesswrong-print
Interesting Minecraft-clone Projects
I’ve been following Minecraft development for awhile, and I’ve
always wondered what future Minecraft games might look like.
Surprisingly, there already seems to be a couple working clones and
bunch more in development. I wouldn’t be surprised if major game
development are starting to work on their own Minecraft games as
well, who knows!
Manic Digger

Manic Digger
is a working Minecraft clone written in C# using (I’m assuming)
XNA. It keeps the blocky style from the original minecraft and some
new features. According to their
wiki:
- New blocks (Natrium, Platinum, Lead to name a few)
- New monsters (Dragons, imps, giants!)
- Monster editor
It’s also open source, if you’re the kind of guy who likes hacking
on open source C# projects. It only works in Windows at the
moment.
Meincraft

meinKraft
is a small Minecraft-like tech demo written in C. He says the
source is included but I didn’t see it in the zip.
RogueMiner
A C++ Minecraft project! This one looks interesting.
RogueMiner looks to be a
Minecraft clone built from scratch using SDL and OpenGL.
Ogre3D projects
There have been some interesting discussions on the Ogre3D forums
about new efficient Minecraft implementations. A person named
Kojack put together a pretty cool tech demo using various shader
implementations:




I highly recommend you read his
posts on
the Ogre3D forums if you’re interested in this stuff.
Cubelands
Can’t say much about this one, it looks to be the most polished
Minecraft clone to date. It’s currently in
private beta.
Future
Most of the clones I found seem to be trying to emulate Minecraft
as close as possible. While this is great and all, what I’d really
like to see in future Minecraft titles are:
- More realistic, immersive gameplay
- MMO?
- Infinite depth, harder difficulty the further down you go.
- Physics?
There’s so many things that you could do in a game like this, I
look forward to future projects. I may even take a stab at it.
Stuxnet Dossier
Symantec has released a breakdown of the Stuxnet worm, you can read it here: goo.gl/fkXF
Some interesting quotes:
If this value is equal to 19790509 the threat will exit. This is thought to be an infection marker or a “do not infect” marker. If this is set correctly infection will not occur. The value appears to be a date of May 9, 1979. While on May 9, 1979 a variety of historical events occured, according to Wikipedia “Habib Elghanian was executed by a firing squad in Tehran sending shock waves through the closely knit Iranian Jewish community. He was the first Jew and one of the first civilians to be executed by the new Islamic government. This prompted the mass exodus of the once 100,000 member strong Jewish community of Iran which continues to this day.” Symantec cautions readers on drawing any attribution conclusions. Attackers would have the natural desire to implicate another party.
In the driver file, the project path b:\myrtus\src\objfre_w2k_x86\i386 \guava.pdb was not removed.
Guavas are plants in the myrtle (myrtus) family genus. In addition, according to Wikipedia, “Esther was originally named Hadassah. Hadassah means ‘myrtle’ in Hebrew.” Esther learned of a plot to assassinate the king and “told the king of Haman’s plan to massacre all Jews in the Persian Empire…The Jews went on to kill only their would- be executioners.” Symantec cautions readers on drawing any attribution conclusions. Attackers would have the natural desire to implicate another party.
Gists on Tumblr?
Looks like it works!