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
# lib/harvesters/yelp_harvester.rb | |
class YelpHarvester | |
def initialize restaurant | |
yelp_business_id = get_yelp_id(restaurant.yelp_url) | |
@yelp_data = Yelp.client.business(yelp_business_id) | |
end | |
def get_yelp_id url | |
url.slice!("http://www.yelp.com/biz/") | |
return 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
# spec/harvesters/yelp_harvester_spec.rb | |
require 'rails_helper' | |
require 'harvesters/harvester_index' | |
require 'harvesters/yelp_harvester' | |
describe HarvesterIndex do | |
it "gets rating" do | |
restaurant = Restaurant.create!({ | |
name: "Test Name", | |
yelp_url: "http://www.yelp.com/biz/ovo-cafe-san-francisco" |
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
# lib/harvesters/harvester_index.rb | |
class HarvesterIndex | |
def self.yelp | |
restaurants = Restaurant.where.not(yelp_url: nil) | |
restaurants.each do |restaurant| | |
yelp_harvester = YelpHarvester.new(restaurant) | |
yelp_harvester.populate_data | |
yelp_harvester.populate_tags | |
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
namespace :restaurant do | |
desc "TODO" | |
task get_yelp: :environment do | |
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
# lib/tasks/restaurant.rake | |
require 'harvesters/yelp_harvester' | |
require 'harvesters/harvester_index' | |
namespace :restaurant do | |
desc "Pull yelp information from yelp api" | |
task get_yelp: :environment do | |
HarvesterIndex.yelp | |
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
require 'benchmark' | |
array = %w( | |
18 5 11 67 55 16 63 15 35 97 9 7 40 42 14 98 50 94 16 86 34 2 39 12 43 42 49 77 48 85 94 57 59 65 96 2 85 59 5 35 28 17 68 55 43 43 73 68 97 79 84 58 34 83 16 7 67 79 24 76 53 43 8 55 56 91 4 44 61 86 73 14 42 60 61 33 58 37 96 73 4 31 8 17 27 60 33 77 6 98 71 12 73 75 97 4 7 83 30 54 | |
).map! {|x| x.to_i} | |
def collapse_sort(array) | |
sorted = [] | |
array.each do |item| | |
if sorted[item] | |
sorted[item].flatten! if sorted[item].class == 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
fs = require('fs') | |
fs.readFile('text.txt', 'utf8', function (e,data) { | |
processFile(data); | |
}); | |
function processFile(content) { | |
var wordArray = content.replace(/'/g,"").replace(/[, *\n().?!;:]/g, "@").replace(/@{2,}/g, "@").split("@") | |
wordArray.splice(wordArray.length-1) | |
var t_words = wordArray.length |
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
@-webkit-keyframes wiggle { | |
from {-webkit-transform: rotateZ(10deg);} | |
50% {-webkit-transform: rotateZ(-10deg);} | |
to {-webkit-transform: rotateZ(10deg);} | |
} | |
#rock{ | |
position: absolute; | |
top: 200px; | |
width: 200px; |
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 sleep(milliseconds){ | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++){ | |
if ((new Date().getTime() - start) > milliseconds){ | |
break; | |
}; | |
}; | |
}; | |
while (true){ |
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 "spec_helper" | |
require "noko_converter" | |
require "business" | |
require "Nokogiri" | |
require "RestClient" | |
describe Business do | |
let(:source) {"http://www.yelp.com/biz/fat-angel-san-francisco"} |