Skip to content

Instantly share code, notes, and snippets.

View adammck's full-sized avatar

Adam Mckaig adammck

View GitHub Profile
@adammck
adammck / rvm [un]export
Created January 8, 2011 08:37
a quick example session using my rvm fork, demonstrating 'rvm export' in rvmrc.
# see:
# https://github.com/adammck/rvm
# no env vars are defined:
$ echo $TWITTER_API_KEY
# rvm isn't enabled as default:
$ which ruby
/usr/bin/ruby
@adammck
adammck / gist:1314693
Created October 25, 2011 23:08
Temporarily patch the Rails configuration for the duration of a block
# Temporarily patch the Rails configuration for the duration of a block.
# For example:
#
# test "should create a resque job when background_jobs is true" do
# with_config :background_jobs=>true do
# repo = Repo.create :url=>TEST_CLONE_URL
# assert_queued(CloneJob, [repo.pk])
# end
# end
#
@adammck
adammck / gist:1954319
Created March 2, 2012 00:41
How much have you paid GitHub?
Log in and visit:
https://github.com/settings/payments
Then in the console:
$("table#payment-history tr.success td.amount").toArray().reduce(function(a, b) {
var dollars = b.innerHTML.replace(/[^\d\.]/g, "");
return a + parseFloat(dollars);
}, 0);
@adammck
adammck / call_spy.rb
Created January 8, 2013 02:35
Track method calls (all of them) for the duration of a block.
def call_spy
calls = []
depth = 0
set_trace_func proc { |event, file, line, id, binding, classname|
if id != :set_trace_func
if (event == "c-call" || event == "call")
indent = " " * (depth * 2)
calls << "#{indent}#{classname}##{id}"
depth += 1
@adammck
adammck / gist:4635994
Created January 25, 2013 16:52
Stub out all Elastic Search queries with a 500 error
FakeWeb.register_uri(:any, %r{^http://(.+?):9200/}, :body=>"", :status=>500)
@adammck
adammck / .ruby-version
Last active December 16, 2015 05:19
Example of shared_connection hack causing "Mysql2::Error: This connection is still waiting for a result"
1.9.3-p194
@adammck
adammck / Gemfile
Last active December 17, 2015 16:30
source "https://rubygems.org"
gem "sinatra"
gem "sinatra-contrib"
gem "sequel"
gem "sqlite3"
gem "multi_json"
group :development do
gem "shotgun"
@adammck
adammck / flash_dynamixel_led.py
Created January 3, 2014 02:43
Flash the LED on a Dynamixel servo
#!/usr/bin/env python
import time
import optparse
import dynamixel
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-p", "--port", help="Serial port", default="/dev/tty.usbserial-A9ITPZVR")
parser.add_option("-b", "--baud", help="Baud rate", default="1000000")
@adammck
adammck / change_dynamixel_id.py
Created January 3, 2014 03:02
Change a the ID of a Dynamixel servo
#!/usr/bin/env python
import sys
import time
import optparse
import dynamixel
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-p", "--port", help="Serial port", default="/dev/tty.usbserial-A9ITPZVR")
@adammck
adammck / test_dynamixels.py
Created January 3, 2014 03:43
Move Dynamixel servos randomly (to make sure they're working)
#!/usr/bin/env python
import time
import random
import optparse
import dynamixel
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-p", "--port", help="Serial port", default="/dev/tty.usbserial-A9ITPZVR")