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...

...do it like this: page.within_frame('iframe-id') do fill_in 'E-mail', with: 'foo@bar.com' fill_in 'Password', with: 'secret' click_button 'Submit' end Instead of the frame's [id...

...can use your existing steps like this: When I fill in "E-mail" with "foo@bar.com" inside the login frame Note: Spreewald >= 4.1.0 already includes that step

...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...

...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.

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...

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

...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...

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...

...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...

...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...

# /home/user/foo.sh echo "$(hostname -f): $(uptime)" echo "${USER}" echo "${SERVERLIST}" | bolt command run @foo.sh --run-as root --targets - Use script run to run a ruby script: #!/usr/bin/env ruby # /home/user/bar.rb...

...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...