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

...into errors like this: I18n::InvalidPluralizationData: translation data {...

...} can not be used with :count => 1. key 'one' is missing. They seem to appear out of the blue and the error...

...the user attribute, but the user model! Now it invokes the translation with count: 1. I18n tries to pluralize the derived key (i.e. the user model, and fails. Instead of...

...for all environments by adjusting your config/database.yml: default: &default adapter: postgresql # ... variables: statement_timeout: 10s # or ms, min, etc Test that it works: ActiveRecord::Base.connection.execute("show statement_timeout;").map { |row...

=> [{"statement_timeout"=>"10s"}] begin ActiveRecord::Base.connection.execute("SELECT pg_sleep(15)") rescue ActiveRecord::QueryCanceled => e Rails.logger.error("Query was canceled: #{e.message}") end Adjust or disable the timeout for a single transaction...

makandra dev

...code, we use ESLint. The workflow is similar to integrating rubocop for Ruby code. 1. Adding the gem to an existing code base You can add the following lines to...

...varsIgnorePattern': '^_', 'argsIgnorePattern': '^_', 'caughtErrorsIgnorePattern': '^_', }], '@stylistic/arrow-spacing': ['error', { before: true, after: true }], '@stylistic/block-spacing': ['error', 'always'], '@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }], '@stylistic/comma-dangle': ['error', { 'arrays': 'always-multiline', 'objects': 'always-multiline', 'imports': 'always-multiline', 'exports': 'always...

sgruendel.blogspot.com

When you install Type 1 fonts (like makandra's corporate typeface), they won't show up in OpenOffice. OpenOffice requires some additional files to process them. Stefan Gründel found out...

Using .includes or .eager_load with 1-n associations is dangerous. Always use .preload instead. Consider the following ActiveRecord query: BlogPost.eager_load( :comments :attachments, ).to_a

...post_id" = "blog_posts"."id"; Now assume there is a single blog post with 100 comments and 10 attachments. The OUTER JOINs will cause the query to return 1000 database...

y: number; } function printPoint(p: Point2D) { console.log(`(${p.x}, ${p.y})`); } const point3D = { x: 1, y: 2, z: 3 }; // has extra property z printPoint(point3D); // [LOG]: "(1, 2)" TypeScript Code...

TypeScript will actually help me catch bugs due to its static typing: printPoint({ x: 1 }); // Error: Property 'y' is missing printPoint({ x: 1, yy: 2 }); // Error: Object literal may only...

// Equivalent if/else function numberOrOne(n: number | undefined): number { if (n === undefined) return 1; else return n; } // Terse || function numberOrOne(n: number | undefined): number { return n || 1; }

...even when they are valid values. function numberOrOne(n: number | undefined): number { return n || 1; } numberOrOne(3); // 3 numberOrOne(0); // 1, but should be 0! The same trap applies to...

...the content type of a file attachment. Normally we would not expect content_type_1 to be a valid content type with the used regular expression image\/(jpeg|png). But...

...as ^ and $ will match lines, it matches both content_type_1 and content_type_2. Using \A and \z will work as expected instead and excludes content_type_1.

...PLAN ------------------------------------------------------------------------------------------------------------------------------- Seq Scan on users (cost=0.00..332518.66 rows=343223 width=422) (actual time=143.706..61621.403 rows=213865 loops=1) Filter: (search_text ~~* '%max%'::text) Rows Removed by Filter...

...true, Deforming true Timing: Generation 5.688 ms, Inlining 0.000 ms, Optimization 8.882 ms, Emission 132.362 ms, Total 146.931 ms Execution Time: 61856.303 ms (9 rows) With a GIN index

...Here is an example where this diff is helpful while comparing two hashes: {a:1}.should match(a:1, b:2) Failure/Error: {a:1}.should match(a:1, b...

...expected {:a=>1} to match {:a=>1, :b=>2} Diff: @@ -1,3 +1,2 @@ :a => 1, -:b => 2, Unfortunately, this diff is not as clever as it would need to...

...may cause the relation to select more records than expected: authorized_users = User.where(id: [1, 2]) filtered_users = User.where(id: [2, 3]) authorized_users.merge(filtered_users).to_sql # => SELECT * FROM users...

...merged relation select the users (2, 3), although we are only allowed to see (1, 2). The merged result should be (2). This card explores various workarounds to combine two...