Skip to content

Instantly share code, notes, and snippets.

require [
#data
'models/options'
'models/ui'
#thin models
'models/optionsOptions'
'models/optionsClubHead'
'models/optionsGrip'
'models/optionsShaft'
'models/optionsLengthWrap'
task :foo do
puts "bar"
end
task :foo do
puts "baz"
end
rake foo
#=> "bar"
# shell
mkfifo mypipe
# ruby
open('mypipe', 'r+b'){ |f| puts f.gets(nil) }
# shell
(ns bit-sandbox.core)
; helper
(defn shifted-byte [int-byte-value, shift-by]
(bit-shift-left
(bit-and int-byte-value 0xFF)
(* shift-by 8)))
; (+ meat potatoes)
validClickElementCallbacks: [
(el) -> $(el)[0].tagName.match(/li/i) && $(el)[0].className.match(/day/),
(el) -> $(el)[0].tagName.match(/span/i) && $(el)[0].className.match(/remaining/),
(el) -> $(el)[0].tagName.match(/h3/i)
]
bindEvents: ->
@element.click (e) =>
return unless _.any(@validClickElementCallbacks, (fn) -> fn(e.target))
it 'creates a participant after clicking `confirm' do
load_page
click_on '10:00 am'
# Not sure why the ActiveRecord connection is becoming
# stale...probably something to do with the way capybara runs tests
# with selenium.
#
# Symptom that led to the change:
# Running this in isolation without refreshing the connection would
def try_cached_event
unless (id = cookies[Event::IDENTITY_KEY]) && (event = Event.find_by_id(id))
cookies[Event::IDENTITY_KEY] = { expires: 1.day.ago }
return
end
redirect_to event_participants_url(event)
end
# Gets the last gist for specified user
#
# last gist [for] <username> - Returns the last gist for specified user
module.exports = (robot) ->
robot.respond /last gist (?:for)? (.+)/i, (msg) ->
username = msg.match[1]
url = "https://api.github.com/users/#{username}/gists"
msg.http(url).get() (err, res, body) ->
gists = JSON.parse(body)
indexed = {}
@jtrim
jtrim / listcomp.erl
Created August 19, 2011 05:58
Erlang nested list comprehensions - an anagram example
-module(listcomp).
-export([perms/1]).
% generates all possible letter permutations given a string of letters
perms( [] ) -> [[]];
perms(Phrase) ->
[ [H|Rest] ||
H <- Phrase,
Rest <- perms(Phrase -- [H])].
@jtrim
jtrim / symbolize_keys.rb
Created April 14, 2011 20:17
Methods to help turn all hash keys into symbols
class Hash
def symbolize_keys
replace( keys.inject({}) { |new_hash,key| new_hash[key.to_sym] = self[key]; new_hash } )
end
def symbolize_keys!
symbolized_hash = keys.inject({}) do |new_hash,key|
new_hash[key.to_sym] = self[key]
new_hash[key.to_sym].symbolize_keys! if new_hash[key.to_sym].respond_to? :symbolize_keys!
new_hash