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
| 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 |
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
| 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(' ') |
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
| case @face | |
| when 'N' | |
| @y += 1 | |
| when 'S' | |
| @y -= 1 | |
| when 'E' | |
| @x += 1 | |
| when 'W' | |
| @x -= 1 | |
| 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
| def face_to(operator, step) | |
| idx = DIRECTIONS.index(@face).method(operator).call(step) % 4 | |
| @face = DIRECTIONS[idx] | |
| 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
| 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 |
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
| 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 |
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
| 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 |
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
| client.search("to:justinbieber marry me", result_type: "recent").take(3).each do |tweet| | |
| puts tweet.text | |
| 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
| SCHEDULER.every '5s' do | |
| stats = Requests::Wordpress.new.stats | |
| send_event( | |
| 'page_views', | |
| current: stats['visitors_today'], | |
| last: stats['visitors_yesterday'] | |
| ) | |
| stars = Requests::Github.new('https://github.com/sparklemotion/nokogiri').stars_count | |
| send_event('stars_count', current: stars) |
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_relative 'request' | |
| require 'nokogiri' | |
| module Requests | |
| class Github < Request | |
| def initialize(url) | |
| super(url) | |
| chrome! | |
| end |
NewerOlder