Skip to content

Instantly share code, notes, and snippets.

View rodrigosoares's full-sized avatar

Rodrigo Soares rodrigosoares

View GitHub Profile
@rodrigosoares
rodrigosoares / max_tasks.rb
Created December 22, 2017 12:00
Maximum simultaneous tasks
# max_tasks returns the maximum number of tasks the system can take
# tasks: an array of unordered task weights
# limit: the maximum load of tasks
# the "context switching" difference between the tasks must be considered
# i.e.: current is 24, next is 23, so the context switching is 1
def max_tasks(tasks, limit)
sorted_tasks = tasks.sort
last = sorted_tasks.first
acc = limit
@rodrigosoares
rodrigosoares / capybara cheat sheet
Created December 14, 2017 03:03 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@rodrigosoares
rodrigosoares / h1_bgpd.conf
Last active November 11, 2021 17:01
Mininet/Mininext network in Python with BGP instance configurations in Quagga DSL.
hostname h1
password routeflow
enable password routeflow
!
router bgp 1000
bgp router-id 172.31.1.100
network 172.10.0.0/16
neighbor 172.36.1.2 remote-as 6000
neighbor 172.37.1.2 remote-as 7000
neighbor 172.31.1.1 remote-as 1
@rodrigosoares
rodrigosoares / math_methods.rb
Created April 12, 2017 18:40
Some useful Math class methods.
module Math
# Erlang-B loss formula returns the probability of call losses for a group of
# identical resources. It uses an auxiliary function 'bloq'. Parameters:
# ndv = number of trunks in full availability group
# gos = grade of service
def self.erlangb(ndv, gos)
ndv_aux = ndv
incr = ndv / 2.0
while incr > 0.0000001
if bloq(ndv, ndv_aux) > gos
@rodrigosoares
rodrigosoares / to_bool_methods.rb
Last active March 21, 2017 15:11
Useful boolean conversions for Ruby. If using Rails, put this in "config/initializers" folder.
class String
def to_bool
return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
return false if self == false || self.blank? || self =~ (/^(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
class Fixnum
def to_bool
@rodrigosoares
rodrigosoares / rails http status codes
Created February 10, 2017 12:22 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@rodrigosoares
rodrigosoares / d20_future_travel_time.rb
Last active November 13, 2016 17:34
This Ruby script calculates the travel time a ship takes to go through a distance. For now, it supports only light speed. It is based on the d20 Future RPG rules.
# Distance units (miles)
AU = 93_000_000.0
LIGHTYEAR = 63241 * AU
PARSEC = 3.26 * LIGHTYEAR
# Speed units (miles per second)
LIGHTSPEED = 186_000
# Time units (seconds)
MINUTE = 60