...or IIFEs) to prevent local variables from bleeding into an outside scope: (function() { var foo = "value"; // foo is scoped to this IIFE })(); In Coffeescript an IIFE looks like this: (->
...value" # foo is scoped to this IIFE )() There is also a shorthand syntax with do: do -> foo = "value" # foo is scoped to this IIFE You can also use do with...
add_column :my_table, :search_text, :virtual, type: :text, as: search_text_expression(:foo, :bar, :baz), stored: true add_index :my_table, :search_text, using: :gin, opclass: :gin_trgm...
...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...
...an element "the container's width minus 20px on each side"? Here you go: .foo { width: calc(100% - (20px * 2)); } When using Sass, you need to interpolate Sass expressions:
.foo width: calc(100% - #{$margin}) Supported by all modern browsers and IE9...
...speed a like query that has a wildcard on the right side: SELECT * FROM foo WHERE field LIKE "bar%" # will be faster with an index It can not speed up...
...a query that has a variable left side: SELECT * FROM foo WHERE field LIKE "%bar%" # will not be faster with an index That also means if you use the ancestry...
...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...
...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...
...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']
...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...
...prevents referencing closures, scopes, etc. from being garbage-collected. This code leaks memory: @app.directive 'foo', -> link: (scope, element, attributes) -> $(document).on 'click', -> # code here To prevent leaks you must manually...
...elements that are not your own descendants. This code does not leak memory: @app.directive 'foo', -> link: (scope, element, attributes) -> listener = -> # code here $(document).on 'click', listener scope.$on '$destroy', -> $(document...
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...
...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
...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...
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...
...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...
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
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...
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...
...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...
...to look something up and gets different results on different Rubies. Consider this: module Foo FOO = 42 end class Bar include Foo end On Ruby 1.8, Bar won't have...
...FOO defined as a constant since that's (even though it's accessible): 1.8.7 > Foo.const_defined? :FOO => true 1.8.7 > Bar.const_defined? :FOO => false 1.8.7 > Bar::FOO => 42 Ruby 1.9 introduces...
...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.