Skip to content

Instantly share code, notes, and snippets.

View mphalliday's full-sized avatar

Michael Halliday mphalliday

View GitHub Profile
2.hours.ago # => Fri, 02 Mar 2012 20:04:47 JST +09:00
1.day.from_now # => Fri, 03 Mar 2012 22:04:47 JST +09:00
Date.today.to_time_in_current_zone # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Date.current # => Fri, 02 Mar
Time.zone.parse("2012-03-02 16:05:37") # => Fri, 02 Mar 2012 16:05:37 JST +09:00
Time.zone.now # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Time.current # Same thing but shorter. (Thank you Lukas Sarnacki pointing this out.)
Time.zone.today # If you really can't have a Time or DateTime for some reason
Time.zone.now.utc.iso8601 # When supliyng an API (you can actually skip .zone here, but I find it better to always use it, than miss it when it's needed)
Time.strptime(time_string, '%Y-%m-%dT%H:%M:%S%z').in_time_zone(Time.zone) # If you can't use Time#parse
@mphalliday
mphalliday / gist:3458369
Created August 25, 2012 01:21
Installing ruby with rbenv on Mac OS X Leopard Server (10.5)
env CC=/usr/bin/gcc-4.2 rbenv install 1.9.3-p194
@mphalliday
mphalliday / deploy.rb
Created August 8, 2012 14:19
Capistrano deploy with rbenv
require 'bundler/capistrano'
load 'deploy/assets'
# rbenv stuff
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:/usr/local/git/bin:$PATH"
}
set :bundle_flags, "--deployment --quiet --binstubs --shebang ruby-local-exec"
set :user, 'rails'
@mphalliday
mphalliday / gist:1327432
Created October 31, 2011 12:51
Dependent jquery select lists
$(".country_selector").change( function(){
if ($(".region_selector").length > 0){
$.getJSON('/countries/'+$(this).val(), function(data) {
$(".region_selector").html($("<option></option>"));
$.each(data.country.regions, function(index, region){
$(".region_selector").
append($("<option></option>").
attr("value",region.id).
text(region.name));
});
@mphalliday
mphalliday / nokogiri
Created September 9, 2011 15:04 — forked from fabioyamate/nokogiri
nokogiri installation from libxml2 and libxslt macosx
# using rvm with ruby-1.8.7-p249
# latest version 2.7.7 2010-06-17
brew install libxml2
# installing libxslt from source code
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.7
make
sudo make install
david$ env ARCHFLAGS="-arch x86_64" gem install mysql2
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/david/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/.gitignore
SilverBullet:ror david$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql2
Password:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/david/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
@mphalliday
mphalliday / devise_migration.rb
Created June 4, 2011 13:06 — forked from Bertg/devise_migration.rb
Migrating to a new password encryption in devise, coming from authlogic
class MigrateUserToDevise < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :encrypted_password, :null => false, :limit => 128
# ...
end
end
def self.down
end
@mphalliday
mphalliday / gist:987155
Created May 23, 2011 17:52
MySQL 5.5 Mac OS X - Bash Profile addition
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
PS1='\[\033[01;37m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '
alias r='rails'