Skip to content

Instantly share code, notes, and snippets.

View tleach's full-sized avatar

Tom Leach tleach

View GitHub Profile
@tleach
tleach / gist:34d91ac3297bdfc9b05a
Created March 6, 2015 19:09
Example GameChanger Dockerfile
FROM docker.gamechanger.io/nodejs0.10
MAINTAINER Tom Leach
ADD . /gc/allegro
WORKDIR /gc/allegro
RUN mv Buildfile npm-shrinkwrap.json
RUN npm install
RUN mkdir -p /var/log/allegro
EXPOSE 80
@tleach
tleach / smoke-prerun.bat
Created December 31, 2014 20:10
Saucelabs pre-run script to prevent the browser from attempting to load Google Ads content (which has a habit of causing tests to hang)
echo 127.0.0.0 pagead2.googlesyndication.com >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.0 googleads.g.doubleclick.net >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.0 google.com >> %WINDIR%\System32\Drivers\Etc\Hosts
@tleach
tleach / prerun.bat
Last active August 29, 2015 14:12 — forked from DylanLacey/prerun.bat
echo 127.0.0.0 pagead2.googlesyndication.com >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.0 googleads.g.doubleclick.net >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.0 google.com >> %WINDIR%\System32\Drivers\Etc\Hosts
@tleach
tleach / gist:8072406
Last active January 1, 2016 01:19
How BSON encodes a datetime
if isinstance(value, datetime.datetime):
if value.utcoffset() is not None:
value = value - value.utcoffset()
millis = int(calendar.timegm(value.timetuple()) * 1000 +
value.microsecond / 1000)
return BSONDAT + name + struct.pack("<q", millis)
@tleach
tleach / gist:8072327
Created December 21, 2013 17:27
How BSON decodes a datetime
def _get_date(data, position, as_class, tz_aware, uuid_subtype):
millis = struct.unpack("<q", data[position:position + 8])[0]
diff = millis % 1000
seconds = (millis - diff) / 1000
position += 8
if tz_aware:
dt = EPOCH_AWARE + datetime.timedelta(seconds=seconds)
else:
dt = EPOCH_NAIVE + datetime.timedelta(seconds=seconds)
return dt.replace(microsecond=diff * 1000), position
#!/usr/bin/env python
"""
This module will bootstrap a machine using chef. The purpose of this
script is actually to work with AWS Auto Scaling Groups. The user data
for the Launch Configuration is set to download this script and then
run it. This is also stores the results in a private gist and sends
a message to logstash with the results.
"""
@tleach
tleach / ReflectingLayout.java
Created January 19, 2012 16:04
An Android Layout which can be used to apply a "reflection" effect to all child Views it contains.
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;
import android.util.AttributeSet;