Skip to content

Instantly share code, notes, and snippets.

View dwaite's full-sized avatar
💭
Wondering what status is for

David Waite dwaite

💭
Wondering what status is for
View GitHub Profile
# Performs normal match and returns MatchData object from $~ or nil.
def match(str)
unless str
Regexp.last_match = nil
return nil
end
str = StringValue(str)
Regexp.last_match = search_region(str, 0, str.size, true)
# Performs normal match and returns MatchData object from $~ or nil.
def match(str)
unless str
Regexp.last_match = nil
return nil
end
str = StringValue(str)
Regexp.last_match = search_region(str, 0, str.size, true)
@dwaite
dwaite / gist:869451
Created March 14, 2011 16:59
regexp-test.rb
def foo
puts "before: '#{$~}'"
/foo/ =~ 'foo'
puts "after: '#{$~}'"
clear_last_match
puts "after call: '#{$~}' (should still be set)"
end
def clear_last_match
$~ = nil
ruby-1.9.2-p180 :008 > z = Fiber.new{Thread.current}.resume
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :009 > Thread.current
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :010 > z = Fiber.new{Thread.current.object_id}.resume
=> 2151955260
ruby-1.9.2-p180 :011 > Thread.current.object_id
=> 2151955260
$ RBXOPT=-Xprofile\ -Xprofiler.graph\ -Xprofiler.full_report rbx -S rspec spec -f p &>foo
bash-3.2$ vim foo
bash-3.2$ grep Array#map foo
0.00 0.22 1 Array#map [74]
[74] 0.3 0.00 0.22 1 Array#map [74]
0.00 0.22 1 Array#map [74]
0.00 0.22 4 Array#map [76]
[76] 0.3 0.00 0.22 4 Array#map [76]
0.00 0.22 4 Array#map [76]
0.00 0.22 1 Array#map [80]
#include <stdio.h>
/* prints 78.882004 */
int main(int argc, char** argv) {
float f = 78.882;
printf("%f\n", f);
return 0;
}
We couldn’t find that file to show.
#!/usr/bin/ruby
# Set two thread locals
Thread.current["foo"] = "fooval"
Thread.current["bar"] = "barval"
puts [Thread.current["foo"], Thread.current["bar"]]
# prints:
# fooval
# barval
____ ____
| |
|__ \ / __|
| / \ |
|____ ____|

Keybase proof

I hereby claim:

  • I am dwaite on github.
  • I am dwaite (https://keybase.io/dwaite) on keybase.
  • I have a public key whose fingerprint is B6E6 30B2 71A7 1FF9 393E 4E6C 5E52 A11A 5979 897C

To claim this, I am signing this object: