api.rubyonrails.org

...Load (0.7ms) SELECT "page_versions".* FROM "page_versions" WHERE "page_versions"."id" IN (1, 2, 3) Image Load (0.4ms) SELECT "images".* FROM "images" WHERE "images"."id" IN (1...

...Video Load (0.5ms) SELECT "videos".* FROM "videos" WHERE "videos"."id" IN (1) Accessing any page.current_version.primary_medium will then happen without any extra queries. Be careful when adding conditions

...on Ubuntu 24.04 with Xorg. Background Ubuntu always sets the primary display to the 1st (i.e. internal) display whenever I connect to a new Dock/Hub. I want my primary display...

...assumes that external display order is left to right. If displays are ordered e.g. 1, 3, 2, connect displays differently. Script The script's comments should explain what is going...

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

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

...the moment (for e.g. if one worker seems to be stuck): * PID: 4273 Sessions: 1 Processed: 47 Uptime: 50m 53s CPU: 43% Memory : 3644M Last used: 49m 24s ago

...request_body_fully_read" : true, "request_body_type" : "NO_BODY", "response_begun" : false, "session" : { "gupid" : "18asd3ed-U4FSeggT0O", "pid" : 4273 }, "last_data_send_time" : null, tells me, that this process did...

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

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

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

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

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

...is to encode the string using JSON, and then escaping all code points above 127 using unicode escape sequences: escapeHighASCII('{"foo":"xäy"}') // => '{"foo":"x\\u00e4y"}' The program that reads the...

...high ASCII in JavaScript function escapeHighASCII(string) { let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0') return string.replace(/[^\x00-\x7F]/g, unicodeEscape) } Escaping high ASCII in Ruby

...following processes to split up the changes into several commits in a logical order: #1 Splitting up the last n commits into m commits #2 Adding changes to a previous...

...creating new commits) 3.1 Splitting up 3.2 Adding to later commits #4 Reordering commits #1 Splitting up the last n commits into m commits If you decide to split up...

...user_input, { class: 'paragraph' }, { sanitize_options: { tags: [], attributes: [] } }) will result in Hello World alert(1) For Rails versions that don't support this option, consider using a custom method...

...ENV.fetch('OPENAI_API_KEY')) puts client.images.generate(parameters: { prompt: prompt, model: 'dall-e-3', size: '1024x1024' }).dig("data", 0, "url") ~/bin/text-to-audio #!/usr/bin/env ruby require 'openai' prompt = ARGV[0] output_path = ARGV...

...1] || 'output.mp3' if prompt.to_s.strip == '' puts 'Usage: text-to-audio "Yesterday I ate some tasty parmiggiano cheese at a wedding. It was the cake!" cake.mp3' exit end client = OpenAI::Client.new(access...

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

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

ruby-doc.org

...to store the conversion factor from MJ to kWh in a variable, which is 1/3.6. Using BigDecimals for this seems like a good idea, it usually helps with rounding errors...

...are cases where you still have to worry about rounding errors. conversion_factor = BigDecimal('1') / BigDecimal('3.6') # => 0.277777777777777777777777777777777778e0 Here the conversion factor got rounded after some decimal places. If you...

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

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

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

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

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

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