...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...
...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...
...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...
...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...
...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...
...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...
...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...
...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
...like seconds, minutes, etc. Example usage >> new Duration(42).humanized() => '42 Sekunden' >> new Duration(123456).humanized() => '1 Tag' >> new Duration(123456).humanized('es') => '1 día' Code Here is the code...
...this.years = this.days / 365 } humanized(locale = 'de') { const humanizer = new Duration.Humanizer(locale) if (this.minutes < 1) { return humanizer.humanize(this.seconds, 'second') } else if (this.hours < 1) { return humanizer.humanize(this.minutes, 'minute') } else if (this.days < 1...
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...
...eager_load or includes queries. Thus, as a general guideline.includes or .eager_load with 1-n associations are dangerous. We recommend to mainly use .preload instead. ActiveRecord::Relation#joins
SELECT "users".* FROM "users" SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1) Accessing each user's posts will not produce extra queries. If all you want is...
...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...
...nslookup will be sufficient. host simple DNS lookup utility. >host heise.de heise.de has address 193.99.144.80 heise.de has IPv6 address 2a02:2e0:3fe:1001:302:: heise.de mail is handled by 10...
...domain name servers. Nslookup has two modes: interactive and non-interactive. >nslookup heise.de Server: 146.254.160.30 Address: 146.254.160.30#53 Non-authoritative answer: Name: heise.de Address: 193.99.144.80 Name: heise.de
...been included for download at the end. This card is roughly structured as follows: 1. Research approach 2. Background 3. Implementation 3.1 Usage 3.xx Implementation details 4. Evaluation
...complete project for all modified files. T1 T2 T3 T4 T5 T6 F1 0 10 5 0 2 0 F2 1 6 0 4 0 0 F3 0
...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.
To do this, start your rails server using something like DISABLE_SPRING=1 strace -e trace=file -f bin/rails s The -e trace=file hides all non-file...
...calls, for example: Video Load (0.0ms) SELECT "images".* FROM "images" WHERE "image"."id" = $1 LIMIT $2 [["id", 975], ["LIMIT", 1]] [pid 264211] stat("/etc/localtime", {st_mode=S_IFREG...
...callbacks later Typical use cases for async Animations Network calls Delays (show tooltip after 100 ms, then animate) When you wait for I/O most of the time (web servers, crawlers...
...Each then() callback gets the settlement value of the previous callback: promise = Promise.resolve(1) promise = promise.then(x) { // x is now 1 return 2 } promise = promise.then(y) {
...Overwrite/add nested key value Select only specific keys Command jq '.[] | { Name, OriginString }' Input [ { "Id": 1, "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net" }, { "Id": 2, "Name": "barfoo.baz", "OriginString": "/FOOBAR/barfoo.baz" } ] Output { "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net...
...OriginString": "/FOOBAR/barfoo.baz" } Modify keys Command jq '.[] | { Name, OriginString, Number: .Id, Static: "Foobar" }' Input [ { "Id": 1, "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net" }, { "Id": 2, "Name": "barfoo.baz", "OriginString": "/FOOBAR/barfoo.baz" } ] Output { "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net...
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...
...array as a value in #where. ActiveRecord will make an IN() query: Card.where(id: [1,2,3]).to_sql # => SELECT * FROM cards WHERE id IN (1, 2, 3)
...FROM cards WHERE id > 5 Chaining multiple #where will AND the conditions: Card.where(id: [1,2,3]).where(title: 'Foo').to_sql # => SELECT * FROM cards WHERE id IN (1...
...hash_including 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...
...id: 1, thread: {id: 1} ) ) end end The example will fail and returns a not very helpful error message: expected {:id => 1, :name => "Foo", :thread => {:id => 1, :title => "Bar"}} to...
...efficient way to do it. Let's say I need this HTML structure: item 1 item 2 This card compares various approaches to fabricating DOM elements for testing. Constructing individual...
...let list = document.createElement('ul') list.type = 'square' jasmine.fixtures.appendChild(ul) let item1 = document.createElement('li') item1.innerText = 'item 1' list.appendChild(item1) let item2 = document.createElement('li') list.appendChild(item2) For a reader it is hard to...