- A is for ARGF
- B is for blocks
- C is for CSV
- D is for DBM (Database Management library) or Dir or DATA
- E is for Enumerable and Enumerators
- F is for Fibers
- G is for GServer
- H is for Hash
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
require 'benchmark' | |
a = Array.new(10_000) { rand } | |
Benchmark.bm(20) do |bench| | |
bench.report('sort <=>') { 10.times { a.sort { |x,y| y <=> x } } } | |
bench.report('sort.reverse') { 10.times { a.sort.reverse } } | |
bench.report('sort_by.reverse') { 10.times { a.sort_by(&:to_f).reverse } } | |
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
# PROMPT | |
# ========== | |
PS1="\[\e[33m\]\h\[\e[0m\]:\[\e[4m\]\W\[\e[0m\] \$ " | |
# ALIASES | |
# ========= | |
alias ls="ls -lh" |
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
# Input | |
events = [ | |
event(status: 'IDLE', job: 1, date: '2014-01-01'), | |
event(status: 'BUSY', job: 1, date: '2014-01-02'), | |
event(status: 'BUSY', job: 1, date: '2014-01-03'), | |
event(status: 'BUSY', job: 2, date: '2014-01-04'), | |
event(status: 'BUSY', job: 2, date: '2014-01-05'), | |
event(status: 'BUSY', job: 2, date: '2014-01-06'), | |
event(status: 'IDLE', job: 2, date: '2014-01-07'), | |
event(status: 'BUSY', job: 3, date: '2014-01-08'), |
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/ruby | |
LBRACE = '{' | |
RBRACE = '}' | |
LBRACKET = '[' | |
RBRACKET = ']' | |
COMMA = ',' | |
COLON = ':' | |
WHITESPACE = /\s/ |
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
require 'io/console' | |
class PressAnyKey | |
MESSAGE = 'Press any key to continue...' | |
def initialize(console: nil, message: MESSAGE) | |
console ||= File.open('/dev/tty', 'w+') | |
console.puts message | |
console.raw { |io| io.readchar rescue nil } | |
rescue | |
warn "Couldn't connect to console!" |
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 RubyProcess | |
WAIT_HELPER = <<-EOS | |
# Top-level method to signal the parent process | |
# and wait for an interrupt. | |
def wait_for(seconds) | |
# Signal parent we are ready. | |
Process.kill('USR1', Process.ppid) | |
# Wait for interrupt. | |
sleep(seconds) |
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 World | |
def initialize(cells) | |
@cells = cells | |
@row_count = cells.length | |
@col_count = cells[0].length | |
end | |
def living_neighbours(col, row) | |
[ | |
cell(col, row - 1), # NORTH |
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 TanksForAllTheFish < RTanque::Bot::Brain | |
NAME = 'Tanks For All the Fish' | |
MAX_RANGE = 400.0 | |
include RTanque::Bot::BrainHelper | |
def tick! | |
if targets_nearby? | |
# command.speed = 2.0 | |
# command.heading = Random.rand(-1.0..1.0) |
OlderNewer