Skip to content

Instantly share code, notes, and snippets.

View bittersweet's full-sized avatar

Mark Mulder bittersweet

View GitHub Profile
@bittersweet
bittersweet / gist:5634954
Created May 23, 2013 09:38
run ctags on current project and every gem
View gist:5634954
$ ctags -R --exclude=.git --exclude=log * ~/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/*
@bittersweet
bittersweet / Array with instances benchmark
Created December 14, 2012 09:53
Quick Benchmark to check what kind of array 'slicing' performs well
View Array with instances benchmark
require 'benchmark'
class User
def initialize
@instance_var = rand(100)
end
end
users = []
10000.times do |i|
@bittersweet
bittersweet / gist:3892492
Created October 15, 2012 13:34
Wrapping an instance method
View gist:3892492
module Instrument
def instrument(method)
alias_method "#{method}_old", "#{method}"
define_method method do |*args|
t = Time.now.to_i
send("#{method}_old", *args)
result = Time.now.to_f - t
p "#{method}: #{result} seconds"
end
@bittersweet
bittersweet / gist:2249539
Created March 30, 2012 08:23
Mute OSX volume with MacRuby and AppleScript
View gist:2249539
framework "ScriptingBridge"
def volume(value)
volume = "set volume output volume #{value}"
applescript = NSAppleScript.alloc.initWithSource(volume)
result = applescript.executeAndReturnError(nil)
end
volume(0)
@bittersweet
bittersweet / gist:1901637
Created February 24, 2012 15:28 — forked from stephankaag/gist:1901565
DataMapper collection bug
View gist:1901637
require 'rubygems'
dm_version = "=1.2.0"
gem "dm-core", dm_version
require 'dm-core'
gem "dm-migrations", dm_version
require 'dm-migrations'
class Thing
@bittersweet
bittersweet / gist:1467545
Created December 12, 2011 14:40
autovivicating hash
View gist:1467545
def autovivicating_hash
Hash.new {|ht,k| ht[k] = autovivicating_hash}
end
x = autovivicating_hash
x["a"]["b"]["c"] = 1
@bittersweet
bittersweet / gist:1219121
Created September 15, 2011 12:32
Creating a capped collection via the mongo ruby driver
View gist:1219121
require 'mongo'
m = Mongo::Connection.new
db = m['metric_io_development']
db.create_collection('incoming', {:capped => true, :max => 10})
# https://github.com/bcg/em-mongo/blob/master/lib/em-mongo/database.rb#L117
@bittersweet
bittersweet / gist:1211139
Created September 12, 2011 12:26
Goliath logger middleware
View gist:1211139
module Goliath
module Rack
class Logger
include Goliath::Rack::AsyncMiddleware
def initialize(app)
super(app)
end
def call(env)
@bittersweet
bittersweet / gist:998960
Created May 30, 2011 14:19
how to insert current file with vimscript
View gist:998960
function! InsertCurrentFile()
let filename = expand("%:p")
execute "normal a".filename
endfunction
:call InsertCurrentFile
View faye debug chrome
assets.denachtdienst.org/javascripts/james.js?1283993145:152010-09-09 11:25:16 [INFO] [Faye.Client] New client created for "http://denachtdienst.org:8000/faye"
assets.denachtdienst.org/javascripts/james.js?1283993145:152010-09-09 11:25:16 [DEBUG] [Faye.Transport] Created new "callback-polling" transport for "http://denachtdienst.org:8000/faye"
assets.denachtdienst.org/javascripts/james.js?1283993145:152010-09-09 11:25:16 [INFO] [Faye.Client] Initiating handshake with "http://denachtdienst.org:8000/faye"
assets.denachtdienst.org/javascripts/james.js?1283993145:152010-09-09 11:25:16 [DEBUG] [Faye.Transport] Client undefined sending message to "http://denachtdienst.org:8000/faye": [{"channel":"/meta/handshake","version":"1.0","supportedConnectionTypes":["callback-polling"],"id":"1ginf3l17dssdu1g6u5of1yhkx9i"}]
assets.denachtdienst.org/javascripts/james.js?1283993145:152010-09-09 11:25:16 [DEBUG] [Faye.Transport] Client undefined received from "http://denachtdienst.org:8000/faye": [{"id":"1ginf3l17dssdu1g6u5of1yh