Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
@rjungemann
rjungemann / email.rb
Created February 25, 2010 07:28
Send an email over IMAP using Ruby
# http://www.tutorialspoint.com/ruby/ruby_sending_email.htm
# http://www.devco.net/archives/2009/10/27/using_ruby_netimap_with_plain_auth.php
require 'net/smtp'
require 'net/imap'
message = <<MESSAGE_END
From: Private Person <[email protected]>
To: A Test User <[email protected]>
MIME-Version: 1.0
@rjungemann
rjungemann / transact.rb
Created February 25, 2010 23:00
Moneta transactions
# This code adds an instance method called "transact" to all Moneta stores.
# You pass it a key and a block, and it pipes in the value for that key in the
# store. Whatever gets returned by the block gets saved over the value in the
# store.
module Moneta
module Expires
def transact(key, &blk); self[key] = yield(self[key]) end
end
end
@rjungemann
rjungemann / dispatcher.rb
Created February 26, 2010 03:19
Simple Ruby event dispatcher
# simple event dispatcher implementation
module Evented
class Dispatcher < Array
def call *args; self.each do |e|; e.call *args end end
end
class Dispatchers < Hash
def call name, *args; self[name].call(*args) if self[name] end
end
@rjungemann
rjungemann / router.js
Created March 11, 2010 19:52
Empty Node HTTP server
// contents of matchUrl code are a slightly modified version of the matchRequest code found
// in the nerve library for node.js http://github.com/gjritter/nerve/blob/master/lib/nerve.js
function matchUrl(matcher, req) {
if(typeof matcher === 'string') return(matcher === req.url);
else if(matcher.constructor === RegExp) return req.url.match(matcher);
else return req.url.match(matcher.apply(req));
}
exports.route = function(servlets, req, res) {
for(var i = 0; i < servlets.length; i++) {
@rjungemann
rjungemann / rm_svn.sh
Created March 11, 2010 23:11
Remove hidden svn files
#!/bin/bash
# removes hidden svn files.
# run it like so:
# rm_svn .
# based off of code found at http://niquimerret.com/?p=116
function rm_svn {
find $1 -name ".svn" | xargs rm -Rf
}
@rjungemann
rjungemann / tail_example.coffee
Created March 11, 2010 23:51
CoffeeScript text streaming example (`tail -f` example)
# text streaming example ported from JavaScript
# http://blog.new-bamboo.co.uk/2009/12/7/real-time-online-activity-monitor-
# example-with-node-js-and-websocket
process.mixin require 'sys'
filename: process.ARGV[2]
return puts "Usage: coffee watcher.coffee filename" unless filename
@rjungemann
rjungemann / sdl_gfx.rb
Created March 14, 2010 20:39
SdlGfx homebrew formula
require 'formula'
class SdlGfx <Formula
url 'http://www.ferzkopp.net/Software/SDL_gfx-2.0/SDL_gfx-2.0.20.tar.gz'
homepage 'http://www.ferzkopp.net/joomla/content/view/19/14/'
md5 '8a787e538a8e4d80d4927535be5af083'
depends_on 'sdl'
def install
@rjungemann
rjungemann / bullet.rb
Created March 16, 2010 21:53
Bullet homebrew formula
# First attempt at a bullet physics formula.
require 'formula'
class Bullet <Formula
head 'http://bullet.googlecode.com/svn/trunk'
homepage 'http://code.google.com/p/bullet/'
depends_on 'cmake'
@rjungemann
rjungemann / rfc2822.rb
Created March 22, 2010 22:05
Ruby print time as rfc2822
# http://griffin.oobleyboo.com/archive/ruby_rfc2822/
class Time
def rfc2822
sprintf(
"%.3s, %02d %.3s %04d %02d:%02d:%02d %s", Date::DAYNAMES[self.wday], self.day,
Date::MONTHNAMES[self.mon], self.year, self.hour, self.min, self.sec, self.zone
)
end
end
@rjungemann
rjungemann / evented_redis.rb
Created March 31, 2010 02:26
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
# http://gist.github.com/348262
# Incomplete evented Redis implementation specifically made for
# the new PubSub features in Redis.
require 'stringio'
require 'rubygems'
require 'eventmachine'