Skip to content

Instantly share code, notes, and snippets.

@stevenwilkin
stevenwilkin / config.ru
Last active August 29, 2015 14:17
Rack redirector
app = lambda do |env|
[301, {'Location' => 'https://www.pensionwise.gov.uk/'}, []]
end
run app
Date: Tue, 30 Sep 2014 16:49:43 +0000
From: Louis Goff-Beardsley <louis@infinitiumglobal.com>
To: London Ruby Users Group <chat@lists.lrug.org>
Subject: [LRUG] [JOBS] Contracts Galore
Message-ID: <48267692359843abb6ad091ab5441d3d@SEHSTE15D2BE3.hs20.net>
Content-Type: text/plain; charset="iso-8859-1"
Hi LRUG,
Just a quick note, the yearly "Just got back from holiday, oh God we need more development done" contracts rush has come and we've been inundated with requests for upper-Mid level & Senior Ruby and/or Javascript contractors.
@stevenwilkin
stevenwilkin / delete_gemsets.sh
Created October 2, 2014 13:26
Delete all gemsets for all rubies managed by RVM
#!/bin/bash -l
for RUBY in `rvm list strings`
do
rvm use $RUBY
for GEMSET in `rvm gemset list | grep -E '^ ' | grep -v '*'`
do
rvm --force gemset delete $GEMSET
done
done
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@stevenwilkin
stevenwilkin / fizz_buzz.go
Created December 25, 2013 00:35
FizzBuzz in Go
package main
func main() {
for i:= 1; i <= 100; i++ {
if (i % 3 == 0) && (i % 5 == 0) {
println("FizzBuzz")
} else if i % 3 == 0 {
println("Fizz")
} else if i % 5 == 0 {
println("Buzz")
@stevenwilkin
stevenwilkin / gist:6727189
Created September 27, 2013 11:24
Calculating memcached miss-rate
HITS=`echo "stats" | nc 127.0.0.1 11211 | grep get_hits | awk '{print $3}' | sed 's/[^0-9]//'`
MISSES=`echo "stats" | nc 127.0.0.1 11211 | grep get_misses | awk '{print $3}' | sed 's/[^0-9]//'`
echo "($MISSES * 100) / ($HITS + $MISSES)" | bc
# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'
require 'net/http'
require 'rack'
# todo
# - detect ssl
# - keepalive?
module Rack
class Forwarder
def initialize(host, port=80)
@stevenwilkin
stevenwilkin / p01-matraka-explained.js
Created August 15, 2012 14:15 — forked from tlack/p01-matraka-explained.js
p01's Matraka javascript demo decoded
// Matraka's source code decoded and beautified
// by @tlack
//
// Matraka is a 1005 byte Javascript "demo" by p01. It includes an 'evolving animation'
// and great dirty synth music. View here:
//
// http://www.p01.org/releases/MATRAKA/matraka.png.html
//
// I fondly recall the demo scene of my youth, puzzling over the work of Future
// Creators and those guys. I was puzzled by this worked so I had to figure it
@stevenwilkin
stevenwilkin / tweet.rb
Created August 1, 2012 11:48
Old example of sending a tweet programmatically
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter' # 1.0
Twitter.configure do |config|
config.consumer_key = ''
config.consumer_secret = ''
config.oauth_token = ''
config.oauth_token_secret = ''