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
require 'sinatra' | |
# before we process a route, we'll set the response as | |
# plain text and set up an array of viable moves that | |
# a player (and the computer) can perform | |
before do | |
content_type :txt | |
@defeat = {rock: :scissors, paper: :rock, scissors: :paper} | |
@throws = @defeat.keys |
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
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
def wine_woot(url) | |
doc = Nokogiri::HTML(open(url)) | |
data = doc.xpath('//*[@id="summary"]/div') | |
puts doc.xpath('html/head/title').text + ' as site_name' | |
puts url + data.xpath('hgroup/a/@href').to_s + ' as site_href' | |
puts doc.xpath('//*[@id="todays-deal"]/a/img/@src').to_s + ' as img_src' |
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
require 'open-uri' | |
class Deal < ActiveRecord::Base | |
attr_accessible :img_src, :price, :site_href, :site_name, :wine_name | |
def self.wine_woot(url) | |
doc = Nokogiri::HTML(open(url)) | |
data = doc.xpath('//*[@id="summary"]/div') | |
site_name = doc.xpath('html/head/title').text | |
site_href = url + data.xpath('hgroup/a/@href').to_s |
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
=begin | |
Given a hash of business hours that looks like: | |
{ | |
"wed"=>{ | |
"endtime"=>"08:00pm", | |
"starttime"=>"10:00am" | |
}, | |
"sun"=>{ | |
"endtime"=>"06:00pm", | |
"starttime"=>"10:00am" |
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
=begin | |
There are better alternatives to storing images as a blob in the db like amazon s3, | |
but I don't have a choice in this case | |
rails g model image file_name:string content_type:string file_size:integer file_data:binary | |
populate in the console | |
rails c | |
require 'net/http' | |
=> true | |
host = 'host_url' |
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
# RSpec 2.0 syntax Cheet Sheet | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |
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 Bird | |
class << self | |
attr_accessor :instances | |
end | |
self.instances = [] | |
def initialize name | |
@name = name | |
@flying = false | |
self.class.instances << self |
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 Validator(): | |
GEO = ('geo', 'lat/lng', 'location') | |
ZIP = ('zip code', 'postal code', 'zip') | |
PHONE = ('phone', 'phone number', 'number', '#') | |
STATE = ('state abbreviation', 'state code', 'state') | |
ADDRESS = ('address') | |
URL = ('url', 'web address', 'facebook page') | |
STATES = { | |
'AK': 'Alaska', | |
'AL': 'Alabama', |
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 Address: | |
''' | |
Algo: | |
Work backward. Start from the zip code, which will be near the end, and in one of two known formats: XXXXX or XXXXX-XXXX. | |
If this doesn't appear, you can assume you're in the city, state portion, below. | |
The next thing, before the zip, is going to be the state, and it'll be either in a two-letter format, or as words. | |
You know what these will be, too -- there's more than 50 of them. | |
Also, you could soundex the words to help compensate for spelling errors. | |
before that is the city, and it's probably on the same line as the state. | |
You could use a zip-code database to check the city and state based on the zip, or at least use it as a BS detector. |
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
import imaplib, email | |
def fetch_csv_from_email(self): | |
file_name_list = [] | |
detatch_dir = '.' | |
if 'files' not in os.listdir(detatch_dir): | |
os.mkdir('files') | |
mail_session = imaplib.IMAP4_SSL('your_mail_box') | |
typ, account_details = mail_session.login('username', 'psswd') |
OlderNewer