themomorohoax.com

A global h2 style probably isn’t going to last more than a month before everyone starts changing it inline...

...than it should, this expression requires 4 attempts to match the string: Attempt Group $1 Group $2 Expression result 1 "aaabbb" not matched not matched 2 "aaabb" not matched

...bbb)/ only requires a single attempt to match "aaabbb": "aaabbb" =~ /^(a+)(bbb)/ Attempt Group $1 Group $2 Expression result 1 "aaa" "bbb" matched! Because greedy quantifiers start backtracking when an...

docs.ruby-lang.org

...the method (and not out of the first block or something similar). def test [1, 2, 3].each do |counter| example { return counter } end return 'test' end test # => 1

...when we look at what was said above about the expected return value): # bad [1, 2, 3].each { |counter| break counter if counter.even? } # => 2 [1, 3].each { |counter| break counter...

In RubyMine you can use find and replace with capture groups (.*?) and backreferences $1 (if you have several groups: $[Capture-Group ID]). Named captures (? .*) are also supported. Examples

...expression captures whatever is contained by two double quotes. Fill in replace field with '$1'. The $1 references what was captured. RubyMine shows you a preview of the result, so...

...opening a form, JavaScript makes a request to acquire a lock for that record (1). After 20 seconds the JavaScript starts polling the server (2), to check if another user...

When the PC was low on resources (parallel_tests), acquiring the lock (1) took so long that the client starts polling for updates (2) before the initial lock...

@email = email @newsletter = newsletter end end User.new( 'Mr.', 'John', 'Doe', 'Potsdamer Platz 1', '10117', 'Berlin', '+49 0151 1122334455', 'john.doe@example.com', true ) Using keyword arguments Using keyword arguments is easier...

salutation: 'Mr.', first_name: 'John', last_name: 'Doe', street_and_number: 'Potsdamer Platz 1', zip_code: '10117', city: 'Berlin', phone_number: '+49 0151 1122334455', email: 'john.doe@example.com', newsletter: true )

...column_value(value) method in active record is traced (simplified output): git log -n 1 --pretty=oneline -G 'convert_number_column_value(value)' -- activerecord/lib/active_record/base.rb ceb33f84933639d3b61aac62e5e71fd087ab65ed Split out most of the...

...activerecord/lib/active_record/base.rb - def convert_number_column_value(value) - if value == false - 0 - elsif value == true - 1 - elsif value.is_a?(String) && value.blank? - nil - else - value - end - end activerecord/lib/active_record/attribute_methods/write.rb + def convert_number_column...

...options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--disable-infobars') options.add_emulation(device_metrics: { width: 1280, height: 960, touch: false }) unless ENV.key?('NO_HEADLESS') options.add_argument('--headless') options.add_argument('--disable-gpu...

...app, browser: :chrome, options: options) end Selenium::WebDriver.logger.level = :error Headless Chrome in legacy Capybara 1 projects If you're working on a legacy project with Capybara version 1.x, the...

guides.rubyonrails.org

...database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users`  WHERE `users`.`id` = 1 +----+-------------+-------+-------+---------------+

...type | table | type  | possible_keys | +----+-------------+-------+-------+---------------+ |  1 | SIMPLE      | users | const | PRIMARY       | +----+-------------+-------+-------+---------------+ +---------+---------+-------+------+-------+ | key     | key_len | ref   | rows | Extra | +---------+---------+-------+------+-------+ | PRIMARY | 4       | const |    1 |       | +---------+---------+-------+------+-------+   1 row in set (0.00 sec)   EXPLAIN for: SELECT `articles...

echo "> Deleting remote branch ..." git push origin --delete $merged_branch_name exit 1 else echo "x Did not delete the \"$merged_branch_name\" branch." fi

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

...the copied invoice and the creation of its items. This list of changes (e.g. 12 INSERT statements) will be committed in a single atomic operation, or not at all. This...

...order, you might get a deadlock. For instance, transaction A wants to change row #1 and row #2. Transaction B wants to change the same rows, but in different order...

...NULL values with the + value. The sum value will be NULL. MySQL: mysql> select 1 + 2 + 3; +-----------+ | 1 + 2 + 3 | +-----------+ | 6 | +-----------+ 1 row in set (0,00 sec)

+--------------+ | 1 + NULL + 3 | +--------------+ | NULL | +--------------+ 1 row in set (0,00 sec) Postgres: test_database=# select 1 + 2 + 3; ?column? ---------- 6 (1 row) test_database=# select 1 + NULL...

