This file contains hidden or 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
| def run(*args) | |
| output = Struct.new(:pid, :stdout, :stderr) | |
| status = Open4.popen4(*args) do |pid, stdin, stdout, stderr| | |
| output = output.new pid, stdout.read, stderr.read | |
| end | |
| [status, output] | |
| end |
This file contains hidden or 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' | |
| require 'set' | |
| class Array | |
| def subset_subtr?(a) | |
| (self - a).length == 0 | |
| end | |
| def subset_inter?(a) | |
| (self & a).length == length | |
| end |
This file contains hidden or 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
| function git_add_submodule { git submodule add `cd $1; git remote -v | head -1 | cut -f 2 | cut -f 1 --delimiter " "` $1; } |
This file contains hidden or 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
| def show_ancestors object | |
| klass = object.is_a?(Class) ? object : object.class | |
| klass.ancestors.map do |a| | |
| a.is_a?(Class) ? a : a.ancestors | |
| end | |
| end |
This file contains hidden or 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
| $ pwd | |
| /Users/acook/Projects/personal/3380730 | |
| $ bash makepaths.sh | |
| -- current_file: requirepath.rb | |
| -- relative_path_of_current_file: . | |
| -- path: /Users/acook/Projects/personal/3380730 | |
| -- filematch: /Users/acook/Projects/personal/3380730/features/support/**/*.rb | |
| -- file: /Users/acook/Projects/personal/3380730/features/support/whatever/something.rb | |
| -- required: true |
This file contains hidden or 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
| # via http://www.megasolutions.net/ruby/Getting-the-size-of-the-terminal-in-a-portable-way-26006.aspx | |
| TIOCGWINSZ = 0x40087468 | |
| def get_winsize | |
| str = [0, 0, 0, 0].pack('SSSS') | |
| if STDIN.ioctl(TIOCGWINSZ, str) >= 0 | |
| rows, cols, xpixels, ypixels = str.unpack("SSSS") | |
| p rows, cols, xpixels, ypixels | |
| else | |
| puts "Unable to get window size" |
This file contains hidden or 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' | |
| # Reads keypresses from the user including 2 and 3 escape character sequences. | |
| def read_char | |
| STDIN.echo = false | |
| STDIN.raw! | |
| input = STDIN.getc.chr | |
| if input == "\e" then | |
| input << STDIN.read_nonblock(3) rescue nil |
This file contains hidden or 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
| co = checkout | |
| st = status | |
| ci = commit | |
| w = whatchanged | |
| nb = checkout -b | |
| b = branch | |
| amend = commit --amend | |
| unstash = stash pop | |
| unstage = reset HEAD -- | |
| remotes = remote -v |
This file contains hidden or 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
| def invert original | |
| result = Marshal.load Marshal.dump(original) | |
| original.each_with_index do |row, r_index| | |
| row.each_with_index do |column, c_index| | |
| result[c_index][r_index] = column | |
| end | |
| end | |
| result |
This file contains hidden or 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
| def extract_state object | |
| state = { local_variables: {}, instance_variables: {} } | |
| object_binding = object.send :binding | |
| puts eval('local_variables', object_binding) | |
| eval('local_variables', object_binding).each do |variable| | |
| state[:local_variables][variable] = eval "#{variable}", object_binding | |
| end | |
| eval('instance_variables', object_binding).each do |variable| |