Skip to content

Instantly share code, notes, and snippets.

View wilson's full-sized avatar

Wilson Bilkovich wilson

View GitHub Profile
words = %w(one two three lol zarglezargle one two six jambo)
p words.select {|word| word if (word.length > 3)..(word.length > 5) }
# output:
# ["three", "lol", "zarglezargle", "jambo"]
# 'one' and 'two' are skipped because they are not > 3 characters in length
# 'three' triggers the left side of the flip-flop condition
# 'lol' is selected because the left side has triggered, but not the right side
# 'zarglezargle' triggers the right side condition, and 'turns off' the flip-flop
# Because we used '..' here instead of '...' in the flip-flop, the condition returns true
# > {:x => 4, :y => 7}.keys_sorted_by_value
# [:y, :x]
class Hash
def keys_sorted_by_value
to_a.sort_by {|tuple| rand - tuple.last.to_i}.map {|tuple| tuple.first}
end
end
data = {}
choices = ('a'..'z').to_a
100_000.times do |i|
data[i] = choices[rand(26)]
end
data.sort_by {|k,v| k}
(gdb) r
Starting program: /Users/wilson/code/rbx/bin/rbx -P stuff.rb
Reading symbols for shared libraries +++. done
Reading symbols for shared libraries ... done
Reading symbols for shared libraries . done
Catchpoint 1 (exception thrown).
Catchpoint 1 (exception caught), throw location vm/exception.cpp:25, catch location unknown, exception type rubinius::TypeError
0x00007fff85953b9d in __cxa_throw ()
(gdb) bt
obj = "something"
method_name = "foo"
obj.instance_eval <<-CODE
def #{method_name}
"blah"
end
CODE
# ... or..
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-08-15/">
<reservationSet>
<item>
<reservationId>r-44a5402d</reservationId>
<ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
<groupSet>
<item>
<groupId>default</groupId>
</item>
</groupSet>
---
gem: --no-ri --no-rdoc
:benchmark: false
:backtrace: true
:update_sources: true
:verbose: really
:sources:
- http://gemcutter.org
- http://gems.rubyforge.org
- http://gems.github.com
# Run the bundler directly instead of relying on Rake to do it
if ARGV.any? {|task_name| task_name =~ /^gems:bundle$/}
system "gem bundle"
end
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
@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