makandra dev

...of requiring the relevant files below its directory. app assets stylesheets application.css blocks index.css foo.css.sass bar.css.sass ^ # app/assets/stylesheets/blocks/index.css *= require foo *= require bar ^ # app/assets/stylesheets/application.css *= require blocks Debugging One step in debugging the...

...a BasicObject class, you need to prefix them with ::. This will not work class Foo < BasicObject def bar Hash.new end end Foo.new.bar # => NameError: uninitialized constant Foo::Hash

If the argument list is the same every time: expect(object).to receive(:foo).with('argument').and_return('response 1', 'response 2') If the argument list differs between invocations:

...object).to receive(:foo).with('argument 1').ordered.and_return('response 1') expect(object).to receive(:foo).with('argument 2').ordered.and_return('response...

Use the attached initializer to do stuff like this str = "abc" str.imbue(:foo => 'foo value', :bar => 'bar value') puts str.foo # 'foo value' puts str.bar # 'bar value...

gist.github.com

...NestedHash.read hash, 'a', 'b', 'c' # => 'value' NestedHash.read hash, 'a' # => { b: { c: 'value' } } NestedHash.read hash, 'foo', 'bar' # => undefined Inspired by victusfate. Code class @NestedHash @read: (objekt, keys...) -> if objekt and keys.length...

...level2: 'value' it 'returns undefined when any of the keys is missing', -> value = NestedHash.read {}, 'foo', 'bar' expect(value).not.toBeDefined...

...in helpers like link_to and content_tag: = link_to 'Label', root_url, :data => { :foo => 'bar', :bam => 'baz' } This will produce: Label Only works in Rails 3. In Rails...

= link_to 'Label', root_url, 'data-foo' => 'bar', 'data-bam' => 'baz...

makandra dev

@reboot start_sidekiq 23 8 * * * baz 30 * * * * plop 5 8 * * * bar 1 0 * * * foo # End Whenever generated tasks for: project100 While you can human-parse this one easily, crontabs...

...Output for the example above will be: @reboot start_sidekiq 30 * * * * plop 1 0 * * * foo 5 8 * * * bar 23 8 * * * baz If you want to sort by day (k3), month...

...with remove_stale_original. It occurs for example if you replace an existing file "foo.avi" with "foo.mov...

...without quotes after a puppetmaster update (it was working for months before that). Bad: foo: %{::fqdn} Good: foo: "%{::fqdn}" I've debugged the error like this: deleted all yaml files...

...should strip carriage returns from any pasted code and prose' do article = Note.new(:prose => "foo\n\rbar", :code => "baz\n\rbam") article.should_receive(:prose=).with("foo\nbar") article.should_receive(:code...

...of jQuery, you may often see events bound to single elements only, like this: $('foo').observe('change', updateThings); $('bar').observe('change', updateThings); $('baz').observe('change', updateThings); If you are calling...

Instead, just do it similar to what you know from jQuery: document.on('change', '#foo, #bar, #baz', updateThings); Or, just apply a nice data attribute to the form fields, and...

...It just does memoization and does it well. The syntax is similiar also: class Foo include Memoizer def bar ... end memoize :bar end If you're using Ruby 2.1+, you...

...can write this even shorter: class Foo include Memoizer memoize def bar ... end end This is because def returns the method name as a symbol in...

...that contains values from Ruby variables. E.g. you want to call a Javascript function foo(...) with the argument stored in the Ruby variable @foo. You can do this by using...

...that are tagged with just awesome and cool User.tagged_with("awesome", "cool", :owned_by => foo ) # Users that are tagged with just awesome and cool by 'foo...

blog.blockscore.com

...a mix of them. It returns nil if any intermediate value is missing. x = { foo: { bar: [ 'a', { baz: 'x' } ] } } x.dig(:foo, :bar) # => [ 'a', { baz: 'x' } ] x.dig(:foo, :bar, 1, :baz...

x.dig(:foo, :wronk, 1, :baz) # => nil There is a tiny gem that backports this...

makandra dev
github.com

...for cleaning up multiple local database server installations in batches. Derivative database names like foo_development and foo_test4 for foo are handled together with foo to allow for per...

...probably did something like this in your state_machine...

def self.final_states [ :foo, :bar ] end transition (all - machine.final_states - [:baz]) => :target_state Instead, define the source states like...

def self.final_states [ :foo, :bar ] end transition (all - (machine.final_states | [:baz])) => :target_state

makandra dev

...s SimpleDelegator (or vice versa). This following will not work: class MyDecorator < SimpleDelegator def foo end end MyDecorator.new(Object.new).andand.foo The reasons are a bit subtle, basically SimpleDelegator will "force...

developer.mozilla.org

...When you set a key, you can read its value just like always. hash['foo'] = 23 hash['foo'] // => 23 But instead of returning undefined for unset keys, our get proxy...

...set the xsi:type attribute like this: client.call(:rpc_method, message: { :some_object => { :name => 'foo', :other => 'bar', '@xsi:type' => 'somenamespace:SomeObject' } } ) This is roughly equivalent to this in Javaland, where...

...you have magic generated stub code: SomeObject so = new SomeObject(); so.setName('foo'); so.setOther('bar'); client.rpcMethod(so...

The good E. g. in the following example, Array could mean either Foo::Array or simply Array: class Foo def list Array.new end end What Ruby does here...

...is to see if the name Array makes sense inside of Foo::, and if that fails, resolves it to ::Array (without a namespace). The bad This is relevant for old...

rspec.info

...would be to test if the current page has a button with the label "Foo". There are many ways to render a button with CSS: Foo We cannot express it...

...with a single have_css() matcher, since we need the { text: 'Foo' } option for some cases ( ), but not for others ( ). What we can do is chain multiple have_css() matchers...

...whenever we try to select an option from a Capybara complains: No such option 'Foo' in this select box. Available options: 'Foo', 'Bar', 'Baz' (Capybara::OptionNotFound) This seems to happen...

web.archive.org

You can restore the original implementation of stubbed methods with unstub: object.stub(:foo => 'bar') # ... object.unstub(:foo) In recent RSpecs double is the preferred way to create a mock...