This file contains 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
Nines of Reliability: (Hours / Minutes / Seconds) | |
2 9's (99%) = up to 87.6h / 5256.0m / 315360.0 seconds of downtime per year. | |
3 9's (99.9%) = up to 8.76h / 525.6m / 31536.0 seconds of downtime per year. | |
4 9's (99.99%) = up to 0.876h / 52.559999999999995m / 3153.6 seconds of downtime per year. | |
5 9's (99.999%) = up to 0.0876h / 5.256m / 315.36 seconds of downtime per year. | |
6 9's (99.9999%) = up to 0.00876h / 0.5256000000000001m / 31.536 seconds of downtime per year. | |
7 9's (99.99999%) = up to 8.76E-4h / 0.05256m / 3.1536 seconds of downtime per year. |
This file contains 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 Person | |
attr_accessor :name | |
end |
This file contains 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
######################################### | |
# | |
# ==Keeps count of number of times key has been added.== | |
# | |
# Use: | |
# hsh = Hash.counter_hsh | |
# hsh << :foo | |
# hsh << :foo << :foo | |
# hsh << "foo" | |
# |
This file contains 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
moby = <<EOL | |
Call me Ishmael. Some years ago - never mind how long precisely - having little | |
or no money in my purse, and nothing particular to interest me on shore, I | |
thought I would sail about a little and see the watery part of the world. | |
[Moby Dick - 1st paragraph] | |
EOL | |
# | |
# "." - matches any character | |
# "\s" - matches digits (0-9) |
This file contains 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
# | |
# The interesting world of public, private, and protected. | |
# | |
# Publics - Work as expected | |
# | |
# Privates - Work as expected, except: | |
# You can send a symbol of the private method as an end around | |
# Classes can call the privates of their superclasses | |
# | |
# Protected - Instances of the same class can call each others protecteds, whut?! |
This file contains 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
############################ | |
# | |
# The world is your oyster. Unless you overload it. | |
# Then it can be anything your heart desires. | |
# | |
# Very few operators can't be overloaded: and, or, not, &&, || | |
# | |
class Person | |
attr_reader :my_bag |
This file contains 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
#! /usr/bin/env ruby | |
require 'benchmark' | |
# | |
# Benchmarking cmd-line tool | |
# | |
# | |
# $ bench_it.rb "x = 5; 100.times { x * 5 }" "(1..1000).to_a.inject(:+)" --times=500 | |
# | |
# EXAMPLE OUTPUT |
This file contains 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
module Algoruby | |
module Sort | |
# | |
# === Counting Sort === | |
# | |
# Best: O(n) [linear] | |
# Avg: O(n) [linear] | |
# Worst: O(n) [linear] | |
# | |
module Counting |
This file contains 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
module Greeting | |
extend self | |
def say_hello(greetable = self) | |
puts greetable.greeting | |
end | |
end | |
class Person | |
attr_accessor :greeting |
This file contains 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 Hash | |
def symbolize_keys | |
inject(Hash.new) do |result, (k, v)| | |
key = k.is_a?(String) ? k.to_sym : k | |
val = v.is_a?(Hash) ? v.symbolize_keys : v | |
result[key] = val | |
result | |
end | |
end |
OlderNewer