Skip to content

Instantly share code, notes, and snippets.

Aidan Rudkovskyi rudkovskyi

Block or report user

Report or block rudkovskyi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
View client_create_tweet.rb
client.search("to:justinbieber marry me", result_type: "recent").take(3).each do |tweet|
puts tweet.text
end
View statistics_final.rb
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)
View github.rb
require_relative 'request'
require 'nokogiri'
module Requests
class Github < Request
def initialize(url)
super(url)
chrome!
end
You can’t perform that action at this time.