Skip to content

Instantly share code, notes, and snippets.

View jamiew's full-sized avatar

Jamie Dubs jamiew

View GitHub Profile
@jamiew
jamiew / vhx-megaplaya.html
Created September 14, 2011 03:18
Example of embedding VHX megaplaya and playing Vimeo videos
<!DOCTYPE html>
<html>
<head>
<title>Videos</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script type="text/javascript" src="http://vhx.tv/javascripts/jquery.swfobject-1.1.1.js"></script>
<style type="text/css" media="screen">
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
@jamiew
jamiew / connection_fix.rb
Created August 23, 2011 16:52 — forked from defunkt/connection_fix.rb
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@jamiew
jamiew / build-failed
Created July 31, 2011 21:48
A CI Joe build-failed hook that includes the test results in the email notification.
# .git/hooks/build-failed
echo -e "http://cijoe-server:4567\n\n" | cat - .git/builds/last | mail -s 'CI: Build failed!' [email protected]
@jamiew
jamiew / google_twunter_lol
Created July 28, 2011 20:34
All the dirty words from Google's "what do you love" project: http://www.wdyl.com/
easterEgg.BadWorder.list={
"4r5e":1,
"5h1t":1,
"5hit":1,
a55:1,
anal:1,
anus:1,
ar5e:1,
arrse:1,
arse:1,
@jamiew
jamiew / tumblr-photo-ripper.rb
Created July 13, 2011 17:46
Download all the images from a Tumblr blog
# Usage:
# [sudo] gem install mechanize
# ruby tumblr-photo-ripper.rb
require 'rubygems'
require 'mechanize'
# Your Tumblr subdomain, e.g. "jamiew" for "jamiew.tumblr.com"
site = "doctorwho"
@jamiew
jamiew / devise_http_rememberable.rb
Created May 19, 2011 22:39
Monkeypatch Devise to support saving sessions via HTTP auth (e.g. via bookmarklets or browser addons)
# config/initializers/devise_http_rememberable.rb
# Monkeypatch Devise so HTTP authentication sets remember_user_token cookie
# ABR: Always Be Remembering
module Devise
module Strategies
class Authenticatable < Base
def remember_me?
# Devise's implementation of this is:
# valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
@jamiew
jamiew / eventmachine url expansion tests.rb
Created May 13, 2011 05:53
Noodling with different ways of expanding short URLs in bulk
require 'rubygems'
require 'benchmark'
require 'pp'
require 'mechanize'
require 'eventmachine'
require 'em-http-request'
def syncronous(urls)
agent = Mechanize.new
expanded_urls = urls.map{|url|
@jamiew
jamiew / ghettovision.sh
Created May 8, 2011 07:01
Poor recreation of Pummelvision-style video animation
#!/bin/sh
# video, adjust for input filenames & output format+filename
ffmpeg -r 6 -b 1800 -i "image%04d.jpg" -f webm test1800.webm
# animated GIF
convert -verbose -delay 20 -loop 0 -density 200 *.jpg output.gif
@jamiew
jamiew / capistrano_memcached_tasks.rb
Created May 6, 2011 16:11
Some handy Capistrano tasks for handling memcached. Assumes memcached runs locally on your app servers, YMMV
# This goes in config/deploy.rb
namespace :memcached do
desc "Flush memcached"
task :flush, :roles => [:app] do
run("cd #{current_release} && RAILS_ENV=#{rails_env} /usr/bin/rake memcached:flush")
end
desc "Flush memcached if there are any pending migrations (hook this before db:migrate)"
task :flush_if_pending_migrations, :roles => [:app] do
output = capture("cd #{current_release} && RAILS_ENV=#{rails_env} /usr/bin/rake db:pending_migration_count"
@jamiew
jamiew / devise_http_rememberable.rb
Created May 2, 2011 00:27
Monkeypatch Devise so HTTP authentication sets remember_user_token cookie
# config/initializers/devise_http_rememberable.rb
# ABR: Always Be Remembering
module Devise
module Strategies
class Authenticatable < Base
def remember_me?
# Devise's implementation of this is:
# valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
# which only works for param authentication, not http authentication
true