This file contains hidden or 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 PokerHandRank | |
RANKS = %w(high pair tpair trip stright flush full four royal) | |
def initialize(hand) | |
@hand = hand | |
end | |
def flush? | |
@hand.suits.any? {|k, v| v >= 5 } |
This file contains hidden or 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
names = Car.uniq.pluck(:name) | |
wheel_counts = Car.uniq.pluck(:wheels) | |
groups = [] | |
names.each do |name| | |
wheel_counts.each do |wheel_count| | |
groups << Car.where(name: name, wheel: wheel_count) | |
end | |
end |
This file contains hidden or 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
> vi spec/controllers/users_controller_spec.rb | |
> rspec spec/controllers/users_controller_spec.rb |
This file contains hidden or 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
UsersController | |
GET 'index' | |
returns http success | |
GET 'show' | |
returns http fail (FAILED - 1) | |
GET 'new' | |
returns http success | |
GET 'edit' | |
returns http success (FAILED - 2) |
This file contains hidden or 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 'rails_helper' | |
RSpec.describe UsersController, :type => :controller do | |
describe "GET 'index'" do | |
it "returns http success" do | |
get 'index' | |
expect(response).to be_success | |
end | |
end |
This file contains hidden or 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
XXXXXXXX | |
X X | |
X XXXX X | |
X X X X | |
X X X X | |
X XXXX X | |
X X | |
XXXXXXXX | |
XXXXXXXXXXXXXXXX | |
XXXXXXXXXXXXXXXX |
This file contains hidden or 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
# here's what Array would output from inspect if it wasn't overridden: | |
class Array | |
def inspect | |
"<##{self.class}:" + "0" + "x" + "#{self.object_id.to_s(16)}>" | |
end | |
end | |
[1,2,3].inspect | |
=> "<#Array:0x1491570>" |
This file contains hidden or 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 HWAVEOUT < FFI::Struct | |
layout :i, :int | |
end | |
class WAVEFORMATEX < FFI::Struct | |
def initialize | |
self[:wFormatTag] = 1 | |
self[:nChannels] = 1 |
This file contains hidden or 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
waveOutOpen returns 0 (no error) if I don't use the callback form | |
0 | |
but if I use a callback, the moment it returns from the callback, there is a seg fault | |
note that the code inside the callback runs, as I am puts-ing the mMsg which is 955 | |
for WOM_OPEN which tells us the device was opened. | |
this is on ruby 1.9.3p484 (2013-11-22) [i386-mingw32] running 1.9.3 x86-mingw32 on | |
Windows 7 | |
955 | |
sound.rb:67: [BUG] Segmentation fault | |
ruby 1.9.3p484 (2013-11-22) [i386-mingw32] |
This file contains hidden or 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
bits = eval("0x" + [0.15625].pack('g').unpack('H16')[0]).to_s(2).rjust(32,"0") | |
#=> "00111110001000000000000000000000" | |
# these are the bits of 0.15625 represented as a single precision float | |
sign = bits[0] | |
#=> "0" | |
exponent = bits[1..8] | |
#=> "01111100" | |
mantissa = bits[9..32] | |
#=> "01000000000000000000000" | |
sign = sign.to_i == 0 ? 1 : -1 |