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:
...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
...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...
# /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...
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...
...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...
...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...
@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...