Skip to content

Instantly share code, notes, and snippets.

View zakgrant's full-sized avatar
🎯
Focusing

Zak Grant zakgrant

🎯
Focusing
View GitHub Profile
@zakgrant
zakgrant / Car.java
Created January 13, 2012 11:13
Junit - Validating exception thrown WIP
public class Car {
}
@zakgrant
zakgrant / person.rb
Created March 10, 2012 15:44
Alias'd Instantiation
class Person
attr_accessor :first_name, :surname
@first_name = 'zak'
@surname = 'grant'
class << self
def new(options={})
Person.new options
end
@zakgrant
zakgrant / module_chaining.rb
Created April 3, 2012 20:08
Example of chaining module instance methods
#! /usr/bin/env ruby
module A
def say_hello name
puts "Hello #{name}"
end
end
class B
include A
@zakgrant
zakgrant / gist:2375494
Created April 13, 2012 09:55
ERB to HAML
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
`rm -Rf #{file}`
end
@zakgrant
zakgrant / gist:2424699
Created April 19, 2012 22:41
How to gwt ruby-debug and ruby-debug-ide up and running
wget http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
wget http://rubyforge.org/frs/download.php/74596/ruby_core_source-0.1.5.gem
wget http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
wget http://rubyforge.org/frs/download.php/63094/ruby-debug19-0.11.6.gem
wget http://rubygems.org/downloads/ruby-debug-ide-0.4.17.beta8.gem
wget http://rubyforge.org/frs/download.php/64707/ruby-debug-ide19-0.4.12.gem
export RVM_SRC=~/.rvm/src/ruby-1.9.3-p0
gem install linecache19-0.5.13.gem -- --with-ruby-include=$RVM_SRC
@zakgrant
zakgrant / erb2haml.rb
Created April 22, 2012 12:02
Script for converting ERB to HAML
#! /usr/bin/env ruby
require 'hpricot'
require 'ruby_parser'
require 'optparse'
class ToHaml
def initialize(path)
@path = path
end
@zakgrant
zakgrant / gist:2465828
Created April 22, 2012 18:09
Installing rbenv and ruby-build
brew update
brew install rbenv
brew install ruby-build
gem install rbenv-rehash
gem install bundler
git clone -- [email protected]:carsomyr/rbenv-bundler ~/.rbenv/plugins/bundler
@zakgrant
zakgrant / override_associations
Created May 16, 2012 13:28
Override Associations [Example of cars current and previous owner]
class Car < ActiveRecord::Base
belongs_to :owner
belongs_to :previous_owner, class_name: "Owner"
def owner(new_owner)
self.previous_owner = owner
super
end
end
@zakgrant
zakgrant / delete_all_albums.rb
Created October 15, 2012 22:06
Delete all Picasa Web Albums for an Account
#!/usr/bin/env ruby
# using the picasa gem => https://github.com/morgoth/picasa
require "picasa"
# delete all albums for an account.
begin
client = Picasa::Client.new(:user_id => $INSERT_GOOGLE_USER_NAME_HERE, :password => $INSERT_PASSWORD_HERE)
client.album.list.entries.each do |album|
client.album.delete(album.id)
@zakgrant
zakgrant / delete_all_picasa_albums.sh
Created November 2, 2012 09:18
Delete all albums in Picasa Web Account
#!/usr/bin/env ruby
require "picasa"
# delete all albums.
begin
client = Picasa::Client.new user_id: $USER_ID, password: $PASSWORD
albums = client.album.list.entries
albums.each do |album|