docs.ruby-lang.org

We already know that that we can create strings using the percent notation: %(<foo="bar's ton">) is perfectly fine Ruby. Modifier But there is more. The curly brackets...

...w Array of Strings %r Regular Expression %x Backtick (capture subshell result)* Examples: %i[foo bar] => [:foo, :bar] %q[foo bar] => "foo bar" Interpolation To interpolate a dynamic value, swap...

...function is provided by PostgreSQL and supports Google-like query grammar: Query Result Message.search('foo bar') Both foo and bar must match somewhere Message.search('foo OR bar')

...bar must match somewhere Message.search('"foo bar"') The phrase foo bar must match in that exact order Message.search('foo -bar') foo must match, but bar must not Searching in multiple...

Jasmine specs for the frontend often need some DOM elements to work with. Because creating them is such a common...

keepachangelog.com

This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased - Added `Foo#foo` method. ## 1.0.0 - 2017-06-20 ### Breaking changes - Renamed `Foo` to `Bar` - Removed `Baz#method...

...Please use `Qax#method` instead. ### Compatible changes - Added new `Bam#foo` method. ## 0.9.0 - 2017-05-20 ### Compatible changes - Improved performance of `Bam...

...record.errors[:email]).to include("can't be blank") # check for presence of error record.email = 'foo@bar.com' # valid state record.validate expect(record.errors[:email]).to_not include("can't be blank") # check for...

...is_expected.to allow_values('EUR', 'USD', 'GBP', 'CHF').for(:currency) } it { is_expected.not_to allow_values('foo', '€', '', nil).for(:currency) } it 'defaults to EUR' do expect(subject.currency).to eq('EUR') end

...constructs your Address instance: # without :mapping Rails uses keyword arguments Address.new(street_and_number: 'Foo St. 1', zip_code: '12345', city: 'Bar Town') # with a :mapping (even if that is...

...the "identity mapping" that keeps all names the same) Rails uses positional arguments Address.new('Foo St. 1', nil, '12345', 'Bar Town') Did you notice the nil in there? That's...

...hash, but the keys can also be accessed like methods h = ActiveSupport::OrderedOptions.new h['foo'] = 'bar' h.foo = 'bar' # same thing h['foo'] # => 'bar' h.foo # => 'bar' in? (> 3.0 only)

Array.wrap(nil) # => [] Array.wrap([1,2,3]) # => [1,2,3] Array.wrap(1) # => [1] Array.wrap("foo \n bar") # => ["foo \n bar"] Class.class_attributes (> 3.0 only) inheritable class attributes. Subclasses inherit from...

...allow you to indent code like you normally do in HTML mails. ❌ DON'T <%= 'foo' if bar %> "\n" if bar is false "foo\n" if bar is true <%= nil %>

<%= 'foo' %> <% end %> " foo" <%= 'foo' %> <%= 'bar' %> "foo\n\nbar\n" ✔️ DO Write unindented code to get the expected result. <% if bar %> <%= 'bar' %> <% end %> <%= 'foo' %> <%= 'bar' %> Use Form Models to...

...to read and is also suggested by Rubocop's Style/GlobalVars cop. Example before: if 'foo' =~ /foo/ puts $~[1] # => foo end Example after: if 'foo' =~ /foo/ puts $LAST_MATCH_INFO...

end Require pitfall in Rails The English library is not loaded by default in Rails. So you or another library needs to require it. The chances are very high...

...hostname for different apps, and you will stay logged in in each app: http://foo-app.daho.im:3000 => 127.0.0.1 http://bar-app.daho.im:3000 => 127.0.0.1 http://bam-app.daho.im:3000 => 127.0.0.1 Caution It's safe to use daho.im since...

...in your .bashrc: alias dahoim='echo "http://$(basename $PWD).daho.im:3000"' From a project directory (e.g. foo-app) this command will print the link to console that you can click on...

makandra Curriculum

...as. It should compare the attributes of two ActiveRecord instances: movie1 = create(:movie, title: 'Foo', year: 2007, description: 'Lorem ipsum') movie2 = create(:movie, title: 'Foo', year: 2007, description: 'Lorem ipsum...

...your arrays a #to_sentence method that may help you build the error message: ['foo', 'bar', 'baz'].to_sentence => "foo, bar and baz" Also see Where to put custom matchers...

...to have the branch deleted: $ git merge ds/foo Updating 338e82e38..2d4269c81 Fast-forward foo | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo > You have just...

...allowing matchers to call other matchers. Example The following test checks that two variables foo and bar (1) have no lowercase characters and (2) end with an exclamation mark:

...foo).to_not match(/[a-z]/) expect(foo).to end_with('!') expect(bar).to_not match(/[a-z]/) expect(bar).to end_with('!') We can extract the repeated matcher chains...

