github.com

...using the json gem, you might run into this error when using JSON.parse: >> json = 'foo'.to_json >> JSON.parse(json) JSON::ParserError: 757: unexpected token at '"foo"' from /.../gems/json-1.7.7/lib/json/common.rb:155:in...

...fix that, use a valid object to build JSON from, e.g. an array: >> JSON.parse([ 'foo' ].to_json).first => "foo" When you do that, remember to select the record from the...

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

Consider this class: class Foo private def test puts "Hello" end end While you can say create a block to call that method (using ampersand and colon) on Ruby...

...Foo.new.tap(&:test) Hello => # ... you cannot do that on Ruby 1.9 or 2.0: 1.9.3 > Foo.new.tap(&:test) NoMethodError: private method `test' called for # ^ 2.0.0 > Foo.new.tap(&:test) NoMethodError: private method `test' called for...

apidock.com

...virtual attributes that get and set a string array: post = Post.last puts post.tag_list # ['foo', 'bar', 'baz'] post.tag_list = ['bam'] puts post.tag_list # ['bam'] If you would like to create...

- form_for @post do |form| = form.check_box :tag_list, { :multiple => true }, 'foo', nil = form.check_box :tag_list, { :multiple => true }, 'bar', nil = form.check_box :tag_list, { :multiple => true...

With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new user.foo # => :bar RSpec 2 (Rails 3) RSpec 2 comes with this feature...

User.any_instance.stub(:foo => :bar) user = User.new user.foo # => :bar RSpec 3 RSpec Mocks 3.3: any_instance allow_any_instance_of(User).to receive(:foo).and_return(:bar) user = User.new

\di Create user that can create databases CREATE USER harry IDENTIFIED BY 'foo'; CREATE ROLE username WITH createdb LOGIN [PASSWORD 'password']; Change password of an existing user ...

w3.org

You probably commonly used the :last-child CSS meta selector like so: .foo { border-bottom: 1px dashed #000; } .foo:last-child { border-bottom-width: 0; } However, this only...

...Instead, prefer using the + sibling selector. It applies to the element following the other. .foo + .foo { border-top: 1px dashed #000; } Note how we now use a top border instead...

makandra dev

...branch means switching branches. Example git checkout HEAD~2 app/models/foo.rb … drops all modifications of foo.rb and replaces the file with its version from HEAD~2 = two commits before the current...

...Ruby objects you may run into problems when encountering fields with NULL values: SELECT foo, bar, foo - bar AS baz FROM plop; +-----+------+------+ | foo | bar | baz | +-----+------+------+ | 30 | 20 | 10 |

...selected value if present and a given alternative if it would select NULL: SELECT foo, bar, foo - IFNULL(bar, 0) AS baz FROM plop; +-----+------+-----+ | foo | bar | baz...

`role_list_from': unknown role `something' (ArgumentError) Consider this task definition: namespace :foo do task :bar, :roles => :something do # do crazy stuff end end Whenever we call foo.bar...

...that is only available for that group of servers, you'll get another error: `foo.bar' is only run for servers matching {:roles=>:something}, but no servers matched To properly fix...

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

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

...set the path=/ option. Reading cookies A result may look like this: hello=universe; foo=bar This means that there are 2 cookies: "hello" with value "universe", and "foo" with...

...cookie that we just stored, and any cookies that existed previously. document.cookie // => "hello=universe; foo=bar; yes=please" That applies to all browsers. Options Cookie options like expiry or the...

- __meta_kubernetes_namespace target_label: Namespace ### NEW drop RULE ### - action: drop regex: ".*foo.*" source_labels: - __meta_kubernetes_namespace The drop will never occur, because meta_kubernetes_namespace will...

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

# something like has_defaults would be nicer, but fails with e.g. User.new :password => 'foo' self.salt ||= ActiveSupport::SecureRandom.hex(20) if new_record? # this double-hashing technique is explained in...

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

...considers text that is actually visible to a user. Then I should not see "foobear" This is because the Rack::Test driver does not know if an element is visible...

Spreewald offers steps to check that an element is hidden by CSS: Then "foo" should be hidden You can also check that an element is visible: Then "foo" should...