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
@peterhellberg
peterhellberg / kick.rb
Created September 3, 2012 20:49
Tiny File System Event kicker
#!/usr/bin/env ruby
require 'rubygems'
require 'rb-fsevent'
cmd, *paths = ARGV
if cmd && paths.any?
system cmd
fsevent = FSEvent.new
fsevent.watch(paths) { system cmd }
fsevent.run
@peterhellberg
peterhellberg / transform_hash.rb
Created October 19, 2012 15:08
Hash Autovivification and eval trickery
data = {
"section1.stuff"=>"as",
"section1.stuff2" => "qw",
"section2.stuff3" => "zx"
}
hash = Hash.new(&(p=lambda{|h,k|h[k]=Hash.new(&p)}))
data.each_with_object(hash) { |(k,v), h|
eval "h['#{k.gsub('.',"']['")}']='#{v}'"
@peterhellberg
peterhellberg / loadbalancer.go
Created October 28, 2012 01:01
A small loadbalancer API written in Go (Using Pat and Redigo)
package main
import (
"io"
"fmt"
"time"
"net/http"
"encoding/json"
"github.com/bmizerany/pat"
"github.com/garyburd/redigo/redis"
@peterhellberg
peterhellberg / barcamp_stockholm_scraper.rb
Last active December 14, 2015 17:08
A small scraper for the list of attendees on http://barcampstockholm.com/
require 'open-uri'
require 'nokogiri'
module BarCampStockholm
class << self
def url
'http://barcampstockholm.com/'
end
@peterhellberg
peterhellberg / yclist_scraper.rb
Created March 12, 2013 09:54
A simple little scraper for the YC List
require 'open-uri'
require 'nokogiri'
module YCList
class << self
def url
'http://yclist.com/'
end
@peterhellberg
peterhellberg / my_json.rb
Last active December 15, 2015 03:39 — forked from jmettraux/my_json.rb
Initial experiments with Parslet
#
# MIT License - (c) 2011 John Mettraux
#
# Slightly modified - 2013 Peter Hellberg
#
require 'parslet'
module MyJSON
class Parser < Parslet::Parser
@peterhellberg
peterhellberg / orange_shoes.rb
Created March 19, 2013 16:05
Playing around with Shoes
Shoes.app do
border "#FF6600", strokewidth: 6
background "#FF6600".."#CC0000"
fill rgb(255,102,0, 0.5)
stroke rgb(255,102,0, 0.9)
strokewidth 0.25
ovals = 40.times.map do
@peterhellberg
peterhellberg / download-dnd.rb
Last active December 15, 2015 11:49
A small Ruby script that downloads the free DnD books from RiotMinds.
require 'open-uri'
require 'nokogiri'
url = 'http://www.riotminds.se/drakar-och-demoner/tiden-innan-trudvang/'
doc = Nokogiri::HTML(open(url))
doc.css('#content .column_left a').map do |a|
title = a.css("img").first.attributes["title"]
href = a.attributes["href"].to_s
cmd = "curl -L #{href} -o \"/tmp/#{title}.pdf\""
@peterhellberg
peterhellberg / arch_linux_on_raspberry_pi.markdown
Created May 13, 2013 17:58
Tips and tricks for running Arch Linux on the Raspberry Pi

Expand rootfs (to use full SD card capacity)

fdisk /dev/mmcblk0
# Delete the second partition /dev/mmcblk0p2
d
2
# Create a new primary partition and use default sizes prompted. This will then create a partition that fills the disk
n
p
@peterhellberg
peterhellberg / daylight.rb
Created May 15, 2013 20:29
Controlling an Arduino using the Dino gem.
require 'dino'
# Slightly nicer interface to the Arduino :)
module Dino
class << self
def board
@board ||= Board.new TxRx.new
end
def method_missing(m, pin)