moncefbelyamani.com

...uses SELECT 1 AS one FROM...

...LIMIT 1 under the hood. In short: Replace foo.count > 0 with foo.any? or foo.count == 0 with foo.none? If you require quick counts and can...

...very liberal equality rules (more like === instead of ==). For example: expect(subject).to receive(:foo).with(MyClass) subject.foo(MyClass) # satisfies the expectation subject.foo(MyClass.new) # also satisfies the expectation expect(subject...

...If you want to expect strict equality, you could use expect(subject).to receive(:foo).with(eq(MyClass)) or expect(subject).to receive(:foo) do |klass| expect(klass).to eq...

makandra dev

...work with properties. Read and write properties (!) // jQuery let value = $input.prop('value') $element.prop('value', 'foo@bar.com') // Native let name = input.name input.name = 'foo@bar.com' // jQuery let src = $image.prop('src') $element.prop('src', 'foo.png')

...let src = image.src input.src = 'foo@.png' Working with CSS class names // jQuery $input.hasClass('active') $input.addClass('active') $input.removeClass('active') $input.toggleClass('active') // Native input.classList.contains('active') input.classList.add('active') input.classList.remove('active') input.classList.toggle('active')

makandra Curriculum

...offer an API like this: contact = Contact.new(first_name: 'Anna', last_name: 'Muster', street: 'Foo Avenue 77') contact.first_name # => 'Anna' contact.last_name # => 'Muster' A Contact object should be able to...

...list of contacts in memory: addresses = AddressBook.new addresses.add Contact.new(first_name: 'Frederik', last_name: 'Foo') addresses.add Contact.new(first_name: 'Berta', last_name: 'Beispiel', phone: '556677') addresses.add Contact.new(first_name: 'Anna...

...snake_case) that is also exposed to the JavaScript world (camelCase). # This query matches "foobar", "foo-bar" and "foo_bar" # The query is case insensitive be default. foo.?bar

...way they were added to singleton class. Consider the following code: module A def foo puts "Foo!!" end end module B def self.included(base) base.extend(ClassMethods) end module ClassMethods

puts "Foo!" super end end end class User singleton_class.include(A) include B end User.instance_eval do def foo puts 'Foo' super end end User.foo # => "Foo Foo! Foo!!" User.singleton_class.ancestors # => [# , B...

...of its compressed output. Let's take this function: function fn() { if (a) { return 'foo' } else if (b) { return 'foo' } else { return c() } } console.log(fn()) Terser will reduce this to...

...the following code: console.log(a||b?"foo":c()) Note how: The if statement has been replaced by a tertiary expression. This is often less readable, but it doesn't matter...

regular-expressions.info

...around will not be part of the match. Positive lookahead: /foo(?=bar)/ matches the foo in the foo and the bar but not in this food is bad Negative lookahead...

...lookbehind: /(?<=ma)kandra/ matches the kandra in makandra but not in kandra Negative lookbehind: /(?<!foo)bar/ matches the bar in moo bar but not in foobar Modifiers in Ruby

...standard ruby character classes like \w, \d will only match 7-Bit ASCII characters: "foo" =~ /\w+/ # matches "foo" "füü" =~ /\w+/ # matches "f", ü is not 7-Bit ASCII

...you-type box to filter the list by query: +-----------------------------------------+ | MOVIEDB | +--------------------+--------------------+ | | | | MOVIES | MOVIES | | [ Search… ] | [ Search… ] | | | | | - Foo movie | - Foo movie | | - Bar movie | - Bar movie | | - Baz movie | - Baz movie | | | | +--------------------+--------------------+ The search box above...

...never affect the other pane. So this state should be possible: +-----------------------------------------+ | MOVIEDB | +--------------------+--------------------+ | | | | MOVIES | MOVIES | | [ Foo ] | [ Ba ] | | | | | - Foo movie | - Bar movie | | | - Baz movie | | | | | | | +--------------------+--------------------+ Did your existing JavaScript already behave that way...

...argument matcher with a nested hash: describe 'user' do let(:user) { {id: 1, name: 'Foo', thread: {id: 1, title: 'Bar'} } it do expect(user).to match( hash_including(

...will fail and returns a not very helpful error message: expected {:id => 1, :name => "Foo", :thread => {:id => 1, :title => "Bar"}} to include hash_including(:id => 1, :thread => {:id => 1})