Skip to content

Instantly share code, notes, and snippets.

View jimeh's full-sized avatar

Jim Myhrberg jimeh

View GitHub Profile
@jimeh
jimeh / latin1-to-utf8.rb
Created December 29, 2009 14:58
Convert a MySQL database from latin1 to utf8 charset.
#! /usr/bin/env ruby
#
# Convert a MySQL database from latin1 to utf8 charset.
#
# Based on the short but slightly limited shell script in this article:
# http://yoonkit.blogspot.com/2006/03/mysql-charset-from-latin1-to-utf8.html
#
# Use at your own risk! I take not responsiblity for anything or
# anyone that might be damaged, lost, or killed from using this
@jimeh
jimeh / Git SVN workflow.sh
Created January 22, 2010 11:43 — forked from anildigital/Git SVN workflow.sh
Git SVN Workflow
# >> First workflow
git svn clone <svn_repo>
git checkout -b featureZ
# hack hack hack
git commit -a
git svn rebase
git svn dcommit # you can add -e to enter new
@jimeh
jimeh / example_usage.rb
Created February 8, 2010 12:15
Quick Rails hack for a Model#increment_attributes method that works like update_attributes
Item.create(
:name => "Lolcat",
:fans => 0,
:views => 0
)
item = Item.find_by_name("Lolcat") #=> <Item name:"Lolcat" fans:0 views:0>
item.increment_attributes({ :fans => 4, :views => 3 })
@jimeh
jimeh / redirect_to.coffee
Created March 9, 2010 22:34
redirect_to.js: Handy url redirection that's as flexilbe as the href attribute of A tags.
###
Handy url redirection that's as flexible as the href attribute of A tags.
There might have been an easier way to do this, if so, let me know how stupid
I am :)
Example:
// Browser is on http://my.domain.com:3000/hello/world.html
window.redirect_to "world2.html"
@jimeh
jimeh / delayed_job.rb
Created March 26, 2010 22:42
delayed_job.rb: Capistrano tasks to "properly" start/stop/restart the delayed_job daemon.
#
# NOTICE: The stop/restart tasks won't work properly due to a bug in the daemons gem
# unless you use the ghazel-daemons gem by putting this in your environment.rb file:
#
# config.gem "ghazel-daemons", :lib => "daemons"
# gem "ghazel-daemons"
# require "daemons"
#
# This will force-load the 'ghazel-daemons' gem and make sure it's used instead of
# the 'daemons' gem. It works even with the 'daemons' gem installed, so you won't
#
# UPDATE!
# Instead of using this monkey-patch, it's better if you simply use the following
# in your environment.rb file:
#
# config.gem "ghazel-daemons", :lib => "daemons"
# gem "ghazel-daemons"
# require "daemons"
#
# This will force-load the 'ghazel-daemons' gem and make sure it's used instead of
@jimeh
jimeh / wait_while.rb
Created February 3, 2011 09:32
wait while &block returns true
# Public: Wait while block returns false by repeatedly calling the block until
# it returns true.
#
# Useful to wait for external systems to do something. Like launching daemons
# in integration tests. Which you're not actually doing right? >_<
#
# timeout - Integer specifying how many seconds to wait for.
# retry_interval - Interval in seconds between calling block while it's
# - returning false.
# block - A block which returns true or false. It should only return
@jimeh
jimeh / en.rb
Created April 17, 2011 10:13
Locale template for fuzzyclock gem.
# encoding: utf-8
class FuzzyClock
@@locales ||= {}
@@locales[:en] = {
:about => "it's about %t",
:hour => {
0 => "twelve",
1 => "one",
2 => "two",
@jimeh
jimeh / birds-of-paradise-theme.el
Created August 7, 2011 12:42
Slightly tweaked version of Paul M. Rodrigues' Emacs port of the Birds Of Paradise theme for Coda
;;; birds-of-paradise-theme.el --- custom theme for faces
;; Copyright (C) 2011 Paul M. Rodriguez <paulmrodriguez@gmail.com>
;; This file is not part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
@jimeh
jimeh / flymake-elisp.el
Created August 7, 2011 22:09
FlyMakeElisp
;;
;;; FlyMake Lisp
;;
;; from: http://www.emacswiki.org/emacs/FlymakeElisp
;;
(defun flymake-elisp-init ()
(unless (string-match "^ " (buffer-name))
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))