This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'yaml' | |
require 'term/ansicolor' | |
include Term::ANSIColor | |
# Usage: | |
# > rake test | bookmark # => Bookmark test output | |
# > bookmark 1 # => Open first failing test. | |
# > bookmark 2 # => Open second failing test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Adder | |
def initialize(a) | |
@a = a | |
end | |
def add_to(b) | |
@a + b | |
end | |
end | |
add_four_to = Adder.new(4).method(:add_to) | |
[1,2,3].map(&add_four_to) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function (req, res) { | |
// res.writeHead(200, {'Content-Type': 'text/plain'}); | |
// res.end('Hello World\n'); | |
}).listen(1337, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:1337/'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
class Rocker | |
include HTTParty | |
def initialize(timeout = 1) | |
self.class.default_timeout(timeout) | |
end | |
def rock | |
self.class.get("http://127.0.0.1:1337/") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-visible-bell () | |
(set-face-background 'mode-line "red") | |
(run-at-time "0.1 sec" nil | |
'(lambda () | |
(set-face-background 'mode-line "#e2962f")))) | |
(setq ring-bell-function #'my-visible-bell) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(a=0, b=1, c=(a > 100 ? exit : (puts a; fib(b, a+b)))) | |
return c | |
end | |
fib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# patch Ruby's Hash class to simplify access and improve error messages | |
# useful for digging through deeply nested hashes | |
class Hash | |
def dig(*keys) | |
#puts "dig: #{keys.inspect} #{self.inspect}" | |
if keys.empty? | |
return self | |
else | |
begin | |
v = self.fetch(keys.first) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BYTES_PER_SECTOR=512 # AFAIK this is constant for Mac OSX RAM disks | |
BYTES_PER_KILOBYTE=1024 | |
BYTES_PER_MEGABYTE=1024*1024 | |
BYTES_PER_GIGABYTE=1024*1024*1024 | |
def bytes_to_sectors(bytes) | |
sectors = (bytes / BYTES_PER_SECTOR).ceil | |
return sectors | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def dig(*keys) | |
#puts "dig: #{keys.inspect} #{self.inspect}" | |
if keys.empty? | |
return self | |
else | |
begin | |
v = self.fetch(keys.first) | |
return v if(keys.size.eql?(1)) | |
v.dig(*keys.drop(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dawn.topology | |
(:import [backtype.storm StormSubmitter LocalCluster]) | |
(:use [backtype.storm clojure config]) | |
(:gen-class)) | |
(defspout random-spout ["random-float"] | |
[conf context collector] | |
(spout | |
(ack [id] | |
(println "random-spout ack")) |