Skip to content

Instantly share code, notes, and snippets.

@blakesmith
blakesmith / gist:1015260
Created June 8, 2011 20:04
Bencoding implementation
require 'stringio'
module EM::Bittorrent
module Benc
def self.decode(input)
Stream.new(input).decode
end
class Stream
def initialize(input)
@blakesmith
blakesmith / gist:995542
Created May 27, 2011 15:52
ZMQ Envelope Deliminators
// I'm confused about enveloping and 'blank frames'.
// One example from the ZMQ guide seems to have each envelope
// separated by an empty frame, and the other has one empty
// frame to deliminate the entire envelope stack. Which is
// correct? Or are there two different things going on here?
// LRU Queue example
s_sendmore (backend, worker_queue [0]);
s_sendmore (backend, "");
s_sendmore (backend, client_addr);
# Script to watch a directory for any changes to a haml file
# and compile it.
#
# USAGE: ruby haml_watch.rb <directory_to_watch>
#
require 'rubygems'
require 'fssm'
directory = File.join(File.dirname(__FILE__), ARGV.first)
FSSM.monitor(directory, '**/*.haml') do
irb(main):001:0> require 'maruku'
=> true
irb(main):002:0> s = File.read('maruku-test')
=> "* Abacus\n * answer\n* Bubbles\n 1. bunk\n 2. bupkis\n * BELITTLER\n 3. burper\n* Cunning\n"
irb(main):003:0> doc = Maruku.new(s)
=> md_el(:document,[
md_el(:ul,[
md_el(:li,[md_par(["Abacus * answer"])],{:want_my_paragraph=>false},[]),
md_el(:li,[
md_par(["Bubbles"]),
#!/usr/bin/env ruby
#
#
# Quick and dirty script to extract some statistics about
# Rails core contributers.
#
# Usage: git_core_stats <path to rails git project>
# Example: git_core_stats ~/code/rails
#
# OR
From d4ed463815b8c7afcf95500a73754f2bca6b1b13 Mon Sep 17 00:00:00 2001
From: Blake Smith <[email protected]>
Date: Tue, 29 Jun 2010 23:43:26 -0500
Subject: [PATCH] Fix garbled UTF-8 characters
---
.../2010-01-16-fully-document-your-datamapper.html | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/_posts/2010-01-16-fully-document-your-datamapper.html b/_posts/2010-01-16-fully-document-your-datamapper.html
# An example Jekyll Liquid tag. Utilizes the new plugin system.
#
# 1. Make a _plugins directory in your jekyll site, and put this class in a file there.
# 2. In anyone of your pages, you can use the 'render_time' liquid tag like so:
# {% render_time Page generated at: %}
module Jekyll
class RenderTimeTag < Liquid::Tag
def initialize(tag_name, text, tokens)
# An example Jekyll generator. Utilizes the new plugin system.
#
# 1. Make a _plugins directory in your jekyll site, and put this class in a file there.
# 2. Upon site generation, version.html will be created in your root destination with
# # the version of Jekyll that generated it
module Jekyll
class VersionReporter < Generator
safe true
# An example Jekyll converter. Utilizes the new plugin system.
#
#
# 1. Make a _plugins directory in your jekyll site, and put this class in a file there.
# 2. Any file in the _posts directory ending in .upcase will be processed using this converter.
module Jekyll
class UpcaseConverter < Converter
safe true
require 'rubygems'
require 'inline'
class MyTestInC
inline do |builder|
builder.c <<-EOF
long factorial(int max) {
int i=max, result=1;
while (i >= 2) {
result *= i--;