Skip to content

Instantly share code, notes, and snippets.

View joho's full-sized avatar
At harbour

John Barton joho

At harbour
View GitHub Profile
@joho
joho / gist:7238
Created August 26, 2008 09:09 — forked from ryan-allen/gist:7230
,---------------------.
_.--._ ( I only bone *artists* )
,' `. `-,-------------------'
/ __) __` \ _.-'
( (`-`(-') )
/) \ _ / (
/' )-._.' . \ ___
( ,--., `.)___(___)
)( /-.,--'\ _ \X/`
'/ .'/ \ ( Uu")\
#!/usr/bin/env ruby
# Open a new tab in Terminal
# usage: tab [cmd]
# If cmd is specified, it will be run in new tab while old tab is reactivated.
# If no cmd, new tab is activated
require "rubygems"
# gem install rb-appscript
require "appscript"
include Appscript
@joho
joho / with.rb
Created November 18, 2008 03:47 — forked from ryan-allen/with.rb
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def scoped_variable(*objects)
yield(objects)
end
alias scoped_variable scoped_variables
end
@joho
joho / with.rb
Created November 18, 2008 05:47 — forked from xaviershay/with.rb
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def with(object)
yield(object)
end
end
@reports = []
@joho
joho / gist:39169
Created December 22, 2008 22:40 — forked from notahat/gist:39132
value = "Don T Alias"
first_name, last_name = value.reverse.split(' ', 2).reverse.collect(&:reverse)
first_name = first_name.to_s
last_name = last_name.to_s
# Refactored to take into account Xavier's pathological aversion to case statements:
last_space_index = value.rindex(' ') || value.size
first_name, last_name = value[0..last_space_index].strip, value[last_space_index..value.size].strip
---
@joho
joho / gist:47746
Created January 16, 2009 00:56 — forked from lightningdb/gist:47739
# what is the idiomatic ruby for this:
# if the var is an array, do_something with each element, otherwise just do something with the var
# if var.is_a?(Array)
# var.each do |element|
# do_something(element)
# end
# else
# do_something(var)
# end
@joho
joho / gist:50822
Created January 23, 2009 00:56 — forked from ryan-allen/gist:50818
# I don't tend to like writing this kind of code:
if Rails.env == 'development' or Rails.env == 'staging'
# ...
end
# So, an alternative Ruby way to do this is:
if %w(development staging).include?(Rails.env)
# ...
@joho
joho / gist:76717
Created March 10, 2009 03:55 — forked from lachie/gist:76701
- @items && @items.each do |item|
- name = item.gsub(/views\/.+\/(.+).haml/, '\1')
- unless name == "index" || name[/^hide-/]
%p do some stuff
@joho
joho / gist:117894
Created May 26, 2009 04:34 — forked from yob/gist:117889
irb(main):005:0> n = "James"
=> "James"
irb(main):006:0> n.strip!
=> nil
irb(main):007:0> n
=> "James"
# that's just plain weird
>> n = "john "
=> "john "
class SignupController < ActionController::Base
def step_two
@signup = Signup.find(params[:id])
@signup.advance_step do |signup|
signup.attributes = params[:signup]
signup.save!
end
end
end