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
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 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 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 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 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 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 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 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 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 |
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
I want to create two records which refer to each other, but | |
Bindata seems to not want to let me do that. | |
The two solutions I came up with are to create a copy of one | |
record to another class with most the same functionality, or | |
to create an anonymous struct in one to copy most the functionality. | |
Both of these solutions require me to repeat myself, so I'd | |
like to create a more compact version like the first example. | |
Am I defining things wrong or does Bindata simply not allow |