This file contains 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 AuthenticationsController < ApplicationController | |
def create | |
omniauth = auth_hash | |
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) | |
if authentication | |
sign_in(authentication.user) | |
redirect_to root_url, notice: "Signed in!" | |
else | |
sign_in(User.create_from_omniauth(omniauth)) if current_user.blank? |
This file contains 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 assert_equal(actual, expected) | |
if expected == actual | |
puts 'pass' | |
else | |
puts "fail: expected #{expected}, got #{actual}" | |
end | |
end | |
def assert(statement) | |
if statement |
This file contains 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 scrape_away(args) | |
threads = [] | |
self.job_url_collection.each do |job_url| | |
threads << Thread.new do | |
job_doc = Nokogiri::HTML(open(job_url)) | |
title = job_doc.css(args[:title_selector]).inner_text.strip | |
company = job_doc.css(args[:company_selector]).inner_text.strip | |
source = self.source | |
job_url = job_url.strip | |
location = job_doc.css(args[:location_selector]).inner_text.strip |
This file contains 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.save_record(student) | |
record = Marshal.dump(student) | |
db_connection.execute('INSERT INTO students (student) VALUES (?);', [record]) | |
end | |
def self.update_record(student) | |
id = student.id | |
row = Marshal.dump(student) | |
db_connection.execute('UPDATE students SET student = ? WHERE id = ?', [row, id]) | |
end |
This file contains 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 Scraper | |
require 'nokogiri' | |
require 'open-uri' | |
attr_accessor :source, :index_url, :index_doc, :job_url_collection, :base_url_for_job, :job_database | |
def initialize(source, index_url, base_url_for_job, job_database) | |
@source = source | |
@index_url = index_url | |
@base_url_for_job = base_url_for_job |
This file contains 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
original = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.' | |
original.each_char.each_with_object("") do |character, final| | |
character.next!.next! unless character.match /\W/ | |
final << character | |
end |
This file contains 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
Tweet.where('created_at > ?','2012-11-15 02:18:28') | |
Tweet Load (0.5ms) SELECT "tweets".* FROM "tweets" WHERE (created_at > '2012-11-15 02:18:28') ORDER BY published_at DESC | |
=> [#<Tweet id: 30, content: "RARARA", published_at: "2012-11-15 02:18:28", handle: nil, created_at: "2012-11-15 02:18:28", updated_at: "2012-11-15 02:18:28", person_id: 1>] | |
#Aren't the created_at dates equal? So the query should return false... | |
'2012-11-15 02:18:28'.to_datetime.in_time_zone('UTC') |
This file contains 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
describe UserMailer do | |
it "there is a corresponding text email template for each HTML template" do | |
# Path to the mailer templates | |
mailers_path = "#{Rails.root}/app/views/user_mailer/" | |
result = Dir.foreach(mailers_path) do |template| | |
# Ignore partials | |
next if template.match /^_/ | |
# Check if it is an HTML template |
This file contains 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
" Example: | |
" response.body.should have_content("something") | |
" expect(response.body).to have_content("something") | |
" ================================================= | |
" Macro that converts rspec "should"s to "expect"s | |
" ================================================= | |
function! ConvertToExpect() | |
:normal! dd | |
:normal! P |
This file contains 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 'date' | |
DateRange = Struct.new(:start_date, :end_date) do | |
def start_date | |
self[:start_date] || Date.today - 30 | |
end | |
def end_date | |
self[:end_date] || Date.today | |
end |
OlderNewer