Skip to content

Instantly share code, notes, and snippets.

@apotonick
apotonick / gist:fed8d7136370877b057762877f060cd3
Last active October 26, 2016 23:14
RSpec RSpec::Core::ExampleGroup::WrongScopeError
module Rspec
module Helpers
def factory(name, method_name, &block)
let(name) { block.call }
end
end
end
RSpec.configure do |c|
c.extend Trailblazer::Rspec::Helpers
var NewInput = React.createClass() {
getInitialState: function() {
return {
value: 'Hello!',
othervalue: this.props.othervalue
};
},
handleChange: function(event) {
this.setState({value: event.target.value});
@apotonick
apotonick / xubuntu-hacks.md
Last active June 13, 2017 06:41
Xubuntu hacks

Key to turn on laptop screen

I have a two monitor setup, but I like my laptop screen turned off (via Display).

When disconnecting the VGA cable, the screen is blank. I put the following command into ~/scripts/turn_on_laptop_screen.sh.

xrandr --output eDP-1 --mode 1366x768
@apotonick
apotonick / collection.rb
Last active November 26, 2015 06:10
HAL collection document
{"_embedded"=>
{"things"=>
[{"name"=>"TRB",
"id"=>3,
"_embedded"=>
{"authors"=>
[{"email"=>"rob@trb.to",
"id"=>3,
"_links"=>{"self"=>{"href"=>"/api/users/3"}}}]},
"_links"=>{"self"=>{"href"=>"/api/things/3"}}},
@apotonick
apotonick / gist:9ec14bc2ef83c96fa4f9
Created September 22, 2015 01:14
Rack-test experimenting

There's a :fatal option when writing to rack.errors. However, that doesn't happen so far.

This will write exceptions to STDOUT

Rails.logger = Logger.new(STDOUT)
# Gemfile:
gem "minitest-line"
# ~/.bash_login
alias t="bundle exec ruby -Itest "
# running tests:
# $ t test/crud_test.rb -l 122
@apotonick
apotonick / gist:2a507ceccc36ec1875af
Created June 11, 2015 23:02
Infer representer from contract (Reform 2)
contract_class = ...
representer_class = Disposable::Twin::Schema.from(contract_class,
include: [Roar::JSON],
superclass: Representable::Decorator,
representer_from: lambda { |inline| inline.representer_class },
options_from: :deserializer
)
@apotonick
apotonick / gist:65a254432d40288819ec
Created June 5, 2015 01:55
Thoughts about output buffers
problem is that in capture, we need access to the output buffer, and that only works via an instance variable, as when we call capture in the view, it goes back to the cell, but doesn't "pass" us the current output buffer or the current template.
gem "ruby-prof"
require "ruby-prof"
Song = Struct.new(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n, :o) # FIXME: what if we don't have STruct#options
song = Song.new(1,2,3,4,5,6,7,8,9,10)
class CopyTwin
alias be="bundle exec"
alias t="bundle exec ruby -Itest"