Skip to content

Instantly share code, notes, and snippets.

#!/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
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"]),
# 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
@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);
@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)
notification-realtime.core=> (require '[clj-hector.core :as hector])
nil
notification-realtime.core=> (def cluster (hector/cluster "collectstream cluster" "localhost"))
java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String; (NO_SOURCE_FILE:3)
(defn read-bytes [input-stream n]
(loop [coll [] bytes-read 0]
(let [next-byte (.read input-stream)]
(if (or (= next-byte -1) (= bytes-read n))
coll
(recur (conj coll next-byte) (inc bytes-read))))))
user=> (read-bytes is 3)
[99 104 112]
user=> [0xE2 0x80 0x99]
[226 128 153]
user=> (String. (into-array Integer/TYPE [0xE2 0x80 0x99]) 0 3)
"???"
user=>
@blakesmith
blakesmith / gist:1587593
Created January 10, 2012 07:08
Simple pallet script
(ns pallet-test.core
(:use
[clojure.contrib.command-line])
(:require
[pallet.core :as core]
[pallet.compute :as compute]
[pallet.phase :as phase]
[pallet.crate.java :as java]
[pallet.crate.automated-admin-user :as automated-admin-user]))
; SLIME 20100404
user> (read-line)
nil
user>