Skip to content

Instantly share code, notes, and snippets.

class Task < ActiveRecord::Base
include Encoder
code :status do
Status::New = "N"
Status::Pending = "P"
Status::Finished = "F"
Status::OverDue = "O"
end
require 'rubygems'
require 'active_support'
class Foo
def talk(arg)
puts "talking about '#{arg}'"
end
end
class Bar
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
def localhost
reverse_lookup "127.0.0.1"
end
@jmorton
jmorton / github_require.rb
Created April 29, 2010 16:17
Load and evaluate gists
def gitget(uri)
# We look for very specific links within the page like:
# <a href="/raw/383785/5bcefcae03bbc40d6ce40591d93f278585e47950/example.rb">raw</a>
raw_uri_pattern = /\<a href="(.+)"\>raw\<\/a\>/
begin
# Load the referenced gist
gist_html = open(uri).read
# Playing with Thrift, Hbase, and Ruby (I created a table and added some values using Hbase shell earlier)
irb > transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost',9090))
=> #<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=nil, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">
irb > transport.open
=> #<Socket:0x10196a030>
irb > protocol = Thrift::BinaryProtocol.new(transport)
=> #<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=#<Socket:0x10196a030>, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">, @strict_write=true>
irb > client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
=> #<Apache::Hadoop::Hbase::Thrift::Hbase::Client:0x10195d448 @seqid=0, @oprot=#<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::Bu
@jmorton
jmorton / enscoped.rb
Created March 28, 2011 19:25
Helper method for building a named scope from a list of scope names
module Enscoped
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Create one named scope from many named scopes.
#
@jmorton
jmorton / gist:983379
Created May 20, 2011 17:34 — forked from dhh/gist:981520
bulk api
# Bulk API design
#
# resources :posts
class PostsController < ApplicationController
before_filter :separate_bulk_ids
# GET /posts/1
# params[:id] => 1
# params[:ids] => [ 1 ]
$ du -sh .git
260K .git
@jmorton
jmorton / passive_record.rb
Created September 27, 2011 22:13
Passive Record
# PassiveRecord disables all of the mutable behaviors of a class that behaves like an ActiveRecord::Base
module PassiveRecord
module Base
extend ActiveSupport::Concern
module InstanceMethods
def passive_record_benign_method(*args, &block)
return false
end
end