View bingy.rb
require 'open-uri' | |
class Bingy | |
LANDING_PAGE = 'http://www.bing.com/translator'.freeze | |
SPEAK_URL = LANDING_PAGE + '/api/language/Speak?locale=en-US&media=audio/mp3' | |
def initialize(text, gender = 'male') | |
@user_agent = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36' | |
@params = { text: text, gender: gender } | |
end |
View download_ny_photos_final.rb
# https://theoryofe.co/2016/10/17/reverse-engineering-by-using-chrome/ | |
require 'open-uri' | |
require 'uri' | |
require 'rmagick' | |
class PhotoDownloader | |
RESOURCE = 'http://access.nypl.org/image.php/'.freeze | |
def initialize(id, zoom) |
View complimentator.rb
require 'twitter' | |
# Bot implementation | |
class Complimentator | |
# Module that holds all commands | |
module Command | |
def compliment(tweet) | |
update(tweet, @compliments.sample) | |
end |
View parse_method.rb
def self.parse(string) | |
commands = string.split("\n") | |
rover = new(*commands.delete_at(0).split(' ')) | |
output = '' | |
commands.each_slice(2) do |deploy_coords, instructions| | |
rover.deploy(*deploy_coords.split(' ')) | |
output << rover.process(instructions) + "\n" | |
end | |
output | |
end |
View command_where_to_turn.rb
def process(commands) | |
commands.each_char do |character| | |
case character | |
when 'L' then turn_left | |
when 'R' then turn_right | |
when 'M' then move_forward | |
end | |
end | |
[@x, @y, @face].join(' ') |
View fun_with_case_and_face.rb
case @face | |
when 'N' | |
@y += 1 | |
when 'S' | |
@y -= 1 | |
when 'E' | |
@x += 1 | |
when 'W' | |
@x -= 1 | |
end |
View face_to_method.rb
def face_to(operator, step) | |
idx = DIRECTIONS.index(@face).method(operator).call(step) % 4 | |
@face = DIRECTIONS[idx] | |
end |
View rover_problem_beginning.rb
class RoverProblem | |
DIRECTIONS = %w(N E S W).freeze | |
attr_reader :face, :x, :y | |
def initialize(max_x, max_y) | |
@x = 0 | |
@y = 0 | |
@max_x = max_x.to_i | |
@max_y = max_y.to_i | |
end | |
end |
View analytical_research_how_hot.rb
def how_hot(topics, takes = 300) | |
results = topics.map do |topic| | |
tweets = @client.search(topic, result_type: 'recent').take(takes) | |
next [topic, 0, 0] if tweets.empty? | |
[topic, (tweets.length / (tweets.first.created_at - tweets.last.created_at) * 60), tweets.length] | |
end | |
results.sort_by {|result| result[1] } | |
end |
View twitter_client_get_recent_tweets.rb
def popularity(string) | |
tweets = @client.search(string, result_type: 'recent').take(1_000) | |
tweets.length / (tweets.first.created_at - tweets.last.created_at) * 60 | |
end |
NewerOlder