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 type(name) | |
| ENV['PATH'].split(File::PATH_SEPARATOR).each do |p| | |
| que = p + File::SEPARATOR + name | |
| return que if File.exists?(que) and File.executable?(que) | |
| end | |
| false | |
| end | |
| type 'foo' # false | |
| type 'openssl' # '/usr/bin/openssl' |
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
| class Hash | |
| def diff(this) | |
| self.dup.delete_if { |key, val| | |
| this[key] == val | |
| }.merge(this.dup.delete_if { |key, val| self.has_key?(key) } ) | |
| 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
| # So to explain this contrived example a bit. Say you have an array of input that you wanted to match with | |
| # multiple regexes how do you in ~1 line match the lot of things. | |
| # | |
| # So say for a given input of %w/ab abc abcde bcde bc efgh etc/ | |
| # You have multiple regexes to match against, in this case its just an array of strings that we build regexes off of. | |
| # | |
| # This is my kitbash first try. | |
| # | |
| # Anyone have any better ideas? I know you could just union them both if === works as your comparison: | |
| # %w/ab abc bc bcde efgh/ & %w/ab bc/ |
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
| main> [[:a], nil, :b, nil, nil].collect!{|x| Array(x)} | |
| => [[:a], [], [:b], [], []] |
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
| main> RVM::Environment.new.list_strings | |
| => ["jruby-1.6.5", | |
| "macruby-0.10", | |
| "rbx-head", | |
| "ruby-1.8.6-p420", | |
| "ruby-1.8.7-p352", | |
| "ruby-1.9.2-p290", | |
| "ruby-1.9.3-p0"] | |
| main> RVM::Environment.new.list.rubies | |
| => ["jruby-1.6.5", |
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
| $ ruby -e 'puts "\e(0\e6n\e(B"' | |
| ┼ | |
| $ ruby -e 'puts "\e(0\e6m\e(B"' | |
| └ |
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
| my $var = "anchor1 lkajfdlkj | |
| match | |
| till | |
| the | |
| next | |
| anchor2 | |
| more | |
| stuff | |
| anchor3 | |
| blah |
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
| Sampling process 28334 for 3 seconds with 1 millisecond of run time between samples | |
| Sampling completed, processing symbols... | |
| Analysis of sampling Google Chrome Helper (pid 28334) every 1 millisecond | |
| Process: Google Chrome Helper [28334] | |
| Path: /Users/Shared/Applications/Google Chrome.app/Contents/Versions/15.0.874.121/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper | |
| Load Address: 0x6d000 | |
| Identifier: com.google.Chrome.helper | |
| Version: 15.0.874.121 (874.121) | |
| Code Type: X86 (Native) | |
| Parent Process: Google Chrome [28232] |
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
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| # irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple | |
| # versions of Ruby at once (using RVM) | |
| # | |
| # By Peter Cooper, BSD licensed | |
| # | |
| # Main dependency is term-ansicolor for each impl: | |
| # rvm exec gem install term-ansicolor |
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
| $ cat eval_with_comment.rb | |
| b = binding | |
| input = $stdin.read.split(/\n/) | |
| input.each do |line| | |
| line.gsub(/\s+\#.*$/, %q{}) | |
| out = eval line, b | |
| puts "#{line} \# #{out.inspect}" | |
| end | |
| $ cat a.rb | ruby eval_with_comment.rb | |
| %w/a b c d/ # ["a", "b", "c", "d"] |
OlderNewer