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 date | |
puts 'For which day would you like to see the APOD?' | |
date = prompt('Enter a date in the format YYYY-MM-DD') | |
validate(date) | |
Cosmos.new(date: date) | |
rescue | |
date_error | |
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
def say(text, voice = VOICES.sample) | |
cmd = "say -v #{voice} \"#{text}\"" | |
system(cmd) | |
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
(Proc.new {|n| n*factor }) |
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
# Convert Json object into an instance of a class | |
class APOD | |
def initialize(data) | |
data.each do |k, v| | |
instance_variable_set("@#{k}", v) | |
reader = proc { instance_variable_get("@#{k}") } | |
self.class.send('define_method', k, reader) | |
getter = proc { |other| instance_variable_set("@#{k}", other) } |
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 self.open(thing) | |
cmd = "open #{thing}" | |
system(cmd) | |
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
#!/usr/bin/env python | |
# saved to ~/bin/batcharge.py and from | |
# http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#my-right-prompt-battery-capacity | |
#!/usr/bin/env python | |
# coding=UTF-8 | |
import math, subprocess | |
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE) | |
output = p.communicate()[0] |
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
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
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
c = ActiveRecord::Base.connection | |
c.tables.collect do |t| | |
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))} | |
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq | |
unindexed = columns - indexed_columns | |
unless unindexed.empty? | |
puts "#{t}: #{unindexed.join(", ")}" | |
end | |
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 Raindrops | |
@hash = { '3'=>'Pling', '5'=>'Plang', '7'=>'Plong' } | |
@p = Prime:: instance | |
def self.convert (n) | |
if n == 1 then '1' | |
else | |
for is_prime(n) :: true do |i| | |
@hash[i].join | |
end |