Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
if [ "$1" ]; then
BRANCH=$1
else
BRANCH=$(git branch | grep '*' | cut -d ' ' -f2)
fi
REMOTE=$(git config --get branch.$BRANCH.remote)
REMOTE_BRANCH=$(git config --get branch.$BRANCH.merge)
echo "$REMOTE/${REMOTE_BRANCH##*/}"
framework 'Cocoa'
# Documentation for delegates:
# http://developer.apple.com/mac/library/documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
class RSSParser
attr_accessor :parser, :xml_url, :doc
def initialize(xml_url)
@xml_url = xml_url
framework 'Cocoa'
# Documentation for delegates:
# http://developer.apple.com/mac/library/documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
class RSSParser
attr_accessor :parser, :xml_url, :doc
def initialize(xml_url)
@xml_url = xml_url
@mattyoho
mattyoho / url_dsl.rb
Created December 14, 2009 19:34 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@mattyoho
mattyoho / gist:256527
Created December 14, 2009 23:03 — forked from evan/gist:256524
class Class
def memoize(*methods)
methods.each do |method_name|
safe_method_name = method_name.to_s.gsub(/(\!|\?)/, '_')
class_eval("
alias :'#{safe_method_name}_without_memo' :'#{method_name}'
def #{method_name}
if defined?(@#{safe_method_name})
@#{safe_method_name}
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
require 'benchmark'
def each_acc list
foos = []
list.each do |letter|
foos << letter.to_i
end
foos
end
namespace :harmony do
desc "Munges the data"
task :munge => :environment do
docs_with_publish = Item.collection.find({'publish' => {'$exists' => true}}).to_a
puts "Item count: #{Item.count}"
puts "Items with publish key: #{docs_with_publish.size}"
docs_with_publish.each do |hash|
hash.delete('publish')
require 'pp'
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = 'testing'
class Rating
include MongoMapper::EmbeddedDocument
key :user_id, ObjectId

A (Nicer) Redis Client for EventMachine

Redis is my favourite key/value store; it’s flexible, easy to set up and insanely fast. [EventMachine][] is a popular Ruby library for doing asynchronous I/O using an event loop. Bindings already [exist][em-redis] for accessing a Redis server using EM’s async-I/O (courtesy of Jonathan Broad), but unfortunately the resulting code has to use [Continuation-Passing Style][cps] via Ruby blocks. A very basic example of what that looks like follows: