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

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

Using .includes or .eager_load with 1-n associations is dangerous. Always use .preload instead. Consider the following ActiveRecord query: BlogPost.eager_load( :comments :attachments, ).to_a

...post_id" = "blog_posts"."id"; Now assume there is a single blog post with 100 comments and 10 attachments. The OUTER JOINs will cause the query to return 1000 database...

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

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

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

moncefbelyamani.com

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

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

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

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

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

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

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

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

makandra dev
ruby-doc.org

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

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

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

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

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

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

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