Skip to content

Instantly share code, notes, and snippets.

@baldowl
baldowl / gist:1299102
Created October 19, 2011 17:51
Nginx, try_files and the Accept-Language header
location / {
root /my/web/site;
# Note (1) the '/' before $lang and (2) the lack of '/' before $uri (which
# already starts with '/').
try_files /$lang$uri /$lang$uri.html /$lang$uri/ $uri $uri.html $uri/ =404;
}
@baldowl
baldowl / strip_exif_tags_filter.rb
Created July 24, 2011 17:00
Stripping Exif Tags
# Custom filter to run exiftool to strip images of every Exif tag. exiftool
# must be installed separately on the system; the filter assumes a Unix-like
# environment.
class StripExifTagsFilter < Nanoc3::Filter
identifier :strip_exif_tags
type :binary
def run filename, params = {}
tool_present = system 'which exiftool >/dev/null 2>&1'
if tool_present
@baldowl
baldowl / capybara-workaround.rb
Created May 17, 2011 18:03
New cucumber-rails: adios Webrat!
require 'capybara/rails'
require 'capybara/cucumber'
@baldowl
baldowl / classic_app.rb
Created May 6, 2011 06:49
Rough, simple Rack::Csrf extension for Sinatra
require 'sinatra'
require 'csrf'
use Rack::Session::Cookie
apply_csrf_protection
# Here follow the route handlers.
@baldowl
baldowl / gallery.rb
Created April 13, 2011 09:19
Rough gallery plugin for Jekyll
@baldowl
baldowl / multipart_upload.rb
Created February 18, 2011 07:21
Bad script to play with S3's multipart uploads and Fog
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
bucket_name = 'my_bucket'
object_name = 'big.zip'
# Part size must be between 5MB and 5GB.
# (http://docs.amazonwebservices.com/AmazonS3/latest/dev/qfacts.html)
# Let's say we've splitted the original file with split(1).
@baldowl
baldowl / .irbrc
Created January 26, 2011 10:21
.irbrc
require 'rubygems'
require 'irb/completion'
if ENV['RAILS_ENV']
# Redirecting ActiveRecord's messages to stdout. RoR2
require 'logger'
Object.const_set :RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)
elsif Object.const_defined? :RAILS_ENV
# Redirecting ActiveRecord's messages to stdout. RoR3
ActiveRecord::Base.logger = Logger.new STDOUT
@baldowl
baldowl / gist:771629
Created January 9, 2011 12:05
Using OS X's Directory Service instead of /etc/hosts
# Adding a host record.
sudo dscl . -create /Hosts/www.example.com ip_address 10.1.2.3
# Removing that same host record.
sudo dscl . -delete /Hosts/www.example.com
@baldowl
baldowl / rack-test-default-host.rb
Created December 6, 2010 07:52
Coercing Cucumber And Webrat To Cooperate
Scenario: Deleting a user
When I go to the users page
And follow "Delete" for the 2nd user
Then I should be on the users page
And should not see "user2"
@baldowl
baldowl / before_migrate.rb
Created November 8, 2010 08:48
Using Chef and Bundler Together
# Drop it in config/deploy/
#
# It's evaluated inside the deploy resource's context.
#
# It assumes Gemfile and Gemfile.lock are present and satisfy Bundler's
# requirements for the --deployment option.
current_release_directory = release_path
running_deploy_user = new_resource.user
bundler_depot = new_resource.shared_path + '/bundle'