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

blog.bigbinary.com

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

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

github.com

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

makandra dev

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

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

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

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

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

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

ruby-lang.org

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

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

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

...mentioned below for your deployment on request. If you're lucky DO_NOT_TRACK=1 opts you out of CLI telemetry - it's not widely adopted. When you're using...

...yarn config set --home enableTelemetry 0 Next.js https://nextjs.org/telemetry export NEXT_TELEMETRY_DISABLED=1 Prisma https://www.prisma.io/docs/orm/tools/prisma-cli#telemetry export CHECKPOINT_DISABLE=1 Angular https://angular.io/cli/analytics Note: The default...

...to 4 reduced test failures by 80% while only increasing test runtime by 10%: CPUs Test runtime Test runtime (%) Failures Failures (%) 8 308 100% 14 100% 8 304 99%

6 43% 4 343 111% 1 7% 4 346 112% 6 43% 4 333 108% 2 14% 4 340 110% 3 21% 3 378 123% 2

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

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

...in strings will be sorted character by character which you probably don't want: ["1", "2", "11"].sort # => ["1", "11", "2"] # you probably expected ["1", "2", "11"] Also the sorting...

You can now say: ["Schwertner", "Schöler"].sort_by(&:to_sort_atoms) #=> ["Schöler", "Schwertner"] ["1", "2", "11"].sort_by(&:to_sort_atoms) # => ["1", "2", "11"] ["a", "B"].sort_by(&:to...

...be formatted using the user's language settings. For example, German users will see 1,23 for . Values in the JavaScript API or when submitting forms to the server will...

...always use a point as decimal separator (i.e. "1.23" even when the browser displays 1,23). You don't need any "conversion" hacks which try to replace commas with dots...

...priority queue if many image records and versions are affected. References sRGB v4 ISO 15076-1 The International Color Consortium, stating: The v4 ICC specification is widely used and is...

...and other de-facto standards. It was first approved as an International Standard, ISO 15076-1, in 2005 and revised in...

...through looking at the stash: $ git stash list stash@{0}: WIP on feature/foo stash@{1}: WIP on feature/bar stash@{2}: WIP on fix/baz Now you can simply use that reference...

...but curly braces must be escaped: git stash pop stash@\{1\} or quoted: git stash apply "stash@{1}" Quick reminder to not shoot yourself in the foot: apply applies the...