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

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

makandra dev

class SomeController < ActionController::Base def old_location redirect_to(new_location_url(params.permit(:foo))) end end This will: It will redirect with a 302 status code

...ActionController::UnfilteredParameters if there is any other query param than foo, e.g. https://www.example.com/old_location?another_param=1. This is because url_for will call to_h on ActionController::Parameters, which will raise...

...was removed from the DOM } attributeChangedCallback(attribute, oldValue, newValue) { // the given attribute was changed } foo() { // a custom method } } customElements.define('my-element', MyElement) Note that this class automatically describes the JavaScript...

...the scope parameter was blank? and aborted the method execution in this case. def foo(scope) return if scope.blank? # Use scope, e.g. scope.find(...) end We then called this method with...

...an all scope: foo(Media::Document::Base.all). Be careful with this. all returns a scope (ActiveRecord::Relation) which looks and is harmless at first because nothing is loaded into memory...

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

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

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

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

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

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

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

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

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

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

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

...JSON, and then escaping all code points above 127 using unicode escape sequences: escapeHighASCII('{"foo":"xäy"}') // => '{"foo":"x\\u00e4y"}' The program that reads the header can access the original string...

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

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

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

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