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
# this only works in 1.8 | |
module People | |
extend self | |
def self.base | |
Object | |
end | |
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
class CurrencyParser | |
def self.parse(currency) | |
currency.gsub(/[$,]/,"").to_i | |
end | |
end | |
CurrencyParser.parse("$40,000") #=> 40000 |
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
options = Spec::Runner::OptionParser.parse "spec/models/some_spec.rb", $stderr, $stdout | |
Spec::Runner::CommandLine.run(options) |
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 'ripper' |
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
[mysqld] | |
# keeps it from executing duplicate queries | |
query_cache_type = 1 | |
query_cache_size = 16M | |
# give as much as you can to the buffer pool | |
innodb_buffer_pool_size = 1000M | |
innodb_additional_mem_pool_size = 200M | |
# helps speed up for lots of short write transactions |
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 'ffi' | |
class MIDISysexSendRequest < FFI::Struct | |
layout :destination, :pointer, | |
:data, :pointer, | |
:bytes_to_send, :uint32, | |
:complete, :int, | |
:reserved, [:char, 3], | |
:completion_proc, :pointer, | |
:completion_ref_con, :pointer |
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 'ffi' | |
module C | |
extend FFI::Library | |
ffi_lib '/System/Library/Frameworks/CoreMIDI.framework/Versions/Current/CoreMIDI' | |
attach_function :MIDIGetNumberOfDevices, [], :int | |
attach_function :MIDIGetDevice, [:int], :pointer | |
# midi_obj, property_id, value_of_property | |
attach_function :MIDIObjectGetStringProperty, [:pointer, :pointer, :pointer], :int | |
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
tree = ["A", "B", "C", ["D", "E", ["F", "G", "H"], "I"], "J"] | |
def emit( expression, accum ) | |
if expression.empty? | |
accum += ")" | |
return accum | |
end | |
accum = "(" if accum.empty? | |
head, *tail = expression |
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
number = 123456789 | |
digits = (Math.log10(number) + 1).to_int | |
result = 0 | |
digits.times do |i| | |
reverse_digit_place = (digits - (i + 1)) | |
digit = number % 10 | |
result = result + (digit * (10 ** reverse_digit_place)) | |
number = number / 10 |
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 'quantity' | |
6.gallons + 5.quarts | |
# => 7.24999669784779 gallon | |
(6.gallons + 5.quarts).to_liters | |
# => 0.02744421 liter | |
# this one might be off.. | |
1.liter.to_gallons |