Skip to content

Instantly share code, notes, and snippets.

View shostakovich's full-sized avatar
🚩
Focusing

Robert Curth shostakovich

🚩
Focusing
View GitHub Profile
@shostakovich
shostakovich / gist:3803457
Created September 29, 2012 07:55
Prime factor
describe PrimeFactorDecomposer do
include PrimeFactorDecomposer
it "returns no prime factors for 1" do
decompose(1).should be_empty
end
end
@shostakovich
shostakovich / prime_factor_decomposer.rb
Created September 29, 2012 15:37
Lessons from the prime factorization dojo
module PrimeFactorDecomposer
def decompose(number)
if number < 4
number
else
[2,2]
end
end
end
@shostakovich
shostakovich / gist:3806384
Created September 30, 2012 10:11
LED USB LAMP
/* LED USB Lamp
This program controls a high power LED via PWM and reads in a touch pad.
The circuit: * LED attached from digital pin 3 to ground. * touch pad connected to pin 6 and 5
Created 18 Aug 2012 By Sebastian Schuster
*/
@shostakovich
shostakovich / bootstrap.sh
Created October 1, 2012 17:16
Chef Solo on Mac OS X - examples
#!/bin/sh
USERNAME=shostakovich
mkdir ~/tmp
cd ~/tmp
# Install GCC + Git
curl https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg > GCC-10.7-v2.pkg
sudo installer -pkg GCC-10.7-v2.pkg -target /
@shostakovich
shostakovich / aritmethics.rb
Created October 7, 2012 11:36
Set.rb illuminated
# given enumerable object.
def |(enum)
dup.merge(enum)
end
alias + | ##
alias union | ##
# Returns a new set built by duplicating the set, removing every
# element that appears in the given enumerable object.
def -(enum)
class EratosthenesGenerator < PseudoPrimeGenerator
def initialize
@last_prime = nil
super
end
def succ
@last_prime = @last_prime ? EratosthenesSieve.instance.next_to(@last_prime) : 2
end
class PseudoPrimeGenerator
include Enumerable
def initialize(ubound = nil)
@ubound = ubound
end
def upper_bound=(ubound)
@ubound = ubound
end
@shostakovich
shostakovich / pressure_sensor.rb
Created November 26, 2012 13:23
Pressure Sensor
class Sensor
OFFSET_IN_MBAR = 1000
def current_pressure
OFFSET_IN_MBAR + random_pressure();
end
private
def random_pressure
@shostakovich
shostakovich / .hash_style_accessors.rb
Created November 30, 2012 12:13
Reading of OpenStruct
def [](name)
@table[name.to_sym]
end
def []=(name, value)
modifiable[new_ostruct_member(name)] = value
end
@shostakovich
shostakovich / .gitconfig
Last active December 14, 2015 15:49
Pre-push hook that rejects force pushes to master. Requires Git 1.8.2 and above.
[push]
default = current
[alias]
pfush = "push --force"