...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
...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...
...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...
...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...
...do ES6 classes translate to prototypes and vice versa? We will spend the first 10 minutes to cover some JavaScript basics and then dive deep into details. Level 1: Objects...
height: 20, computeArea: function() { return this.width * this.height } } shape.width // => 30 shape.height // => 20 shape.height = 100 Note how "methods" are just properties with a function value: shape.computeArea // => function() { return this.width * this.height...
def splat_kwargs(**kwargs) # ... end def no_kwargs(*args) # ... end explicit_kwargs(x: 1, y: 2) # works explicit_kwargs({x: 1, y: 2}) # raises an ArgumentError explicit_kwargs(**{x...
...1, y: 2}) # works splat_kwargs(x: 1, y: 2) # works splat_kwargs({x: 1, y: 2}) # raises an ArgumentError splat_kwargs(**{x: 1, y: 2}) # works
...you just need to know "are there any records" use any?. This uses SELECT 1 AS one FROM...
...LIMIT 1 under the hood. If you just need to know "are...
...there no records" use empty? or none?. This 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...
...easily loose track of the desired example. Nesting index syntax looks like this: spec/models/user_spec.rb[1:2:1]. It describes a path in the nesting tree of the spec file, with...
...1-based indexes. Example # spec/models/user_spec.rb describe User do it 'validates presence of its email address' describe '#full_name' do it 'combines first and last name' it 'does not crash if...
...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...
...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
...execution failed: #{stderr}" unless status.success? if (match = pdf_info.match(/^Pages:\s*(\d+)/)) page_count = match[1].to_i blob.update!(metadata: blob.metadata.merge(page_count:)) end end blob.metadata[:page_count] end end
...execution failed: #{stderr}" unless status.success? if (match = pdf_info.match(/^Pages:\s*(\d+)/)) { page_count: match[1].to_i } else {} end end rescue StandardError => e Rails.logger.error("PdfAnalyzer failed to parse metadata: #{e.message...
...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...
1. Saving files to a directory that is not shared between deploys or servers If you save your uploads to a made up directory like "RAILS_ROOT/uploads", this directory goes...
...one path like "public/system/images/4.jpg" and then replacing the record ID (4) with values from 1 to 9999999999. So don't store confidential stuff in there. Non-public files should by...
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...
...all tables (schema public) from every database. Replication For updates method names in postgres 10 look in the wiki. Current xlog position on the master: SELECT pg_current_xlog_location...
SELECT pg_current_wal_lsn(); -- repeat command every second on psql \watch 1 Received xlog position on the slave: SELECT pg_last_xlog_receive_location(); -- postgres 10
Tested on Ubunut 22.04 1. Opener script Create a file ~/.local/bin/coverage_zip_opener with: #!/bin/bash tmp_folder="/tmp/coverage-report-opener" if [ -z "$1" ] then echo "Usage: coverage_zip_opener [filename]" exit -1 fi
...1" =~ ^.*Pipeline.*Coverage.*\.zip$ || "$1" =~ ^.*merged_coverage_report.*\.zip$ ]]; then file-roller "$1" exit 0 fi rm -Rf $tmp_folder unzip -qq "$1" -d $tmp_folder index_filename=$(find /tmp/coverage-report-opener...
...an easy task, but on the other hand we now have context limits of ~1 million token, which allows us to just dump in everything we have in many cases...
Use Cases pack_repo_context Packs the entire repo (with some exclusions!) into 1-5 XML files. Can be used for all kind of tasks from "How does this...
...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) {
...Example/-Group is the combination of the filename and the nested index (starting from 1) in brackets. To run the shared example from above you could execute: rspec spec/models/my_model_spec.rb[1...
Note that if an example from a shared example group fails, RSpec will print out the file name with that ID. You just need to paste it to your...
...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...
...vacation.period.class # Range # ActiveRecord can cast as well vacation = Vacation.create(period: 2.weeks.ago..1.day.ago) Note In Ruby 1...10 excludes 10 and 1..10 includes 10. Ruby also supports 1.. and...
...1 as endless ranges. Syntax [,]::daterange or (,)::daterange // contains all days [2025-12-12, 2026-12-12)::daterange // 12.12.2025 until but not including 12.12.2026...
typeof x === 'string' || x instanceof String // => true Numbers Numbers can exist as literal (123) and as an object (new Number(123)), hence we cannot rely on typeof:
typeof new Number(123) // => "object" Your test should check both forms: x = 123 typeof x === 'number' || x instanceof Number // => true Functions x = function() {} typeof x === 'function' // => true
Starting with Ruby 1.9, most #each methods can be called without a block, and will return an enumerator. This is what allows you to do things like ['foo', 'bar', 'baz...
Now you can either do my_collection.each { |item| do_something_with(item) } or my_collection.each.take(100) # returns first 100 items, items 101+ will never be fetched. Example I have used this...
Define a class and create objects: UserPreview = Struct.new(:gid, :email, :name) u = UserPreview.new(1, 'hans@peter.de', 'Hans Peter') => #<struct UserPreview gid=1, email="hans@peter.de", name="Hans Peter"> access attributes:
u.name => "Hans Peter" u['name'] => "Hans Peter" u[:name] => "Hans Peter" u[2] => "Hans Peter" u.to_a => [1, "hans@peter.de", "Hans Peter"] u.to_h => {:gid=>1, :email=>"hans@peter.de", :name=>"Hans...