Skip to content

Instantly share code, notes, and snippets.

@jzellman
jzellman / gist:1711922
Created January 31, 2012 18:06
Var Args 2
def args_inspect(*names)
names.class
end
args_inspect("Bob", "Alice")
=> Array
@jzellman
jzellman / gist:1711917
Created January 31, 2012 18:05
Var Args 1
# For a variable amount of names
def say(salutation, *names)
names.map do |name|
"#{salutation} #{name}!"
end.join(" ")
end
say("Hello", "Bob", "Alice")
=> "Hello Bob! Hello Alice!"
@jzellman
jzellman / gist:1572222
Created January 6, 2012 20:17
How to do this Idiom in Rails 3
#!/usr/bin/env ruby
# works in rails 3
RAILS_ENV = ARGV[0]
if RAILS_ENV.nil?
puts "usage: blah.rb environment"
exit
end
class Company
# Returns the latest past scan or nil if one does not exist
#
def last_scan(start_date = nil, end_date=Time.now)
conditions = if start_date
['status in ? AND scheduled_at IS NOT NULL and scheduled_at > ? AND scheduled_at < ?',
Status.finished_states, start_date, end_date]
else
['status in ? AND scheduled_at IS NOT NULL AND scheduled_at < ?',
Status.finished_states, end_date]
#!/usr/bin/env ruby
# save as vuln2csv and run
# ./vuln2csv < infile.txt > outfile.csv
require 'rubygems'
require 'fastercsv'
class CVERow
def initialize(line)
# not assuming " is text delimiter
function current_branch(){
BR=$(git symbolic-ref HEAD 2>/dev/null | awk -F/ '{ print "<" $3 ">" } ') || { echo "$@" ; exit ; }
echo " $BR"
}
export PS1='\[\e[32;1m\]\u@\h \[\e[34;1m\]\w\[\e[36;1m\]$(current_branch)\[\e[0;30m\]\[\e[0m\]$ '
#installing sqlite3-ruby on FreeBSD 8 with custom ruby install
gem install sqlite3-ruby -- --with-sqlite3-include=/usr/local/include/ --with-sqlite3-lib=/usr/local/lib
class IncomingTicketHandler
require 'rubygems'
require 'tmail'
def self.receive(email)
ticket = Ticket.new
ticket.title = email.subject
ticket.body = email.body
ticket.assignedTo = email.to
ticket.creator = email.from
<h1>Listing people</h1>
<table>
<tr>
<th><%= sorted_people_url("First name", "first_name") -%></th>
<th><%= sorted_people_url("Last name", "last_name") -%></th>
<th><%= sorted_people_url("Personal Email", "email") -%></th>
<th><%= sorted_people_url("Age", "age") -%></th>
</tr>
class ApplicationController < ActionController::Base
def rescue_action(exception)
# Why do I need the :: in front of ActionController?
if exception.is_a? ::ActionController::UnknownAction
redirect_to :controller => "account", :action => "login"
else
...
end
end
end