Skip to content

Instantly share code, notes, and snippets.

View adammck's full-sized avatar

Adam Mckaig adammck

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
body {
@adammck
adammck / example.sql
Created February 6, 2014 03:53
Track updated rows across multiple tables with Postgres
CREATE SEQUENCE sync_id;
CREATE FUNCTION bump_sync_id() RETURNS trigger AS $$
begin
NEW.sync_id := nextval('sync_id');
RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;
CREATE TABLE dogs (id SERIAL, name VARCHAR NOT NULL, sync_id INTEGER NOT NULL);
@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")
@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 / 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 / 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 / .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 / 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 / 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: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);