Skip to content

Instantly share code, notes, and snippets.

View andrewgleave's full-sized avatar

Andrew Gleave andrewgleave

View GitHub Profile
@andrewgleave
andrewgleave / main.go
Created March 2, 2018 14:55
pg_hashids trigger test
package main
import (
"fmt"
"log"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" //import pq
)
@andrewgleave
andrewgleave / GeoJSON2Couch.py
Last active August 29, 2015 14:15
Snippet to clean up and push KMZ->JSON data to a CouchDB instance. Routes are converted to LineStrings.
import ijson
from couchdbkit import (Document, Server, StringProperty, DictProperty)
class Route(Document):
id = StringProperty()
geometry = DictProperty()
properties = DictProperty()
@andrewgleave
andrewgleave / ContrastingColor.js
Last active August 29, 2015 14:03
Determine best contrast color (black/white) for a given color
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function contrastColor(color) {
@andrewgleave
andrewgleave / AnimatableComponent.js
Last active May 17, 2024 02:06
Keyframe animation support for React. Enables integration between React components and JS animation events.
/** @jsx React.DOM */
'use strict';
var React = require('react');
var AnimatableComponent = React.createClass({
propTypes: {
tag: React.PropTypes.component.isRequired,
@andrewgleave
andrewgleave / ContentEditableLabel.js
Last active September 15, 2016 09:32
An editable React.js label element based on the contenteditable attribute
/** @jsx React.DOM */
'use strict';
var React = require('react');
var ContentEditableLabel = React.createClass({
propTypes: {
tag: React.PropTypes.func,
import base64
import binascii
from Crypto.Cipher import AES
from django.template import Library
from django.utils.safestring import mark_safe
from django.conf import settings
register = Library()
@andrewgleave
andrewgleave / gist:5362194
Created April 11, 2013 10:04
Mirror site to S3 using s3cmd and wget
#optionally create two buckets and serve from root, redirecting www
s3cmd mb --bucket-location=EU s3://example.com
s3cmd mb --bucket-location=EU s3://www.example.com
s3cmd ws-create --ws-index=index.html s3://example.com
s3cmd ws-create s3://www.example.com
#configure www redirect if necessary
wget --mirror -p --html-extension --convert-links -e robots=off -P . http://example.com
s3cmd put --recursive --exclude=".DS_Store" --acl-public example.com/ s3://example.com
#create hosted zones and redirect DNS
@andrewgleave
andrewgleave / iOSMapKitFitAnnotations.m
Last active May 17, 2024 02:07
Zooms out a MKMapView to enclose all its annotations (inc. current location)
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapView.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}