Skip to content

Instantly share code, notes, and snippets.

SELECT
COUNT(Track.id) AS playCount,
CanonicalArtist.title AS ArtistName,
CanonicalPage.title AS AlbumName,
FROM
-- Tables to query playlist info
tracks AS Track
INNER JOIN broadcasts AS Broadcast ON (Track.broadcast_id = Broadcast.id)
INNER JOIN programs AS Program ON (Program.id = Track.program_id)
-- Tables to query canonical presentation
@BenWard
BenWard / pinboard-full.js
Created January 29, 2011 07:47
A smarter bookmarklet for Pinboard.in; wraps selected text in <blockquote> tags, keeps variables out of the global scope, supports filling tags from rel="tag" markup in the page, and titles from hAtom entry titles.
(function() {
// Change `silent` to true to invoke the promptless, self-closing
// version of the bookmarklet.
var silent = false;
var url = location.href;
var title = document.title;
// Look for a single hAtom entry on the page, and iff one is found, extract
// the entry-title in place of the document title:
@BenWard
BenWard / s3-buffer.sh
Last active October 11, 2019 07:23
Move files from an s3 bucket to a second buffer bucket, if the buffer bucket contains fewer than $file_count objects.
#!/bin/sh
#file_count=100
#source_bucket="example-log-stream"
#buffer_bucket="example-log-stream-buffer"
# 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.)
// Stupid simple bookmarklet function to duplicate the current page in a new window. Boom.
javascript:(function(){window.open(window.location.href)})();
@BenWard
BenWard / extended-tweet-embed.html
Created May 9, 2013 23:52
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.)
<blockquote class="twitter-tweet" cite="https://twitter.com/mroth/status/332642087713521664">
<p>Best practices for nicely embedding a static tweet in a GitHub README.md? (Twitter's embed code obviously won't work due to SCRIPT tags.)</p>
<p>&mdash; Matthew Rothenberg (<a href="https://twitter.com/mroth/">@mroth</a>)
<a href="https://twitter.com/mroth/status/332642087713521664">May 9, 2013</a> &middot;
<a href="https://twitter.com/intent/tweet?in_reply_to=332642087713521664">Reply</a> &middot;
<a href="https://twitter.com/intent/retweet?tweet_id=332642087713521664">Retweet</a> &middot;
<a href="https://twitter.com/intent/favorite?tweet_id=332642087713521664">Favourite</a>
</p>
</blockquote>
@BenWard
BenWard / tumblr_export.js
Created March 25, 2013 06:49
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 …
!function () {
// You'll need an application registered at http://www.tumblr.com/oauth/apps
// 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 'benw.tumblr.com' or
// 'blog.benward.me'.
const domain = "example.tumblr.com";
// Since we're pasting this on gist rather than giving you a full repo to
@BenWard
BenWard / oembed.rb
Created March 15, 2013 23:36
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.
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
BenWard / gist:2580401
Created May 2, 2012 20:52
Sublime Text 2 Settings
{
"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
BenWard / gist:1858216
Created February 18, 2012 08:24
Oneliner, bookmarklet script to bypass Facebook news apps (e.g. The Independent.)
window.location.search.split('&').filter(function(item,i){i=item.split('='); return(i[0]&&i[0]=='redirect_uri')}).forEach(function(u){window.location=unescape(u.split('=')[1])})
@BenWard
BenWard / gist:1729232
Created February 3, 2012 09:25
Script to show a growl notification for pending Homebrew updates
brew outdated | growlnotify -n "Homebrew Update Check" -t "Homebrew Updates Available" -a Xcode -s -d "brew-updates"