Skip to content

Instantly share code, notes, and snippets.

BenWard /
Last active Oct 11, 2019
Move files from an s3 bucket to a second buffer bucket, if the buffer bucket contains fewer than $file_count objects.
# Move $file_count files from an s3 bucket to a second buffer bucket, if the buffer
# bucket contains fewer than $file_count objects.
# We use this to prevent a logstash s3 input filter blowing up our ELK server when backlog of
# files builds up in s3 (e.g traffic spikes, or after period of system downtime.)
BenWard / subl.bash
Last active Aug 29, 2015
A simple wrapper for `subl`, which handles opening explicit arguments, `sublime-project` definitions if present, or falls back to open the current directory.
View subl.bash
function subl {
if [ -n "$1" ]; then
command subl $1
elif [ -f *.sublime-project ]; then
command subl *.sublime-project
command subl .
BenWard / gist:7f47ee00da22dd52ff09
Created Oct 15, 2014
Dirty little hack script to make the Creek.FM time-stamp field update live, to make it easier to post tracks at the right time.
View gist:7f47ee00da22dd52ff09
(function realTimeTrackTime () {
function padNumber (i) {
i = "" + i;
if (i.length == 1) return "0" + i;
return i;
function updatePlaytime () {
var d = new Date()
window.requestAnimationFrame(function () {
BenWard / gist:1f38be8e28df87fced81
Created Oct 15, 2014
Quick script to generate end-times from track lengths for tracks played on Creek.FM
View gist:1f38be8e28df87fced81
(function endTimesFromTrackLength () {
function padNumber (i) {
i = "" + i;
if (i.length == 1) return "0" + i;
return i;
function timestampToSecs (dateString) {
return Date.parse(dateString.replace(" ", "T") + "-07:00") / 1000;
BenWard / gist:4189f5cf1452adac41fc
Last active Aug 29, 2015
Quick and dirty function to extract tracklistings from a BFF.FM show playlist and convert it into a Mixcloud compatible blob of text. Recognises gaps in songs and creates chapter breaks automatically.
View gist:4189f5cf1452adac41fc
(function mixcloudify (startHour) {
var TALK_BREAK_MINIMUM = 4, // minimum length to insert a talk break
function showTime () {
var start = startHour.split(":").map(function (item) {
return padNumber(item);
return Date.parse([
BenWard / extended-tweet-embed.html
Created May 9, 2013
Expanded version of the Twitter embed code that includes static Tweet actions using Web Intents. (Won't actually initialize as a JavaScript embed due to a parsing assumption on our part, but I'll fix that when I get a chance.)
View extended-tweet-embed.html
<blockquote class="twitter-tweet" cite="">
<p>Best practices for nicely embedding a static tweet in a GitHub (Twitter's embed code obviously won't work due to SCRIPT tags.)</p>
<p>&mdash; Matthew Rothenberg (<a href="">@mroth</a>)
<a href="">May 9, 2013</a> &middot;
<a href="">Reply</a> &middot;
<a href="">Retweet</a> &middot;
<a href="">Favourite</a>
BenWard / tumblr_export.js
Created Mar 25, 2013
Quick and dirty script to pull down all of your posts from Tumblr as raw, unformatted JSON responses. Useful for crude back-ups, or if you're going to transform them later and only want to hit the API once. There's no rate limiting or back-off or anything, and the blog I wrote it for only had 580 posts, so I'm not sure what issues you might run …
View tumblr_export.js
!function () {
// You'll need an application registered at
// Just put the OAuth Consumer Key here (Tumblr's version of application-auth
// is really simple and unsigned.)
const key = "";
// Next, put your Tumblr domain name here. That might be '' or
// ''.
const domain = "";
// Since we're pasting this on gist rather than giving you a full repo to
BenWard / oembed.rb
Created Mar 15, 2013
Dirty little ruby script to get oEmbed from URLs, for use with automator actions in Mac OSX. Enables embedding Tweets and Flickr photos (and probably others) for selected URLs. Rather fragile.
View oembed.rb
require 'rubygems'
require "open-uri"
require 'nokogiri'
require 'json'
ARGV.each do |f|
doc = Nokogiri::HTML(open(f))
doc.css('link[type="application/json+oembed"]').each do |link|
oembed_uri = link['href']
oembed = open(oembed_uri).read
BenWard / gist:2580401
Created May 2, 2012
Sublime Text 2 Settings
View gist:2580401
"theme": "Soda Light.sublime-theme",
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"font_size": 13,
"tab_size": 2,
"draw_white_space": "all",
"gutter": true,
"margin": 2,
"rulers": [78, 80],
"draw_minimap_border": false,
BenWard / gist:1858216
Created Feb 18, 2012
Oneliner, bookmarklet script to bypass Facebook news apps (e.g. The Independent.)
View gist:1858216'&').filter(function(item,i){i=item.split('='); return(i[0]&&i[0]=='redirect_uri')}).forEach(function(u){window.location=unescape(u.split('=')[1])})