...for performance measurements. I wrote a small script that runs each query to benchmark 100 times and calculates the 95th percentile. Note: The script requires sudo permissions to drop RAM...
...runner lib/scripts/benchmark.rb` require 'open3' # For debugging # Rails.logger = Logger.new(STDOUT) # ActiveRecord::Base.logger = Logger.new(STDOUT) ITERATIONS = 100 PERCENTILE = 0.95 def system!(*) stdout_str, error_str, status = Open3.capture3(*) unless status.success? puts [status, stdout...
...on production. Consider this history: %%{init: { 'gitGraph': {'showCommitLabel': true, 'mainBranchName': 'production'}} }%% gitGraph commit id: "1" commit id: "2" branch master commit id: "3" commit id: "4" branch my-feature-branch...
...and 4 from master. %%{init: { 'gitGraph': {'showCommitLabel': true, 'mainBranchName': 'production'}} }%% gitGraph commit id: "1" commit id: "2" branch master commit id: "3" commit id: "4" checkout production merge master
...each array element: users = User.all user_names_by_id = users.to_h { |user| [user.id, user.name] } { 1 => "Alice", 2 => "Bob" } Array#to_h on an array of key/value tuples (Ruby 2.1+)
users = User.all user_names_by_id = users.map { |user| [user.id, user.name] }.to_h { 1 => "Alice", 2 => "Bob" } Enumerable#index_by (any Rails version) users = User.all users_by_id = users.index...
...it to console.log. Understand why each code block behaves the way it does: Variant 1: Iterating with forEach's callback function const callbacks = []; [1, 2, 3].forEach(function(i) { callbacks.push...
...callback) => callback()) Example 2: Incrementing a variable created with var const callbacks = []; var i = 1; while (i <= 3) { callbacks.push(function() { console.log(i) }) i++ } callbacks.forEach((callback) => callback()) Variant 3: Wrapping the...
...When I erase my query, the popup disappears. - The popup contains a maximum of 10 suggestions. - When I click outside the popup, it disappears. - If I click on a suggestion...
...the issue turns out to be more complicated than anticipated. We suggest a 0,1,2,3 point scale, with the following meaning: 0 points: <= 1h 1 points: <= half a...
...Time.new will initialize with the current Time in your Timezone, DateTime.new initializes at January 1, at an undefined year, without a timezone offset. Comparing or calculating with both datastructures mixed...
...and formatting time of day objects, some of them are listed below: Tod::TimeOfDay.parse "15:30" # => 15:30:00 Tod::TimeOfDay.parse "3:30:45pm" # => 15:30:45 Tod::TimeOfDay.new...
>> tel_to '(01234) 555 6789' => (01234) 555 6789 >> tel_to '+1 555 123-456' => +1 555 123-456 If you have user-provided phone numbers, you may want...
...should not include that zero. def tel_to(text) groups = text.to_s.scan(/(?:^\+)?\d+/) if groups.size > 1 && groups[0][0] == '+' # remove leading 0 in area code if this is an international number...
...original `setTimeout()` before it is mocked by `jasmine.clock.install()`. const unmockedTimeout = window.setTimeout function wait(ms = 1) { return new Promise((resolve) => { unmockedTimeout(resolve, ms) }) } it('handles an event', async () => { triggerAnEventOn(this.form)
...bit for a certain condition to occur: async function waitFor(callback) { let msToWait = [0, 1, 5, 10, 100] // we use some exponential fall-off while (true) { let [msToWaitNow, ...msToWaitNext] = msToWait...
...browser process crashes on your users. Although this guide has been written for Angular 1 originally, most of the advice is relevant for all client-side JavaScript code.
link: (scope, element, attributes) -> updateTime = -> var now = new Date(); element.text(now.toString()) setInterval updateTime, 1000 The version below clears the interval and doesn't leak memory: @app.directive 'clock', -> link: (scope...
...Ruby: Get started with the greatest programming language made for humans. Note that chapters 16 (RDoc), 23 (Multi Threading) and everything after chapter 27 is irrelevant for now References
...lines and paragraphs, and outputs the result. For example: $ ruby count_words.rb test.txt test.txt has 123 words test.txt has 13 lines test.txt has 4 paragraphs Hint Find out about ARGV.
Run the test to see it fail bundle exec rspec F Failures: 1) File "/entrypoint.sh" is expected to exist Failure/Error: it { should exist} expected File "/entrypoint.sh" to exist...
.../spec/dockerfile_spec.rb:10:in `block (2 levels) in <top (required)>' Finished in 1.94 seconds (files took 0.31723 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/dockerfile_spec.rb:10 # File "/entrypoint.sh...
...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...
config.cache_store = :redis_cache_store, { pool: { timeout: 0.5 }, read_timeout: 0.2, # default 1 second write_timeout: 0.2, # default 1 second # Attempt two reconnects with some wait time in...
reconnect_attempts: [1, 5], # default `1` attempt in Redis 5+ url: REDIS_URL, error_handler: ->(method:, returning:, exception:) { Sentry.capture_exception(exception) }, } Timeouts You probably want to adapt these settings...
...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...
...nmap -A makandracards.com -p 443 Starting Nmap 6.40 ( http://nmap.org ) at 2016-07-26 13:45 CEST Nmap scan report for makandracards.com (92.51.173.90) Host is up (0.014s latency).
...Service detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 6.63 seconds
...it might still be a good idea to use the same path of proof. 1. Identify the query your application produces query = User.order(:last_name, :created_at).to_sql
...Scan using index_users_on_last_name_and_created_at on users (cost=0.28..140.10 rows=1164 width=187) (actual time=0.045..0.499 rows=1164 loops=1)"} # => {"QUERY PLAN"=>"Planning...
...array-like already. The behaviour is a bit saner than Array[...]. Array.wrap(nil) # => [] Array.wrap([1,2,3]) # => [1,2,3] Array.wrap(1) # => [1] Array.wrap("foo \n bar") # => ["foo \n bar...
Subclass.setting # => false Base.setting # => true Float#round round to a given number of decimals 1.2345.round(2) # => 1.23 1.2345.round(3) # => 1.235 Hash#deep_merge(!) merge hashes recursively String#squish(!) removes leading...
...for an MP4 and an WebM version: Container / Codecs Chrome 80 FF 74 Safari 13 IE 11 Android Browser 80 iOs Safari Samsung Internet MP4, H.264 + AAC ✓ ✓ ✓ ✓ ✓ ✓ ✓ WebM, VP8 + AAC...
...audio playback was verified unless stated otherwise. Operating system Chrome 80 FF 74 Safari 13/9 IE 11 Mobile Chrome Mobile Safari / Samsung Mobile Firefox Ubuntu 18.04 webm webm / / / / /
...single in an example application writes to the Rails log. Started GET "/rails/active_storage/blobs/redirect/..." for ::1 at ... Processing by ActiveStorage::Blobs::RedirectController#show as SVG Parameters: ... ActiveStorage::Blob Load (0.4ms...
...at key:...
...(http://localhost:3000/rails/active_storage/disk/...) Redirected to http://localhost:3000/rails/active_storage/disk/... Completed 302 Found in 18ms (ActiveRecord: 0.4ms (1 query, 0 cached) | GC: 13.3ms) Started GET "/rails/active_storage/disk/..." for ::1...
...digits and decimal separators, an "e" is also allowed (to allow scientific notation like "1e3"). Non-technical users will be confused by this. Your server needs to understand that syntax...
...digits (e.g. to_i in Ruby) you'll end up with wrong values (like 1 instead of 1000). Users can change values with the up and down arrow keys.
...It's good to know them all, but we recommend Option 0 or Option 1. Option 0: Sub-query with conditions from a scope You may also pass the existing...
...FROM posts WHERE user_id IN (SELECT id FROM users WHERE trashed=f); Option 1: Pluck foreign keys and make a second query We can first fetch the IDs of...
...User < ApplicationRecord end User.first #=> SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 class User < ApplicationRecord self.implicit_order_column = ['updated_at'] end User.first #=> SELECT "users".* FROM "users" ORDER...
...BY "users"."updated_at" ASC, "users"."id" ASC LIMIT 1
When you are using lambdas in RSpec to assert certain changes of a call, you know this syntax: expect { playlist.destroy...
When Rails releases a new version of their gems, they also release a number of npm packages like @rails/activestorage or...