I’ve broken down the semantics of the ZMQ opening handshake and gotten data in to Haskell. Now let’s send data out of a Haskell program and in to a C/libzmq program. Previous Posts http://xrl.tureus.com/a-quick-post-on-zmqhs http://xrl.tureus.com/haskell-and-binary-streams-parsing-with-field http://xrl.tureus.com/black-box-reverse-engineering-zmq Find the Code http://github.com/xrl/zmqhs The Spec more-frame = length more body final-frame = length final body length = OCTET / (%xFF 8OCTET) more...
Black-Box Reverse Engineering ZMQHS It’s time to bang on the networking aspect and interact with real ZMQ frames. I have written a pure C test app against libzmq to perform a transmission test. My Haskell code will attempt to send data and I will snoop in on the transmission using a third party tool. To gather the wire data I am using tshark, the command line version of the wireshark network packet sniffer. This style of protocol debugging can be considered ‘black box’. I’m teasing out meaning from the C implementation...
Implementing the ZeroMQ spec has taught me a lot about parsing in Haskell and I thought I should share. A Note on Middleware In general, a middleware is used to abstract away some complex behavior, simplifying the user-developer’s application. The middleware will performs its task and when satisfied it will invoke the application layer — this is usually called “delivering” the message. If a message is corrupted or does not meet some pre-described contract it may be discarded without notice. Middleware is commonly...
ZMQHS is a pure Haskell implementation of the ZeroMQ library. My first task is to break down the wire protocol and then figure out an API which gives sufficient access to the semantics.Why use a purely Haskell system? I was thinking about how I would love to write Mongrel2 handlers for the HalVM and I thought to myself "ZeroMQ on Haskell relies on a C extensions". You don't have the usual programming environment, so no usual malloc, libc, etc. Plus, the Mongrel2 developers have found snafus in the ZeroMQ implementation...
Bootstrapping Your DB Over time my Merb/Sequel migrations folder has grown unwieldy. Currently at over 90 migration steps. And more importantly, I can’t reason about the final state of the schema without having already applied the steps. Sequel has a nice command line tool which provides a basic schema dump but then I would be giving away all my constraints. Since I’m a Postgres believer, here’s how you replicate an existing DB into something you can apply in one step. #!bash pg_dump -Uyour_user_name -h...
Euler.hs Tips and Tricks for Everyday Coding Changes in how I use Haskell As I move through the Project Euler questions I have begun to see trends in how the questions work as well as what functionality I need to answer questions. Enter the module! And while we’re discussing every day use of Haskell code, I’ll cover how to build Haskell projects using a familiar friend, GNU Make and how to create standalone executables. The Haskell Module You should save this module in a file of the same name, in this example...
“What is the largest prime factor of the number 600851475143?” First of all, what is a factor of a number? In my inexact language: a number is a factor of another number if it is a clean divisor. Example: 2 is a factor of 4 because 4%2 is 0. 3 is not a factor of 5 because 3%5 is 3. My plan for grabbing those factors is a simple algorithm where we tear down the number but systemically finding it’s smallest factors. You start by dividing the number by 2, if it is divisible by 2 you add 2 to the list of factors and...
So I've been working my way through the excellent Learn You A Haskell, http://learnyouahaskell.com/ , and I'm glad to say it's going pretty well. My previous experience with functional programming is limited to Erlang. The promise of Haskell's speed, brevity, and safety are enticing. What better way to learn a language inside and out than to use it? Enter Project Euler, http://projecteuler.net/ , a compendium of increasingly-difficult programming problems. Very math oriented. The trick? Don't use brute force! And...
Why Git? It is my strong opinion that github is the best way to get collaboration going on open source code. It lowers the barrier of forking and toying with the code and actually encourages ‘social coding’. One great example: the MacRuby project. They made the switch 2 weeks ago (see their blog post here) and they already have 16 forks. MacRuby’s situation does pull out a few facts about life on github a) git is particularly popular with rubyists, b) macruby was an alreayd highly visible project, c) those forks...