Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@augustl
augustl / application_helper.rb
Created October 29, 2008 14:24
The simplest thing that could possibly work.
def path_to_attachment_image(attachment)
image_path("attachments/#{attachment.filename}")
end
@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
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/
@joakimk
joakimk / livereload.rake
Created November 17, 2010 20:41
A simple rakefile to run livereload and generate css from the sass (scss) files specified in asset_packages.yml.
desc "Continuously watch for changes and rebuild files"
task :livereload do
pids = `ps ax|grep ruby|grep livereload|awk '{ print $1 }'`.split
other_pids = pids.reject { |pid| Process.pid == pid.to_i }
system "kill #{other_pids.join(' ')} &> /dev/null"
system "nohup livereload &> /dev/null &"
require 'rubygems'
require 'fssm'
@joakimk
joakimk / install.sh
Created November 21, 2010 14:01
Install script for Apache+REE+Passenger 3 on Ubuntu 10.04 64bit
# Install script for Apache+REE+Passenger 3 on Ubuntu 10.04 64bit
# BEFORE:
# - Make sure you are logged as a non-root user that can sudo.
# - Add your key here:
SSH_KEY="ssh-rsa ..."
# Add key to admin user
mkdir -p .ssh && echo "$SSH_KEY" >> .ssh/authorized_keys || exit 1
@jpmckinney
jpmckinney / tz_identifiers_to_rails_identifiers.rb
Created January 5, 2011 21:44
Maps tz database time zone identifiers to Rails time zone identifiers
# blog post: http://blog.slashpoundbang.com/post/2613268281/changing-from-tz-database-identifiers-to-rails-friendly
{
"Australia/Adelaide" => "Adelaide",
"Australia/Broken_Hill" => "Adelaide",
"America/Anchorage" => "Alaska",
"America/Juneau" => "Alaska",
"America/Nome" => "Alaska",
"America/Yakutat" => "Alaska",
"Pacific/Gambier" => "Alaska",
"Asia/Almaty" => "Almaty",
@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:
@henrik
henrik / disable_google_maps_scroll_zoom.user.js
Created July 3, 2011 22:33
Userscript to disable Google Maps scroll zoom in Google Chrome.
// ==UserScript==
// @name Disable Google Maps scroll zoom in Google Chrome
// @namespace http://henrik.nyh.se
// @description Disables Google Maps scroll zoom because it's unusable with Apple's Magic Mouse. Confirmed to work in Google Chrome.
// @include http://maps.google.com/*
// ==/UserScript==
// Adapted from the Safari extension by Mario Tausch/Tiago Rodrigues (https://public.me.com/ix/mariotausch/dev/index.html)
// via http://www.leancrew.com/all-this/2011/05/the-google-maps-scrollzoom-confusion/.
@wadey
wadey / iterm2.zsh
Last active March 10, 2024 00:32
Change iTerm2 tab color when using SSH
# Usage:
# source iterm2.zsh
# iTerm2 tab color commands
# https://iterm2.com/documentation-escape-codes.html
if [[ -n "$ITERM_SESSION_ID" ]]; then
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
@joakimk
joakimk / Example of output
Created August 21, 2011 18:14
Rake task for cleaner output when deploying with capistrano
$ rake deploy
> Executing deploy
> Executing deploy:update
> Executing deploy:update_code
> Executing deploy:finalize_update
> Executing bundle:install
> Executing link_config
> Executing link_files
> Executing build_assets
> Executing deploy:symlink
@joakimk
joakimk / migrate_with_annotation.rake
Created September 7, 2011 16:08
Script to automatically annotate models after db:migrate is run.
# Used with:
# gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
if Rails.env.development?
def after_task(task_name, &new_task)
old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
desc old_task.full_comment
task task_name do
old_task.invoke
new_task.call