Skip to content

Instantly share code, notes, and snippets.

View olleolleolle's full-sized avatar
🙌
In sunny Malmö in Sweden 🌞

Olle Jonsson olleolleolle

🙌
In sunny Malmö in Sweden 🌞
View GitHub Profile
@pgraham
pgraham / gist:4127832
Created November 21, 2012 21:22
function to create a mock iterator over an array using PHPMock
/**
* Create a mock iterator over the given array.
*
* @param array $a
* @param string $class The class to use for the mock, should be/implement/extend Iterator
* @param boolean $complete Whether or not to build a complete iteration. This is
* used when an exception/break is expected in the middle of the iteration.
* @param integer $numElms The number of elements that should be iterated in the case of an
* incomplete iteration.
*/
@statique
statique / serialized_conversion.sql
Created November 2, 2012 20:42
PostgreSQL Convert Rails serialized YAML to JSON query
-- replace table_name with the name of your database table, e.g. users
-- replace data with the serialized field in the table, e.g. nicknames
-- output generates serialized data that decrypts to a Ruby array.
-- data with quotes, hyphens, or spaces will have issues with this query.
-- preview the YAML to JSON to confirm the conversion is working.
SELECT data, REPLACE(REPLACE(REPLACE(REPLACE(REGEXP_REPLACE(REPLACE(REPLACE(REPLACE(data,
' ', ''),
'...', ''),
'---', '["'),
@peterneubauer
peterneubauer / GoT.sql
Created July 11, 2012 13:12
The Game of Thrones Graph
start westeros=node(0)
set westeros.name = "Westeros"
create targaryen={house:"Targaryen"},
stark={house:"Stark"},
lannister={house:"Lannister"},
baratheon={house:"Baratheon"},
tully={house:"Tully"}
@qerub
qerub / x_forwarded_for.clj
Created June 12, 2012 15:06
[Clojure] Ring middleware for `X-Forwarded-For` [:remote-addr rewrite]
(ns ring.middleware.x-forwarded-for
(:use [clojure.string :only (split)]))
(defn wrap-x-forwarded-for [handler]
(fn [request]
(if-let [xff (get-in request [:headers "x-forwarded-for"])]
(handler (assoc request :remote-addr (last (split xff #"\s*,\s*"))))
(handler request))))
@ebi
ebi / buster.sublime-build
Created September 26, 2011 22:01
Small build system for sublime text 2 to execute Buster.JS
{
"cmd": ["buster-test", "--reporter", "xUnitConsole", "--color", "none"],
"working_dir": "${project_path}",
"selector": "source.js",
"file_regex": "@(.*?):([0-9]*)"
}
@klauswuestefeld
klauswuestefeld / gist:1186975
Created September 1, 2011 19:03
Martin Fowler to Usurp Pattern
We couldn’t find that file to show.
@jonasb
jonasb / install
Created July 16, 2011 09:11
My dotfiles install script
#!/usr/bin/env ruby
# update git submodules
`git submodule init && git submodule update`
# update symlinks
# inspired by http://errtheblog.com/posts/89-huba-huba
home = File.expand_path('~')
@tjsingleton
tjsingleton / heroku_env_logger.rb
Created May 12, 2011 15:23
Middleware that logs heroku requests into redis.
require "csv"
class HerokuEnvLogger
PREFIX = "HerokuRequest"
TIME_STEP = 1.minute * 1000 # ms
EXPIRE_IN = 6.hours
KEYS = %w[HTTP_X_REQUEST_START
HTTP_X_HEROKU_QUEUE_WAIT_TIME
HTTP_X_HEROKU_QUEUE_DEPTH
HTTP_X_HEROKU_DYNOS_IN_USE]
@hugs
hugs / selenium-examples.py
Created February 16, 2011 19:40
Example code for using the Selenium 2 Python bindings.
# To install the Python client library:
# pip install -U selenium
# Import the Selenium 2 namespace (aka "webdriver")
from selenium import webdriver
# iPhone
driver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')
# Android
@olleolleolle
olleolleolle / TextMate PHP deprecated style checker helper
Created September 1, 2010 10:45
Deprecations checker: A PHP Bundle script that I put on Ctrl-Shift-V (as a second PHP validation). Will jump to the line of the first reported error.
#!/usr/bin/env ruby
#
# Uses Stas Malyshev's migrate.php script to check code style
#
require ENV['TM_SUPPORT_PATH'] + '/lib/textmate'
version = %x{#{ENV['TM_PHP'] || 'php'} -v}.split[0..2].join(' ')
result = `#{ENV['TM_PHP'] || 'php'} /Users/olle/opensource/php/migrate/migrate.php '#{ENV['TM_FILEPATH']}'`
result.gsub!("in file #{ENV['TM_FILEPATH']}", '')
puts "OK!" if result.empty?
puts result