...to keep your test output and logs clean. How to express page breaks, headers, footers, etc. There are concepts and formattings that only make sense on paper, so the question...
...These are things like: Paper form Print margins Repeating header on every page Repeating footer on every page You can actually execute JavaScript before the page is rendered to PDF...
...you need complex expectations on method arguments like this SomeApi.should_receive(:find).with(:query => '*foo*', :sort => 'timestamp ASC', :limit => 100).and_return(['some result']) This is not very flexible, and...
Instead, consider doing this: SomeApi.should_receive(:find) do |params| params[:query].should == '*foo*' params[:sort].should == 'timestamp ASC' params[:limit].should == 100 ['some result']
...logic, all perform almost equally: require 'benchmark/ips' # requires the 'benchmark-ips' gem GC.disable class Foo define_method("foo") { 10.times.map { "foo".length } } class_eval 'def bar; 10.times.map { "foo".length }; end'
...baz; 10.times.map { "foo".length }; end end Benchmark.ips do |x| foo = Foo.new x.report("define_method") { foo.foo } x.report("def via class_eval") { foo.bar } x.report("def") { foo.baz } end Warming up -------------------------------------- define_method...
Indent text by 4 spaces. This way it is recognized as code. def foo "hello!" end def foo "hello!" end You can also create code blocks GitHub-style: ```
"hello!" end ``` def foo "hello!" end Lists * Bullet list item 1 * Bullet list item 2 Bullet list item 1 Bullet list item 2 You can also use + or - instead...
...the nth-child within a subset of siblings matching a selector. For example: .container .foo %span.my-selector .bar %div.my-selector .container > *:nth-child(1 of .my-selector) color: red
...port 16380 --database 1 INFO memory | grep maxmemory_human maxmemory_human:512.00M Memory footprint If you want to calculate the estimated Redis memory usage of a job, you can...
...memory usage before and after the job was enqueued. For a simple job like Foo.perform_async(1) the memory footprint is around 508 bytes. Here is a short table to...
...either some Ruby code or your Rails app, use the differ gem. puts Differ.diff "foo", "boo" # => {"boo" >> "foo"} Usage There are several variants available, all using the base method diff...
Standard formatting is :ascii. You also have :html and :color formatting: diff = Differ.diff "foo", "boo" puts diff.format_as :html # => boo foo puts diff.format_as :color # => \e[31mboo\e[0m...
...helper from a controller using the helpers method: # Inside a controller action helpers.link_to 'Foo', foo_path In older Rails versions you can use view_context instead: # Inside a controller...
view_context.link_to 'Foo', foo_path
URLs can transport key/value pairs ("parameters") using this syntax: /path?foo=bar If the value is blank, mind these subtle differences: URL Meaning /path?foo= Parameters have a key foo...
...Its value is an empty string. /path?foo Parameters have a key foo. Its value is null. /path Parameters have no key foo...
...and you modify the copy, you will run into the following behavior: original_hash = { foo: { bar: 'original value' } } copied_hash = original_hash.dup copied_hash[:foo][:bar] = 'changed value' original_hash # => { foo...
...changed value" } This is, because { bar: 'baz' } is an object, which is referenced in :foo. The copy of original_hash still holds the reference to the same object, so altering...
...passes with [up-hungry] fragments. Targeting sibling elements now supports union selectors like .parent .foo, .parent .bar...
...getter/setter functions, and probably never will. However, you can define getters/setters using Object.defineProperty: object = {} fooValue = undefined Object.defineProperty object, 'foo', get: -> fooValue set: (newValue) -> fooValue = newValue Some people are also doing...
...would actually be longer than two lines: Dies ist ein Text mit mehreren Zeilen foo bar would be rendered as Dies ist ein Text mit mehreren Zeilen... I recommend building...
status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end You may not be able to...
...when SomeException is raised Some advanced examples for scriptable breakpoints: debugger(pre: "info ;; puts @foo ;; info ;; bt ;; break @user.name") # starts debugging session after executing each of the pre commands
...Rails versions for each of the bundles: ~/my_project$ bundle show rails .../gems/rails-3.0.20 ~/my_project$ cd foo && bundle show rails .../gems/rails-3.2.13 Now you will usually just use bundle exec to run stuff...
~/my_project$ bundle exec ruby -e "require %(rails) ; puts Rails.version" 3.0.20 ~/my_project$ cd foo && bundle exec ruby -e "require %(rails) ; puts Rails.version" 3.2.13 So far, so good.
...method, created by a user in commit d47bf443: def hello 'world' end ^ $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello d47bf443 (Arne...
...is how Git blames those lines with and without the -w switch: $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello f5fae4c1 (Señor...
...Here is a useless comment. -# It will be removed. class File1 - def foo + def bar # ... end end diff --git a/file2.rb b/file2.rb index 550e1c6..600f4e3 100644 --- a/file2.rb +++ b/file2.rb...
...Here is another useless comment. class File2 - def foo + def bar # ... end end While you can easily stage such changes using git add -p, you can be much faster when...
context 'with lots of required arguments' do it 'should work' do subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello world' end it 'should work again' do subject.stub...
...target => 'universe' subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello universe' end it 'should work yet again' do subject.stub :target => 'multiverse' subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should...
...attribute on it, but then don't attach it to the DOM: $element = $(' '); $element.data('foo', 'bar'); After the last line in the code sample above, $element can no longer be...
We can call the method we're overriding inside our monkey patch: class Foo def bar(argument) 'Hello' + argument end end module FooExtensions def bar super(' in my') + ' World...
end class Foo prepend FooExtensions # the only change to above: prepend instead of include end Foo.new.bar # => 'Hello in my World' As mentioned, monkey patches are usually a threat to...
In Rubocop you might notice the cop Style/CaseEquality for e.g. this example: def foo(expected, actual) expected === actual end In case expected is a Regex, it suggests to change it...
...to the following pattern: def foo(expected, actual) expected.match?(actual) end In case expected is a Regex or a String, you need to keep ===. Otherwise the actual expression is always...
Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users. Here is how to generate that from an issue in Linear...
Copy the attached file to config/initializers/indent_string.rb and you can say "foo".indent(4) # " foo" Note you will find many simpler implementations of this method on the Interweb. They probably won...
it 'should indent the string by the given number of spaces' do "foo".indent(2).should == " foo" end it 'should indent multiple lines line by line' do