Skip to content

Instantly share code, notes, and snippets.

View jeremyf's full-sized avatar

Jeremy Friesen jeremyf

View GitHub Profile
@jeremyf
jeremyf / hack.sh
Created April 1, 2012 00:41 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jeremyf
jeremyf / conductor-verifier.rb
Created April 17, 2012 13:31
Testing Conductor Ruby 1.8.7 upgrade to 1.9.3
require 'rubygems'
require 'rest_client'
require 'fileutils'
require 'logger'
require 'childprocess'
require 'yaml'
module Conductor
module Verifier
class Runner
@jeremyf
jeremyf / gist:2638310
Created May 8, 2012 18:34
Converting latin1 to UTF8 the hard way
ActiveRecord::Base.connection.select_all(%(show table status where collation like '%latin1%')).each do |options|
table_name = options['Name']
puts "Started Processing\t#{table_name}"
FileUtils.mkdir_p(Rails.root.join('tmp/db-conversion'))
filename_pre_transform = Rails.root.join("tmp/db-conversion/conductor.#{table_name}.pre.sql").to_s
filename_post_transform = Rails.root.join("tmp/db-conversion/conductor.#{table_name}.post.sql").to_s
commands = []
commands << %(mysqldump -uroot --opt --skip-set-charset --default-character-set=latin1 --skip-extended-insert conductor_dev --tables #{table_name} > #{filename_pre_transform})
commands << %(perl -i -pe 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/' #{filename_pre_transform})
commands << %(iconv -f LATIN1 -t UTF8 #{filename_pre_transform} > #{filename_post_transform})
@jeremyf
jeremyf / fast-one.rb
Created May 10, 2012 17:51
A command line tool to help with testing pull requests.
#!/usr/bin/env ruby
# Before you use this:
# git clone git://github.com/some-other-user/their-repo
# This assumes that origin is the repo that you are merging into!
require 'rubygems'
gem 'rest-client'
gem 'crack'
require 'rest-client'
@jeremyf
jeremyf / class-inline.rb
Created July 6, 2012 13:42
Demonstrate in-file testing option for Ruby
# This file demonstrates a quick and dirty means of testing a file.
# Above the ```if __FILE__ == $0``` line is where the "production" code
# is written. Inside the IF block, the "test" code is written.
class Inline
def to_s
'Hello'
end
end
# From Terminal, you can type `ruby class-inline.rb`
@jeremyf
jeremyf / ruby-to_s-method.rb
Created July 9, 2012 14:04
Overwrite Ruby's #to_s method for cleaning up views.
# By making use of Ruby's natural coercion methods (i.e. #to_s, #to_i)
# we can save some headaches with potential nil objects.
# By overwriting the #to_s method on a class, we can get a lot of benefits
# in our presentation logic. We don't have to remember are we using #title
# or #pretty_title.
# I would caution that we not put markup in the #to_s method, as that violates
# the intent of #to_s. In fact, markup should probably not be in the model,
# as the markup makes an assumption about how the content is presented.
@jeremyf
jeremyf / latin1-utf8-conversion.rb
Created July 23, 2012 17:25
Latin1 to UTF8 character encoding correction for mysql
# Copyright (C) 2012 Jeremy Friesen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@jeremyf
jeremyf / .bashrc.example
Created July 30, 2012 14:48
my .bashrc file configuration for displaying git and rvm info
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "[⚡]"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty) /"
}
function __my_rvm_ruby_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
@jeremyf
jeremyf / pre-commit
Created August 7, 2012 17:55
Remove trailing whitespace
#!/bin/sh
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
@jeremyf
jeremyf / project
Created September 22, 2012 22:27
bash-completion
# project completion for Sublime projects by Jeremy Friesen <jeremy.n.friesen@gmail.com>
function _project {
local cur
COMPREPLY=()
_get_comp_words_by_ref cur
COMPREPLY=( $(find $HOME/Repositories -type d -maxdepth 1 -mindepth 1 -exec basename {} \; | egrep "^$cur"))
}
complete -F _project -o default project