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

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

github.com

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

makandra dev

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

makandra dev

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

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

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

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

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

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

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