This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def args_inspect(*names) | |
names.class | |
end | |
args_inspect("Bob", "Alice") | |
=> Array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# works in rails 3 | |
RAILS_ENV = ARGV[0] | |
if RAILS_ENV.nil? | |
puts "usage: blah.rb environment" | |
exit | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\]$ ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |