Skip to content

Instantly share code, notes, and snippets.

View peterhellberg's full-sized avatar
💙
Coding Go

Peter Hellberg peterhellberg

💙
Coding Go
View GitHub Profile
module Athega
class LonemodellWithJSON < Lonemodell
def to_json(*args)
Yajl::Encoder.encode(to_hash)
end
end
end
@peterhellberg
peterhellberg / blunderbuss.sh
Created April 5, 2011 14:54
Launch shotgun, listening to the first IP
function blunderbuss {
if [ -z "$1" ]; then
PORT=9393
else
PORT=$1
fi
IP=`ifconfig | grep -m 1 broadcast | awk '{print $2}'`
shotgun -s thin -o $IP -p $PORT
}
@peterhellberg
peterhellberg / fun_with_the_ruby_19_stl.rb
Created April 7, 2011 00:27
Fun with the Ruby 1.9 Standard Library
require 'set'
# Sorted list of random numbers
pp 10.times.each_with_object(SortedSet.new) { |n, s| s << Random.new.rand(1..100) }
# Associative arrays
aoa = ('a'..'l').each_slice(2).to_a
Hash[aoa] #=> {"a"=>"b", "c"=>"d", "e"=>"f", "g"=>"h", "i"=>"j", "k"=>"l"}
@peterhellberg
peterhellberg / button_press.rb
Created April 7, 2011 16:17
Playing with Lego Mindstorms (NXT 2.0)
require 'serialport'
require 'nxt'
# Connect to the Lego NXT
nxt = NXT.new
# Get the touch sensor
ts = TouchSensor.new(nxt)
while true
@peterhellberg
peterhellberg / sass-watch.sh
Created April 14, 2011 12:56
Converting SCSS to CSS when a new file is saved.
function sass-watch {
if [ -z "$3" ]; then
SASS_IN='all.scss'
CSS_OUT='all.css'
SASS_WATCH_PATH='.'
else
SASS_IN=$1
CSS_OUT=$2
SASS_WATCH_PATH=$3
fi
@peterhellberg
peterhellberg / first.rb
Created April 23, 2011 20:37
Test: Multiple files in the same Gist
puts "first file"
@peterhellberg
peterhellberg / reset_fan_speed.sh
Created December 13, 2011 16:32
Control the fan speed of the Macbook Air
#!/bin/sh
smc=/Applications/smcFanControl.app/Contents/Resources/smc
min_hex=$(python -c "print hex("2000" << 2)[2:]")
max_hex=$(python -c "print hex("6500" << 2)[2:]")
${smc} -k F0Mn -w ${min_hex}
${smc} -k F0Mx -w ${max_hex}
@peterhellberg
peterhellberg / .rvmc
Created January 9, 2012 22:20
ArgumentError after include Goliath::TestHelper
rvm --create use 1.9.3@goliath-wrong-number-of-arguments
@peterhellberg
peterhellberg / Guardfile
Created January 12, 2012 15:08
External JSON API testing (using minitest/spec, rest-client and yajl-ruby)
guard 'shell' do
watch(/relation_tree_spec\.rb/) { `clear && ruby relation_tree_spec.rb` }
end
@peterhellberg
peterhellberg / .bash_profile
Created February 23, 2012 11:29
Small .bash_profile and .vimrc for a brand new server
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin