...When I go to the start page Then I should not see "Home of Foo" When our host is "foo.example.com" And I go to the start page

...see "Home of Foo" The host will be stubbed for the remainder of one scenario and restored after each scenario (i.e. you do not need an After step to clean...

Example def test(input) input.gsub /(f)/ do puts $1 'b' end end >> test('foo') f => "boo" >> test('foo'.html_safe) nil => "boo" Wat? More fun: It's not a...

...problem when using inline blocks. >> 'foo'.html_safe.gsub(/(f)/) { puts $1; 'b' } f => "boo" Why? This is because of the way rails_xss implements "unsafe" methods: # vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb UNSAFE_STRING_METHODS = [ ..., "gsub...

...added by calling the indexer method on the DatabaseCleaner module: DatabaseCleaner[:active_record, db: Foo]. The DatabaseCleaner gem itself does not define any cleaners. By default, it's empty.

When using _.extend/_.assign or _.merge, you will modify the destination object. object1 = { foo: 23, bar: 42 } object2 = { bar: 99 } _.extend(object1, object2) // => { foo: 23, bar: 99 } object1 // => { foo: 23, bar...

...you do not want to do that, simply extend into a new object: object1 = { foo: 23, bar: 42 } object2 = { bar: 99 } _.extend({}, object1, object2) // => { foo: 23, bar: 99 } object1 // => { foo...

...use for growing (e.g. to get from [1, 2, 3] to [1, 2, 3, "foo", "foo"] you have to say [1, 2, 3].fill("foo", 3..4) or...

...fill("foo", 3, 2) which are both equally odd-looking) and while we could use it inside our #in_size method it would not make things easier...

...good). But in doing so, it will disconnect the existing connection. Now consider this: Foo.transaction do Foo.create! with_other_database do raise 'Oops' if Bar.count > 9000 end end

...of each line is the connection ID): 1 Connect 1 BEGIN 1 INSERT INTO foos 1 Quit 2 Connect 2 SELECT COUNT(*) FROM bars 2 Quit That's it. Unfortunately...

makandra dev

Sometimes your code has long lines: describe 'foo' do describe 'bar' do really_long_line_really_long_line_really_long_line another_line When you're working with multiple editor...

...panes, such code will often be wider than the pane area: describe 'foo' do | describe 'bar' do | really_long_line_really_long_| another_line | To help with this you can...

...own piece of code before the actual scenario is run which looks like that: @foo Scenario: Do something ... and you place the following snippet into support/env.rb: Before('@foo') do

...This is run every time a @foo tagged scenario is hit" end You can tag RSpec examples like this: it 'does something', :foo => true do ... end What you need is...

makandra dev

...allow the user to pass in arrays as well as scalar values, since Array("foo") == ["foo"] Array(["foo", "bar"]) == ["foo", "bar"] But Array() actually calls to_a on its arguments...

...which may not always do what you expect. For example Array("foo \n bar") == ["foo \n", "bar...

To find a version containing the regular expression foo in the history of any branch: git grep foo $(git rev-list --all) You may also limit the search to a...

...file extension, e.g. Ruby files (.rb) like this: git grep foo $(git rev-list --all) -- *.rb

makandra dev
curl.haxx.se

...b will read cookies from a given file Example The remote server sets a "foo" cookie to value "bar". We tell curl to store them to a file at /tmp/cookies...

...file was generated by libcurl! Edit at your own risk. httpbin.org FALSE / FALSE 0 foo bar To send cookies to a server, use the -b switch. This URL will render...

Given those modules: module A def foo; end def bar; end end module B end When you want to call methods from A inside B you would normally just include...

...cleaner way would be like this: module B module Outside include ::A module_function :foo end end This allows you to use B::Outside.foo or just define a method inside...

Decode Quoted Printable Decoding such strings is actually quite simple using plain Ruby: "foo=3Dbar".unpack('M')[0] # => "foo=bar" Note that unpack will return an array. Our result...

...Quoted Printable If you ever need to encode that manually, pack your input similarly: ["foo=bar"].pack('M') # => "foo=3Dbar\n" Note the extra line break, and that you need...

...Imagine you have the following content in your log file. # content for log/test.log test foo bar test foo bar baz bla Now if you would like to grep for lines...

...that contain foo but not bar, you can use the following command chain: $ tail -f log/test.log | grep --line-buffered "foo" | grep -v "bar" Output:

makandra dev

...cannot be changed or passed around, but is determined syntactically. $string = "hello world" class Foo def $string.baz # define a singleton method on $string / an instance method on $string's singleton...

def bar; end end end Foo.instance_methods(false) # => ["bar"] $string.methods(false) # => ["baz"] define_method A method defined in Module Defines an instance method on the receiver; implicit receiver is...

...parse XML-documents, I recommend the gem nokogiri. A few hints: xml = Nokogiri::XML(" foo bar ") parses an xml string. You can also call Nokogiri::HTML to be more liberal...

...be triggered by a leading . or / xml % 'item' returns the first matching node node.attribute('foo') returns the attribute named foo node.attribute('foo').value returns its value node.content returns the content...

...s say you want to merge the properties of two JavaScript objects: let a = { foo: 1, bar: 2 } let b = { bar: 3, baz: 4 } let merged = merge(a, b) // => { foo...

...from a controller, it won't work by default. Take this controller action: class FoosController < ApplicationController def download file = Tempfile.new('foo') file.puts 'foo' file.close send_file file.path end end

...is to save the tempfile in your project directory's tmp instead: file = Tempfile.new('foo', 'tmp') Note that depending on your setup, you might need to change that file's...

Since Ruby 2.1, defining a method returns its name as a Symbol: def foo() end # => :foo define_method :foo do end # => :foo You can use this to do Python-like...

...decorators like so: private def foo; end memoize def foo; end

makandra dev
dev.mensfeld.pl

...Enumerable#grep_v excludes from the result set. It's similar to Rails' #reject: ['foo', 1, 'bar', {}].grep String # => ['foo', 'bar'] ['foo', 1, 'bar', {}].grep_v String # => [1, {}]

...hash representation. In older Rubies you need OpenStruct#marshal_dump instead. Ruby 2.0+ >> OpenStruct.new(foo: 23, bar: 42).to_h => { :foo => 23, :bar => 42 } Ruby 1.9.3 and 1.8.7 >> OpenStruct.new(:foo...

...bar => 42).marshal_dump => { :foo => 23, :bar => 42 } Both approaches will return the underlying hash table (a clone of it in Ruby...

...type a command in your bash that doesn't exist you get this: bash: foo: command not found or if you have installed the command-not-found package on ubuntu/debian...

...The program 'foo' can be found in the following packages: * foobar * barfoo Try: sudo apt-get install -bash: foo: command not found But you can customize this with the command...

EOF } do_monitoring The resulting eMail looks like this: Hey, this is foo.example.com calling. I just sent two ICMP packets to 1.2.3.4 and that failed apparently.

...a traceroute to 1.2.3.4: HOST: foo.example.com Loss% Snt Last Avg Best Wrst StDev...

When you need to bulk rename files you can not call "mv *.foo *.bar" to change the extension of all .foo files to bar (because bash resolves wildcards and replaces...

...linuxes who use the Perl version of the rename command (like Ubuntu): rename 's/\.foo$/\.bar/' * You can also use this to rename other parts of the file, e.g. from...