Skip to content

Instantly share code, notes, and snippets.

View samgiles's full-sized avatar
🗺️

Sam Giles samgiles

🗺️
  • Citymapper
  • London
View GitHub Profile
@samgiles
samgiles / postgistogeojson.js
Created April 4, 2012 07:38
A function that converts a PostGIS query into a GeoJSON object.
/*
* A function that converts a PostGIS query into a GeoJSON object.
* Copyright (C) 2012 Samuel Giles <sam@sam-giles.co.uk>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@samgiles
samgiles / buster.js
Created December 11, 2012 14:19
Buster JS TestCase
var config = module.exports;
config["The Tests"] = {
env: "browser",
rootPath: ".",
tests:[
"*-test.js"
]
};
@samgiles
samgiles / count3s_pthread_mutex_slow
Created May 28, 2013 12:40
Bad usage of threads to solve a simple count threes problem.
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
void count3s_thread(int id);
int* array;
int length = 100000;
int t = 2;
@samgiles
samgiles / gist:5713917
Created June 5, 2013 13:39
Weather command line app
#!/bin/sh
curl "http://forecast.io/forecast?q=51.4957,-0.2149&satellites" -H "If-None-Match: \"-852332961\"" -H "Accept-Encoding: application/json" -H "Host: forecast.io" -H "Accept-Language: en-US,en;q=0.8" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" -H "Accept: */*" -H "Referer: http://forecast.io/" -H "X-Requested-With: XMLHttpRequest" -H "Cookie: _gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1; __utma=188038335.1999350163.1370437973.1370437973.1370437973.1; __utmb=188038335.2.10.1370437973; __utmc=188038335; __utmz=188038335.1370437973.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" | awk -F"[,:]" '{for(i=1;i<=NF;i++){if($i~/time\042/){ print system("date -j -r" $(i+1) " +%d/%m:%H:%M")} if ($i~/summary\042/){print $(i+1)}} }' | egrep -v '^0$' | less
@samgiles
samgiles / gist:9711796
Created March 22, 2014 18:17
RPython Error
def _malloc_signed(initial_value):
SIGNEDP = lltype.Array(lltype.Signed)
value = lltype.malloc(SIGNEDP, 1, flavor="raw")
value[0] = initial_value
return value
-----------------------------------------------------------------------------------------------
[translation:info] assert not signature.has_kwarg() # XXX should not happen?
[translation:ERROR] AssertionError
[translation:ERROR] Processing block:
@samgiles
samgiles / gist:9856834
Last active August 29, 2015 13:57
Steps to reproduce JIT memory errors
make wlvlang-jit PYPYPATH=~path/to/pypy
# This should pass
make test_all_jit
# Unfortunately the path to the script needs to be relative! (I should fix that)
bin/wlvlang-jit tests/benchmarks/thread-ring.wl 10 10
# This should cause a segfault or:
#
@samgiles
samgiles / gist:9994055
Last active August 29, 2015 13:58
auto-vectorisation example in GCC
void test_vec(double* restrict a, double* restrict b) {
int i;
double *x = __builtin_assume_aligned(a, 16);
double *y = __builtin_assume_aligned(b, 16);
for(i = 0; i < SIZE; i++) {
x[i] = x[i] + y[i];
}
}
@samgiles
samgiles / gist:11173191
Last active August 29, 2015 14:00
Get the current Python path as a string with correct path separator
import sys
import os
def pythonpath():
# Remove filter if you don't care about cases such as: ':/path::', where members of the path are
# empty. It would be slightly faster to complete this operation if the filter was not run but the size of the
# input is likely to be small
os.pathsep.join(filter(lambda path: len(path) > 0, sys.path))
@samgiles
samgiles / test.occ
Created April 23, 2014 12:27
Simple producer, consumer example [occam-pi]
#include "course.module"
PROC producer(VAL INT start, step, CHAN OF INT c!)
INT count:
SEQ
count := start
WHILE TRUE
SEQ
c ! count
count := count + step
@samgiles
samgiles / gist:11214993
Created April 23, 2014 13:22
Full example of 'channel poisoning' for producer channels using a control channel [occam-pi]
#INCLUDE "course.module"
PROTOCOL CONTROL
CASE
poison
:
PROTOCOL TAGGED.INT
CASE
normal; INT