Skip to content

Instantly share code, notes, and snippets.

View banister's full-sized avatar
🇳🇱

John Mair banister

🇳🇱
View GitHub Profile
[1] (pry) main: 0> require './prytime'
=> true
[2] (pry) main: 0> def a
[2] (pry) main: 0* x = :circky
[2] (pry) main: 0* y = :ryanie
[2] (pry) main: 0* b()
[2] (pry) main: 0* end;
[3] (pry) main: 0> def b
[3] (pry) main: 0* z = :fowlie
[3] (pry) main: 0* y = :mon_french_guy
@banister
banister / gist:1289619
Created October 15, 2011 14:11
using LD_PRELOAD to override functions like rb_raise() in ruby with my own definitions in an .so
If you set LD_PRELOAD to the path of a shared object, that file will be loaded before any other library (including the C runtime, libc.so). So to run ls with a your special malloc() implementation, do this:
$ LD_PRELOAD=/path/to/my/malloc.so /bin/ls
require 'io/console'
class Coolline
# Creates a new cool line
# @param [IO] input Input to read from. This has to be an actual IO object.
# @param [IO] output Output. This can be an object of any kind.
#
# @yield after each character entered
# @yieldparam [String] line
# @yieldreturn [String] string to print for this input
ls
Tweak display of methods with:
-m show only public methods
-p show public/protected/private methods (i.e. -p implies -m)
-M show only public instance methods
@banister
banister / gist:1198126
Created September 6, 2011 16:46
Changing current directory with `posix_spawnp`
Changing current directory with `posix_spawnp`
```ruby
posix_spawn('sh -c "cd blah ; ls')
```
method(:foo).to_java.source_location(Thread.current.to_java.getContext())
pry(main)> def hello(friends)
pry(main)* puts "my friends i have come here to say hello"
pry(main)* puts "hello is an unusual word, but is appropriate at a time like this"
pry(main)* puts "when it has been so long since we last met"
pry(main)* puts "before the dogs were put to sleep"
pry(main)* s/hello/goodbye
1: def goodbye(friends)
2: puts "my friends i have come here to say goodbye"
3: puts "goodbye is an unusual word, but is appropriate at a time like this"
4: puts "when it has been so long since we last met"
require 'pry'
require 'drb'
DRb.start_service
client = DRbObject.new nil, ARGV[0]
# Dummy proxy, DRb won't allow us to pass Readline directly.
Proxy = Object.new
pry(main)> blame Pry#repl
John Mair def repl(target=TOPLEVEL_BINDING)
John Mair target = Pry.binding_for(target)
John Mair target_self = target.eval('self')
John Mair
John Mair repl_prologue(target)
Mon ouïe
John Mair # cannot rely on nesting.level as
John Mair # nesting.level changes with new sessions
John Mair nesting_level = nesting.size
int main(int argc, char *argv[]) {
TestDefaultFormatter formatter;
use_formatter(formatter);
describe("Test", []{
it("1 == 1", []{ assert(1).equals(1); });
it("2 == 1", []{ assert(2).equals(1); });
describe("with strings", []{
it("std::string == char*", []{ assert_equals(std::string("a"), "a"); });