Skip to content

Instantly share code, notes, and snippets.

class Module
# Takes symbols representing instance methods defined in the module.
# Returns a new anonymous module with only those instance methods defined.
def slice(*methods)
src = self
Module.new do
methods.each do |sym|
define_method(sym, src.instance_method(sym))
end
end
@jamesmacaulay
jamesmacaulay / gist:375a1fc9eacded79bcdc
Created June 14, 2014 16:58
github.io https -> http redirect
$ curl -I https://shopify.github.io/dashing/
HTTP/1.1 200 OK
Date: Sat, 14 Jun 2014 16:57:15 GMT
Server: GitHub.com
Content-Type: text/html; charset=utf-8
Last-Modified: Wed, 07 May 2014 03:44:03 GMT
Expires: Sat, 14 Jun 2014 17:07:15 GMT
Cache-Control: max-age=600
Content-Length: 15154
Accept-Ranges: bytes
debounce : Time -> Signal a -> Signal a
debounce t sig = sig |> sampleOn (Time.since t sig |> keepIf not False)
import Mouse
import Array
buildAppDataMap delta pos history =
{ frameDelta=delta
, mousePosition=pos
, clickHistory=history }
arrayTakeLast n array =
let inputLen = Array.length array
module AttributeReaders
class <<self
# str = "foo"
# overrides = {
# another_reverse: :reverse,
# exclaimed: ->(str) { str + "!" },
# to_sym: ->(str) { str.reverse.to_sym }
# }
# reader = AttributeReaders.object_reader(str, overrides)
# [:reverse, :another_reverse, :exclaimed, :to_sym].map(&reader)
#!/usr/bin/env ruby
# gemmate
# open the directory of a rubygem as a project in textmate
# responds to anything that `gem which` can handle
# e.g.:
# gemmate autotest
# => `mate /Library/Ruby/Gems/1.8/gems/ZenTest-3.11.0`
# gemmate active_record
# => `mate /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2`
#!/usr/bin/env ruby
# branchmate
# opens whichever files you've modified in this git branch compared to master
target = ARGV[0] || 'master'
p (cmd = "git diff #{target} --name-only")
files = `#{cmd}`.split.reject {|f| f =~ /^vendor/}
puts files.join("\n")
# debug_in
# call debugger only when the stack trace includes a certain file and/or method
#
# use like:
# debug_in(:file => 'order_test', :method => 'test_taxes_included')
# debug_in(:r => /taxes.*included/)
#
# put in test_helper.rb
def debug_in(options = {})
debugger if caller.detect {|c| c =~ /#{(options[:file].to_s + ".rb") if options[:file]}.*#{("`" + options[:method].to_s + "'$") if options[:method]}/ && c =~ (options[:r] || //)}
<ul>
<r:feed:items
url="http://feeds.boingboing.net/boingboing/iBag"
order="creator ASC">
<r:feed:header for="creator">
<h2><r:feed:creator /></h2>
</r:feed:header>
function bd {
if [ -z $1 ]; then
n=1
else
n=$1
fi
pushd +$n > /dev/null
}
function fd {