...all tables (schema public) from every database. Replication For updates method names in postgres 10 look in the wiki. Current xlog position on the master: SELECT pg_current_xlog_location...
SELECT pg_current_wal_lsn(); -- repeat command every second on psql \watch 1 Received xlog position on the slave: SELECT pg_last_xlog_receive_location(); -- postgres 10
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...
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...
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...
...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
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...
...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
...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...
...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...
...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...
...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...
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...
...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...
...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...
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...
...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...