...contained values. If your project uses Lodash or Underscore.js, you can use _.isEqual(): _.isEqual([1, 2], [2, 3]) // => false _.isEqual([1, 2], [1, 2]) // => true If your project already uses...

...Unpoly you may also use up.util.isEqual() in the same way: up.util.isEqual([1, 2], [2, 3]) // => false up.util.isEqual([1, 2], [1, 2]) // => true If you are writing server-side code in...

mysqlperformanceblog.com

...foo@example.com'; +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ | 1 | SIMPLE | users | const | index_users_on_email | index_users_on_email | 768 | const | 1 | | +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+

...data types. Like integers for string fields: mysql> EXPLAIN SELECT * FROM users WHERE email = 12345; +----+-------------+-------+------+----------------------+------+---------+------+--------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+----------------------+------+---------+------+--------+-------------+

...You might think that the following queries yield the same result: User.where(movie_ids: [16, 17]) User.where(movie_ids: [17, 16]) Turn's out - they are not! They do care...

...the where_array_matches method below. Note that it does not care about duplicates - [1, 2, 2] is handled identically to [1, 2]: # lib/ext/active_record/relation.rb class ActiveRecord::Relation def where_array...

...OpenGraph image Some social networks display your image with an aspect ratio of 2:1 (wide), some with (1:1), some both. Facebook supports only 1.91:1. Images that do...

...make sure relevant content is still visible when cropped. We recommend a resolution of 1200x630. Note that Facebook does not support SVG images for og:image. You should use PNG...

makandra dev

...can globally disable animations like this: up.motion.config.enabled = false Disabling animations in AngularJS In AngularJS 1.x you can globally disable animations like this: angular.module('myApp', []).run(['$animate', function($animate) { $animate.enabled...

...AJAX, I've found it helpful to limit the number of concurrent requests to 1. This will implicit serialize UI interactions that make an AJAX request. You can configure Unpoly...

makandra dev
ruby-doc.org

...for hash equality other.name == name end end bob = Person.new('bob') phone_list = { bob => '0821 123', } phone_list[bob] # returns '0821 123' phone_list[Person.new('bob')] # returns nil [bob, Person.new('bob...

[ [0] #<Person:0x0000559054263420 @name="bob">, [1] #<Person:0x000055905404ee50 @name="bob"> ] Only after implementing hash we get the expected results: class Person ... def hash name.hash end end bob = Person.new('bob...

2 application servers 6 Rails worker processes in each application server 1 background job server with Sidekiq (will spawn 10 threads by default) When your code does...

...you may use the following number of connections: (2 app servers * 6 app workers) + (1 job server * 10 sidekiq workers) = 12 + 10 = 22 connections When your code does use ActiveRecord...

makandra dev

...be using this example tree (from the acts_as_nested_set docs): root | +-- Child 1 | | | +-- Child 1.1 | | | +-- Child 1.2 | +-- Child 2 | +-- Child 2.1 | +-- Child 2.2 Option 1: Parent Association

This would serialize the example above to this table: id | parent_id | data ---+-----------+---------- 1 | NULL | root 2 | 1 | Child 1 3 | 2 | Child 1.1 4 | 2 | Child 1.2...

...Rails do the logic # Good User.where.not(id: []).to_sql => SELECT "users".* FROM "users" WHERE (1=1) User.where.not(id: [1]).to_sql => SELECT "users".* FROM "users" WHERE ("users"."id" != 1) User.where.not...

...id: [1, 2]).to_sql => SELECT "users".* FROM "users" WHERE "users"."id" NOT IN (1, 2) Rails < 4 Before Rails 4, you needed to work around this yourself: # Good excluded_ids.blank...

...Rails 5 does not halt callback chain if false is returned Legacy Rails versions (1-4) Goal Rails version Within before_* Within after_* Cancel later callbacks Rails 1-4

return false Rollback the transaction Rails 1-4 return false raise ActiveRecord::Rollback Take care that your callbacks don't accidentally return false, since that cancels the chain in...

...the net total is calculated from the gross total: gross = items.sum(&:total) vat = (gross * (1 - (1 / VAT_RATE))).round(2) net = gross - vat Don't show VAT amounts for individual...

end create_table :items do |t| t.integer :invoice_id t.decimal :unit_price, :precision => 10, :scale => 2 t.integer :quantity t.timestamps end Note how we are using a DECIMAL column rather...