Skip to content

Instantly share code, notes, and snippets.

View stuartloxton's full-sized avatar

Stuart Loxton stuartloxton

View GitHub Profile
@stuartloxton
stuartloxton / recreate_bug.sh
Created April 2, 2012 14:42
recreate_bug.sh
curl -XPUT http://127.0.0.1:9200/test_bug/products/24 -d '{"product_id":"24","product_styles":[],"product_sizes":["Superking","Kingsize","Double","Single"]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/25 -d '{"product_id":"25","product_styles":[],"product_sizes":["Superking","Kingsize","Double","Single"]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/33 -d '{"product_id":"33","product_styles":[],"product_sizes":[]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/34 -d '{"product_id":"34","product_styles":[],"product_sizes":[]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/35 -d '{"product_id":"35","product_styles":[],"product_sizes":["Superking","Kingsize","Double","Single"]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/36 -d '{"product_id":"36","product_styles":[],"product_sizes":["Superking","Kingsize","Double","Single"]}'
curl -XPUT http://127.0.0.1:9200/test_bug/products/41 -d '{"product_id":"41","product_styles":[],"product_sizes":[]}'
curl -XPUT http://127.0.0.1:9200/test_
@stuartloxton
stuartloxton / html5.py
Created February 14, 2012 15:58
Quick script to convert videos into mov + ogg for HTML5 videos
#!/usr/bin/env python
import sys
import os.path
import re
import subprocess
if( len(sys.argv) < 2 ):
print("Usage: %s filename" % sys.argv[0])
sys.exit(1)
@stuartloxton
stuartloxton / table-split.py
Created January 27, 2012 09:53
Split PHPMyAdmin export into individual tables.
import sys
f = open(sys.argv[1])
files = f.read().split('-- --------------------------------------------------------')
files.pop(0)
for file in files:
# Find table name
name_index = file.index("for table `") + 11
name_end = file.index("`", name_index)
@stuartloxton
stuartloxton / gist:652483
Created October 28, 2010 22:35
Closure Memoization in PHP
<?php
function Memoize($function) {
$cache = array();
return function() use (&$cache, $function) {
$args = func_get_args();
$serialized = serialize($args);
if( isset($cache[$serialized]) )
return $cache[$serialized];
<?php
function luhnCheck($number) {
$digits = str_split($number);
for( $i = (count($digits) - 2); $i >= 0; $i -= 2 ) {
$digits[$i] *= 2;
}
$digits = str_split(implode($digits));
return (array_sum($digits) % 10) === 0;
}
-module (shttp).
-export ([bench_test_start/0, bench_test_stop/0, start/1, start/2]).
bench_test_start() ->
Pid = start(8000, fun handle_page/3),
register(http_server, Pid).
-module (beersong).
-author("Stuart Loxton").
-export ([sing/1]).
-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~n"
"Go to the store and buy some more,"
).
-define(TEMPLATE_N, "~s of beer on the wall, ~s of beer.~n"
"Take one down and pass it around, ~s"
" of beer on the wall.~n~n").
@stuartloxton
stuartloxton / kvo.php
Created January 28, 2009 23:36
An example implementation of Key Value Observing in PHP5.3+
<?php
class ExampleClass {
private $bindings = array();
public function __set($a, $b) {
$this->$a = $b;
if(is_array($this->bindings[$a])) {
foreach($this->bindings[$a] as $bind) {