This file contains 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 Snatcher < BasicObject | |
C = ::Object.new | |
class << C | |
def abduct_method(meth, arity) | |
ObjectSpace.each_object(Module) do |mod| | |
next if mod.kind_of? Class | |
if mod.instance_methods.include?(meth) | |
return mod.instance_method(meth) | |
end |
This file contains 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 | |
require 'open-uri' | |
require 'rexml/document' |
This file contains 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
What I mean is that even though JS method invocation seems to work like this: | |
(obj.method)(args) | |
it's a bit trickier than that. See this: | |
> a = {} | |
> a.toString() | |
"[object Object]" | |
> (a.toString)() |
This file contains 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
$ history 1 | awk {'print $2, $3, $4'} | sort | uniq -c | sort -k1 -rn | head -n 30 | |
172 fg | |
164 git st | |
163 ls | |
72 ruby create_event_local.rb blah | |
62 git push | |
59 git pull | |
54 git commit -m | |
50 git di | |
47 bundle |
This file contains 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
# Summary: In MRI 1.9, if you keep threads in an array in a local variable, the threads may outlive the local variable. | |
# I have not yet been able to produce a scenario in which the threads are ever garbage-collected. | |
# You have to remove the thread from the array before it goes out of scope, e.g. using #pop or #clear. | |
# INPUT DESIRED: If anyone can demonstrate a condition in which a local array keeps threads and those threads are eventually GC'd. | |
# INPUT DESIRED: Is this expected behavior or a bug? | |
# NOTE: This test will not work as expected in JRuby, because its garbage collection works differently. Whether the same behavior exists in JRuby is an exercise for someone smarter than I am. | |
class Foo | |
THREAD_PROC = lambda{ (0..10).to_a.map do Foo.new end } |
This file contains 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
# http://blog.jazzychad.net/2012/08/01/array-iteration-problem.html | |
def add1(arr, val, n) | |
range = (0 ... arr.length) | |
indexes = n < 0 ? range.reverse_each : range.each | |
n = n.zero? ? arr.length : n.abs | |
indexes.each do |idx| | |
if arr[idx] == val | |
arr[idx] += 1 |
This file contains 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 Object | |
private :dup | |
private :clone | |
private :freeze | |
end | |
module ValueObject | |
def self.included(into) | |
into.send :public, :dup | |
into.send :public, :clone |
This file contains 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
#!/bin/sh | |
# backdroppify - sizes an image to the minimum size which will fill your entire screen & trims overflow | |
bgsize=`xwininfo -root | grep -- -geometry | cut -d' ' -f4 | cut -d+ -f1` | |
convert $1 -resize $bgsize^ -gravity center -extent $bgsize ~/.backdrop.jpg | |
set-backdrop |
This file contains 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 'test/unit/testcase' | |
require 'test/unit' if $0 == __FILE__ | |
class Proc | |
def as_proc | |
if arity == -1 | |
self | |
else | |
aty = arity.abs - (arity < 0 ? 1 : 0) |
This file contains 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 'celluloid' | |
require 'zip/zipfilesystem' | |
require 'uri' | |
require 'net/http' | |
class ZipManifest | |
include Celluloid | |
def initialize(filename) | |
@urls = {} |