Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gallery.rb
Created April 13, 2011 09:19
Rough gallery plugin for Jekyll
@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 / capybara-workaround.rb
Created May 17, 2011 18:03
New cucumber-rails: adios Webrat!
require 'capybara/rails'
require 'capybara/cucumber'
@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 / 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 / mds_ops.sh
Created December 27, 2011 08:15
Moving a Time Machine Disk
# disable indexing on the backup disk
sudo mdutil -i off /Volume/MyBackupDisk
# delete Spotlight's indexes
sudo rm -rf /Volume/MyBackupDisk/.Spotlight-V100
# re-enable indexing
sudo mdutil -i on /Volume/MyBackupDisk
@baldowl
baldowl / gist:1561249
Created January 4, 2012 18:07
Installing Xcode 4
open /Applications/Install\ Xcode.app/Contents/Resources/Xcode.mpkg
@baldowl
baldowl / import.rb
Created January 8, 2012 16:41 — forked from juniorz/import.rb
Import a blogger archive to jekyll (octopress version)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]