Skip to content

Instantly share code, notes, and snippets.

View wilson's full-sized avatar

Wilson Bilkovich wilson

View GitHub Profile
@wilson
wilson / carbon.md
Created November 5, 2009 21:23 — forked from defunkt/carbon.md
use ruby instead of perl

Vim

autocmd BufWritePre * :%s/\s\+$//e

Emacs

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Textmate

Process: vm [69331]
Path: /Users/wilson/code/rbx/vm/vm
Identifier: vm
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: ruby [68208]
Date/Time: 2009-11-06 16:44:22.851 -0500
OS Version: Mac OS X 10.6.1 (10B504)
Report Version: 6
@wilson
wilson / gist:234170
Created November 13, 2009 21:17
merge two sorted arrays
#!/usr/bin/env ruby
require 'time'
require 'benchmark'
class Thing
attr_accessor :timestamp
def initialize(timestamp)
@timestamp = timestamp
end
### running this code: http://gist.github.com/234170
### jruby trunk from last week
> jruby sorting.rb
Rehearsal ---------------------------------------------
merge: 1.070000 0.000000 1.070000 ( 1.070000)
nocopy: 0.730000 0.000000 0.730000 ( 0.730000)
------------------------------------ total: 1.800000sec
user system total real
本拠> bin/rbx ../sorting.rb
Rehearsal ---------------------------------------------
merge: 2.448515 0.000000 2.448515 ( 2.448516)
nocopy: 0.896591 0.000000 0.896591 ( 0.896639)
------------------------------------ total: 3.345106sec
user system total real
merge: 0.855341 0.000000 0.855341 ( 0.855353)
nocopy: 0.569976 0.000000 0.569976 ( 0.569993)
x,y,z = "X ", "Y ", "Z "
[x,y,z].each_with_index do |str, i|
str << str[0,1]
p str
redo if i == 1
end
puts "ruby version: #{RUBY_VERSION}"
pass = 0
proc do |@x|
pass += 1
puts "proc pass number #{pass}"
@x = 3 if pass == 1
puts "proc x is: #{@x}"
redo if pass != 2
module IncludeMe;end
module BehindTheScenes;end
# Include IncludeMe in a module
module One
include IncludeMe
end
# Add an ancestor to IncludeMe
module IncludeMe
Process: vm [69929]
Path: /Users/wilson/code/rbx/vm/vm
Identifier: vm
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: zsh [37874]
Date/Time: 2009-11-22 04:23:08.915 -0500
OS Version: Mac OS X 10.6.2 (10C540)
Report Version: 6
# shortcut method for opening a metaclass on the receiver
module Kernel;def m;class << self;self;end;end;end
Module.m # #<Class:Module>, metaclass of Module
Module.m.superclass # Class, because that is how Module is bootstrapped
Module.m.m # #<Class:#<Class:Module>>, metaclass of Module's metaclass
Module.m.superclass # #<Class:#<Class:Module>>
Module.m.m.superclass # #<Class:#<Class:Module>>
# Opening a metaclass on Module's metaclass changes its superclass to be the same as its metaclass's superclass!?