Skip to content

Instantly share code, notes, and snippets.

View pdg137's full-sized avatar

Paul Grayson pdg137

  • Pololu Robotics and Electronics
  • Las Vegas, NV
View GitHub Profile
@pdg137
pdg137 / modules.rb
Last active January 17, 2017 20:47
module M
A = 1
end
module M::N
B = 2
end
class M::N::C
prepend M::N
#!/usr/bin/ruby
require 'i2c'
bus = I2C.create('/dev/i2c-1')
bus.write(20, 200, "abcd")
bus.write(20, 201, "bcde")
while true
raise if "abcde" != bus.read(20, 5, 200)
@pdg137
pdg137 / gist:5a37ebaa860cac7aeeca
Created November 6, 2014 08:33
Regex for testing divisibility by three
/^([147][0369]*[258]|([147][0369]*[147]|[258])([258][0369]*[147]|[0369])*([258][0369]*[258]|[147])|[0369])+$/
@pdg137
pdg137 / gist:9554958
Created March 14, 2014 19:26
Random seeds in rspec contexts
describe Random do
specify do
puts "Random seed was #{Random.srand}"
end
specify do
puts "Random seed was #{Random.srand}"
end
context "A" do
@pdg137
pdg137 / gist:8062980
Created December 20, 2013 22:55
Spot the bug
# Old version
def f(a)
return a == 1 ||
a == 2 ||
a == 3
end
# New version removing the a == 1 case
def f(a)
return
Timecop.freeze(DateTime.parse('2013-07-01 00:00 -0700')) { puts DateTime.now }
# -> 2013-06-30T23:00:00-08:00
describe "rspec" do
context "using .each" do
[1,2].each do |x|
let(:y) { x }
specify "#{x} == #{x}" do
y.should == x
end
end
end
@pdg137
pdg137 / paul-sumo-2.c
Last active May 8, 2017 20:50
Code from "Paul Sumo 2", my winning entry in the LVBots sumo competition. This is an app for the Pololu Wixel that I compiled using the Wixel SDK.
#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <adc.h>
#include <stdio.h>
uint32 start_ms;
void resetTime()
{