Skip to content

Instantly share code, notes, and snippets.

@simon2k
simon2k / IpCalculator.rb
Created March 17, 2012 19:06
IpCalculator
class Ip < Array
def initialize(arg)
case arg
when Array # array with octets
concat(arg)
when /(\d{1,3}\.){3}\d{1,3}/ # string with decimal address - splitted by dots
concat(arg.split('.')).map!(&:to_i)
when /\d{1,32}/ # string with binary address - not splitted by dots
concat(arg.scan(/\d{1,8}/).map { |oct| oct.to_i(2) })
else
# set default prefix
set -g prefix C-w
unbind C-b
# set start index
set -g base-index 1
# default time to repeat
set -g repeat-time 1000
@simon2k
simon2k / gist:2247405
Created March 30, 2012 06:14
tmux - sample script
tmux new-session -s main -n "Finch & Gmail" -d
tmux split-window -v -t main
tmux split-window -h -t main:1.0
tmux split-window -h -t main:1.1
tmux send-keys -t main:1.0 'finch' C-m
tmux send-keys -t main:1.1 'w3m mail.google.com/mail/u/0/?ui=html' C-m
tmux send-keys -t main:1.3 'mocp' C-m
tmux new-window -n Browser -t main
tmux send-keys -t main:2 'w3m google.com' C-m
@simon2k
simon2k / gist:2250576
Created March 30, 2012 10:13
sokoban
# http://www.rubyquiz.com/quiz5.html
# SOKOBAN
# gem install highline
require 'highline/system_extensions'
include HighLine::SystemExtensions
class String
# define methods:
# crate? garage? wall? man?
{ 'crate?' => /o|\*/, 'garage?' => /\.|\*/,'man?' => /@|\+/, 'wall?' => /#/ }.
@simon2k
simon2k / gist:2994758
Created June 26, 2012 09:55
rspec debugger
require 'ripl'
config.after(:each) do
if exception = example.instance_variable_get(:@exception)
save_and_open_page unless Capybara.current_driver == :selenium
Ripl.start :binding => binding
end
end
require "rubygems"
require 'rspec/rails'
require 'kameleon'
require 'kameleon/ext/rspec/dsl'
require 'support/_support/helpers'
include Capybara::DSL
Capybara.default_selector = :css
Capybara.default_wait_time = 2
Capybara.default_driver = :selenium
#!/bin/bash
set -e
pivotal_ticket_id=$1
function commits_from_development() {
git checkout development > /dev/null 2>&1
git log --reverse --oneline --no-abbrev-commit --grep $1 | cut -d ' ' -f 1
}
class Maze
require 'singleton'
include Singleton
def process_maze_matrix(maze_matrix)
@maze_matrix = maze_matrix
set_max_coordinates_for_maze!
set_entrances_to_maze!
end
@simon2k
simon2k / codeeval_155.rb
Created December 14, 2014 17:42
Solution for code eval 55
N = 4
class Coordinate
MAX_COORDINATE = N
MIN_COORDINATE = 0
def initialize(y, x)
@y = y
@x = x
end
@simon2k
simon2k / gist:38ca0a95b9e94bfa58d5
Created February 12, 2015 08:59
Longest Common Subsequence
class LongestCommonSequence
def initialize(str1, str2)
@str1 = str1
@str2 = str2
@cached_lcs_for_points = {}
end
def get
get_lcs(0, 0)
end