Skip to content

Instantly share code, notes, and snippets.

View stefania11's full-sized avatar
💭
Halloween

Stefania Druga stefania11

💭
Halloween
View GitHub Profile
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
def say(text, voice = VOICES.sample)
cmd = "say -v #{voice} \"#{text}\""
system(cmd)
end
(Proc.new {|n| n*factor })
# 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) }
def self.open(thing)
cmd = "open #{thing}"
system(cmd)
end
@stefania11
stefania11 / batcharge.py
Last active August 29, 2015 14:17 — forked from remy/batcharge.py
#!/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]
=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')
@stefania11
stefania11 / gist:fef6a840d70cfcb65b33
Created February 25, 2015 22:43
Testing missing index for foreign keys
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
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