Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
ryanbriones / gist:3062772
Created July 6, 2012 21:12
A Storm ShellBolt written in R; logs the message and acks it
library(RJSONIO)
cStdin <- file('stdin')
open(cStdin)
readMessage <- function() {
message <- c()
while(length(line <- readLines(cStdin, n = 1)) > 0) {
if(line == "end") { break }
message <- c(message, line)
@ryanbriones
ryanbriones / pomodoro.html
Created December 1, 2011 02:07
Prototype pomodoro timer
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
</head>
class String
def method_missing(*args)
if args.first.to_s.match(/omnom/)
noms = args.first.to_s.scan(/nom/).length
self[0..-(noms+1)]
else
super
end
end
end
mov esi, 1000
mov eax, 0
loop:
cmp eax, esi
je end
mov ebx, eax
mod ebx, 3
rem ebx
cmp ebx, 0
@ryanbriones
ryanbriones / mysql_store.rb
Created August 19, 2011 22:20
Code for an object mapper using plain ruby objects. Goal: make it easier to focus on creating objects based on behavior and only care about persistence at the very end
mysql = MysqlStore.new
person_mapper = mysql.generate_table_mapping("person") do
map :first_name
map :last_name
map :dob, :dob_to_s_db
end
a = Person.new
a.first_name = "Ryan"
a.last_name = "Briones"
class ConvertsNumberAlphaID
ALPHAS = %w( a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 0 1 2 3
4 5 6 7 8 9
A B C D E F
G H I J K L
M N O P Q R
@ryanbriones
ryanbriones / gist:1066683
Created July 6, 2011 06:35
Towers of Hanoi
class Tower
attr_reader :name
def initialize(name)
@name = name
@disks = []
end
def stack(disk_number)
raise "Disk too big" unless can_stack?(disk_number)
class Foo
def deadline_string=(deadline_string)
self.deadline = (parse_string(deadline_string, Chronic) || parse_string(deadline_string, Time))
@deadline_invalid = true unless self.deadline
end
private
def parse_string(string, parser)
begin
parser.parse(string)
#!/usr/bin/env ruby
# From: https://github.com/ryanbriones/cgiup/blob/master/bin/cgiup
require 'webrick'
unless ARGV[0]
STDERR.puts "usage: cgiup [PATH TO CGI SCRIPT]"
exit 1
end
cgi_script = File.expand_path(ARGV[0])
@ryanbriones
ryanbriones / server.rb
Created April 22, 2011 01:12
basic event machine pubsub for ChicagoRuby
#!/usr/bin/env ruby
require "rubygems"
require "eventmachine"
class PubSubServer < EM::Connection
attr_accessor :channels
SubscriberChannel = EM::Channel.new