Skip to content

Instantly share code, notes, and snippets.

View rue's full-sized avatar

Rue Saynatkari rue

View GitHub Profile
@certainty
certainty / gist:3792694
Created September 27, 2012 07:33
generalized method chaining and array as applicative
class Array
def >>(other); self + [other]; end
def to_proc(*args)
->(r) { inject(r){ |o,(m,*args)| o.send(m,*args) } }
end
def apply(rec)
self.to_proc[rec]
end
@apeiros
apeiros / capabilities.rb
Created June 29, 2012 22:38
Require files and provide an interface to check what's available
Moved to https://github.com/apeiros/available
@zzak
zzak / util.rb
Created January 12, 2012 23:05
Catch all exceptions and airbrake them
require 'airbrake'
Airbrake.configure do |config|
config.api_key = AIRBRAKE_API_KEY
end
at_exit {
if $!
e = $!
Airbrake.notify(
@pkieltyka
pkieltyka / web_proxy.rb
Created December 27, 2011 21:37
web_proxy.rb
module Nulayer
class WebProxy
ENDPOINT = '/webp'
URL_PARAM_NAME = 'url'
attr_accessor :env, :params, :referred, :url
def initialize(env, params, referred=false)
self.env = env
self.params = params
@hitode909
hitode909 / SolarizedLight.css
Created December 7, 2011 03:30
Solarized like LimeChat theme
html {
font-family: "Monaco";
background-color: #fdf6e3;
color: #657b83;
word-wrap: break-word;
margin: 0;
padding: 3px 4px 10px 4px;
}
body {
@jdeerhake
jdeerhake / Sources
Created December 1, 2011 23:46
Let it snow
jQuerify:
http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
jQuery Snowfall:
http://www.somethinghitme.com/2011/10/05/jquery-snowfall-1-5-update-now-with-snow-buildup/
@apeiros
apeiros / dirtyhash.rb
Created July 8, 2011 19:27
A hash preserving changes made to it
require 'hash/dirty'
# DirtyHash behaves just like Hash, but keeps track of changes applied to it.
#
# @example
# dh = DirtyHash.with :x => 1
# dh.clean? # => true
# dh.update :y => 2, :z => 4
# dh.changed # => {:y => [:added, 2], :z => [:added, nil, 4]}
# dh[:z] = 3
@Twisol
Twisol / escaper.rb
Created May 16, 2011 20:13
JSON parser in kpeg
module StringEscaper
def process_escapes (str)
str.gsub! /\\(u\d{4}|\D)/m do
seq = $1
case seq
when '/' then "\/"
when 'b' then "\b"
when 'f' then "\f"
when 'n' then "\n"
when 'r' then "\r"
@jbarnette
jbarnette / example.rb
Created April 6, 2011 14:55
A naïve state machine for ActiveRecord. Ruby 1.9.
require "stateful"
class Folder < ActiveRecord::Base
include Stateful
# ...
stateful do
state :active
state :inactive