Skip to content

Instantly share code, notes, and snippets.

View derek-watson's full-sized avatar

Derek Watson derek-watson

View GitHub Profile
@derek-watson
derek-watson / tumblr.rb
Created March 12, 2011 18:47
Tumblr to Jekyll migration
#!/usr/bin/env ruby
# Script to import tumblr posts into local markdown posts ready to be consumed by Jekyll.
# Inspired by New Bamboo's post http://blog.new-bamboo.co.uk/2009/2/20/migrating-from-mephisto-to-jekyll
# Supports post types: regular, quote, link, photo, video and audio
# Saves local copies of images
require 'rubygems'
require 'open-uri'
require 'nokogiri'
@derek-watson
derek-watson / gist:3060402
Created July 6, 2012 14:13 — forked from mattheworiordan/gist:1037984
Backbone patch to defer update method requests when new create requests are not complete on a model
(function() {
function proxyAjaxEvent(event, options, dit) {
var eventCallback = options[event];
options[event] = function() {
// check if callback for event exists and if so pass on request
if (eventCallback) { eventCallback(arguments) }
dit.processQueue(); // move onto next save request in the queue
}
}
Backbone.Model.prototype._save = Backbone.Model.prototype.save;
@derek-watson
derek-watson / simple-throttle.js
Created August 14, 2012 14:44
Simple javascript function throttling
var isThrottled = false,
throttleDuration = 24; // ms
function thingToThrottle() {
if (isThrottled) { return; }
isThrottled = true;
setTimeout(function () { isThrottled = false; }, throttleDuration);
// do your work here
}
@derek-watson
derek-watson / strip_inline_styles.rb
Created September 14, 2012 20:16
Strip all inline style attributes from HTML
# - Reads from STDIN until EOF
# - Writes to STDOUT.
# - Requires Nokogiri (gem install nokogiri)
#
# Hi Tom!
require 'nokogiri'
doc = Nokogiri::HTML.parse(STDIN.read)
@derek-watson
derek-watson / initd_nginx
Last active August 29, 2015 14:01
passenger-install-nginx-module default nginx init script
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@derek-watson
derek-watson / logger.js
Last active August 29, 2015 14:05
Flexible bunyan logger module
/*
npm install --save bunyan
Basic usage:
var logger = require('./logger')
logger.info('hi')
log.warn({lang: 'fr'}, 'au revoir')
Create specific loggers for various parts of your app,

Keybase proof

I hereby claim:

  • I am derek-watson on github.
  • I am dcwca (https://keybase.io/dcwca) on keybase.
  • I have a public key ASAAJN3pQwa-0zO63HrqN7dKGC2rUPmm9EeqmuBnHARbcQo

To claim this, I am signing this object:

@derek-watson
derek-watson / Promise.allObj.js
Created August 23, 2017 18:58
A wrapper for Promise.all that accepts an object of promises and returns an object of response values
// extend Promise
Promise.allObj = promises => {
return Promise
.all(Object.values(promises))
.then(values => {
return values.reduce((obj, val, i) => {
obj[Object.keys(promises)[i]] = val
return obj
}, {})
})
from shapely.geometry import shape, mapping
from shapely.ops import unary_union
import fiona
import itertools
with fiona.open('Data/NonRegulatoryLayers_Subset.shp') as input:
# preserve the schema of the original shapefile, including the crs
meta = input.meta
with fiona.open('Out/dissolved.shp', 'w', **meta) as output:
# groupby clusters consecutive elements of an iterable which have the same key