Skip to content

Instantly share code, notes, and snippets.

View samgiles's full-sized avatar
🗺️

Sam Giles samgiles

🗺️
  • Citymapper
  • London
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@samgiles
samgiles / index.html
Created September 30, 2016 17:30
Simple knock/tap detector
<html>
<body>
<script>
const state = {
x: 0,
y: 0,
z: 0,
knocked: 0,
};
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
real 135m58.539s
user 216m42.077s
sys 2m12.026s
@samgiles
samgiles / gist:826adc30d5209d56a692
Last active February 26, 2016 15:22
This makes no sense...
type mismatch: the type `[closure@src/service_router.rs:28:37: 32:6 c2:T]` implements the trait
`for<'r, 'r, 'r> core::ops::Fn<(&'r mut iron::request::Request<'r, 'r>,)>`,
but the trait
`for<'r, 'r, 'r> core::ops::Fn<(&'r mut iron::request::Request<'r, 'r>,)>`
is required
(expected struct
`iron::request::Request`,
found a different struct
`iron::request::Request`
)
@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 / 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;
E/Gecko ( 9982): ShmemAndroid::Create():open: Bad address (14)
I/Gecko ( 9982): [GFX1]: [Tiling:Client] Failed to allocate a TextureClient
I/Gecko ( 9982): [GFX1]: ValidateTile failed
.
├── JSONStream
│   ├── LICENSE.APACHE2
│   ├── LICENSE.MIT
│   ├── examples
│   │   └── all_docs.js
│   ├── index.js
│   ├── package.json
│   ├── readme.markdown
│   └── test
@samgiles
samgiles / tcp-proxy.sh
Created January 29, 2015 16:28
Simple TCP proxy src-port -> dest-host:port.
#!/bin/sh -e
if [ $# != 3 ]
then
echo "usage: $0 <src-port> <dst-host> <dst-port>"
exit 1
fi
TMP=`mktemp -d`
BACK=$TMP/pipe.back