...first argument. Compare these two different ways of calling fun() in Ruby: # Ruby array = [1, 2, 3] fun(array) # same as fun([1, 2, 3]) (1 argument) fun(*array) # same...
...as fun(1, 2, 3) (3 arguments) Depending on your culture the spreading of array elements into multiple argument slots is called "splat args" or "spread args" or "rest operator...
...slider--item.is-current, [aria-label="slider's item that is current"]' when /^the (.*)$/ match = $1 match =~ /^(.+?)(?:'s (.+?))?(?: that (.+))?$/ bem_selector = '.' bem_selector << selectorify($1) bem_selector << '--' << selectorify($2) if...
...selector = '[aria-label="' aria_selector << match.gsub('"', '\\"') aria_selector << '"]' [bem_selector, aria_selector].join(', ') when /^"(.+)"$/ $1 else raise "Can't find mapping from \"#{locator}\" to a selector.\n" + "Now, go and...
...match?(/[[:space:]]/) # => true "\n".match?(/[[:space:]]/) # => true nbsp = "\xC2\xA0".encode!(Encoding::ISO_8859_1) # => "\xA0" nbsp.match?(/[[:space:]]/) # => Encoding::CompatibilityError (incompatible encoding regexp match (UTF-8 regexp with ISO...
# => true "\n".match?(/\p{Zs}/) # => false nbsp = "\xC2\xA0".encode!(Encoding::ISO_8859_1) # => "\xA0" nbsp.match?(/\p{Zs}/) # => Encoding::CompatibilityError (incompatible encoding regexp match (UTF-8 regexp with ISO...
...Elasticsearch to Opensearch This card deals with specifics concerning the use of searchkick. Step 1: Make Opensearch available for Searchkick In your Gemfile # Search gem 'searchkick' # needs to be...
...if forces connections via https, which we don't have in local environments. Option 1: With plugins Create a Dockerfile FROM opensearchproject/opensearch:2.11.0 RUN /usr/share/opensearch/bin/opensearch-plugin list | grep 'ingest-attachment' || /usr/share/opensearch/bin/opensearch-plugin...
...the constructor. returnValue & returnValues it('shuffles the array', () => { spyOn(Random, 'shuffle').and.returnValue([3, 2, 1]) array = [1, 2, 3] testedClass = new testedClass(array) expect(Random.shuffle).toHaveBeenCalled() expect(testedClass.array).toEqual...
}) If you have several new classes created in one test you could also use returnValues for any call of the method Random.shuffle. callFake If you are testing the class...
...fully permitted parameters object. You never want that. Why? Because it introduces potential vulnerabilities. [1] Even if you are sure that nobody else accesses the params object after your code...
...be. Be careful what you use it; we have a separate card on that. [1] For example: If params are assigned to model attributes, your model won't complain, since...
I, [2024-01-21T06:22:17.484221 #2698200] INFO -- : [4cdad7a4-8617-4bc9-84e9-c40364eea2e4] test I, [2024-01-21T06:22:17.484221 #2698200] INFO -- : [4cdad7a4-8617-4bc9...
...84e9-c40364eea2e4] more I, [2024-01-21T06:22:17.484221 #2698200] INFO -- : [6e047fb3-05df-4df7-808e-efa9fcd05f87] test I, [2024-01-21T06:22:17.484221 #2698200] INFO -- : [6e047fb3...
...once results exceed a certain threshold. For example, you may only need to display 100+ in the UI. Using a plain COUNT(*) would scan all matching rows. The following query...
...LIMIT to cap the scan early. You’ll get the exact number up to 100 otherwise you can show 100+. SELECT COUNT(*) FROM (SELECT 1 FROM movies LIMIT 101) AS...
...This task list is divided by the Gate keeping process in the following steps: 1. Starting a new feature 2. Working on the issue 3. Finishing a feature
...design and the points from Building web applications: Beyond the happy path The template: 1 Starting a new feature Set the issue to "In Progress" in Linear Pull the most...
...t: the current time in 24-hour HH:MM:SS format, \T: same, but 12-hour format, @: same, but in 12-hour am/pm format \n: newline \r: carriage return
...x: attribute of the text 3y: foreground color 4y: background color x: 0: normal 1: bold 4: underline 7: reverse y is the color: 0 black 1 red
The git doc states on the difference of these two commands: git-restore[1] is about restoring files in the working tree from either the index or another commit. This...
...also be used to restore files in the index from another commit. git-reset[1] is about updating your branch, moving the tip in order to add or remove commits...
...is also suggested by Rubocop's Style/GlobalVars cop. Example before: if 'foo' =~ /foo/ puts $~[1] # => foo end Example after: if 'foo' =~ /foo/ puts $LAST_MATCH_INFO[1] # => foo end
...a SHA1 revision. Your editor will open with a file like pick fda59df commit 1 pick x536897 commit 2 pick c01a668 commit 3 Each line represents a commit (in chronological...
...these commits into a single one, change the file to this: pick fda59df commit 1 squash x536897 commit 2 squash c01a668 commit 3 This means, you take the first commit...
...using Geordi, disable automatic updating of chromedriver in ~/.config/geordi/global.yml: auto_update_chromedriver: false Option 1: Use Geordi The geordi gem can upgrade to the correct version of chromedriver: geordi chromedriver...
...z "$VERSION" ]; then echo "Failed to read current version from $VERSION_URL. Aborting." exit 1 else echo "Current version is $VERSION" fi # Abort script if any of the next commands...
...sort the number of requests for a single IP address. Bash Command awk '{ print $1}' test.log | sort | uniq --count Result 1 87.140.79.41 3 87.140.79.42 Explain awk '{ print $1}' test.log...
87.140.79.41 87.140.79.42 87.140.79.42 87.140.79.42 uniq --count [1] 1 87.140.79.41 3 87.140.79.42 [1] -c, --count: prefix lines by the number of occurrence
...example.metadata[:type] # => "controller" From an example itself or a before block, query self.class.metadata. RSpec 1 Unfortunately, RSpec 1 doesn't offer such filters, and the helpful metadata isn't around...
...in a spec that knows about request and response You can use the RSpec 1 approach to find out if your current example knows about RSpec's request and response...
...ActiveRecord::Base.establish_connection(config) end it 'should synchronize processes on the same lock' do (1..20).each do |i| fork_with_new_connection do @reader.close ActiveRecord::Base.connection.reconnect! Lock.acquire('lock') do...
...a typo or similar lines.each_slice(2) do |start, finish| start.should =~ /Started: (.*)/ start_thread = $1 finish.should =~ /Finished: (.*)/ finish_thread = $1 finish_thread.should == start_thread end @reader.close end end Caveats
...a new frame is rendered 60 times a second. Thus, a single frame is 1000ms / 60 = 16.6...ms long. Once a frame renders longer than 16ms, the page will begin...
...s well searchable when you just have a question about some function. Performance issue 1: Slow JavaScript If an event occurs and JavaScript has to run, the browser have to...
...approaches in Rails, how you can assign such an association via HTML forms. Option 1: Array column One way to solve the problem is using a database column with an...
...We need to take care of not assigning nil as value of posts Option 1: Using with_defaults! in the controller + include_hidden: false in the form (used in the...
...can list them like this: $ git stash list stash@{0}: WIP on feature/foo stash@{1}: WIP on feature/bar stash@{2}: WIP on fix/baz All those stashed changes have their own...
...reference (like branch names) that you can look at, like stash@{0}, stash@{1}, etc. Above, we looked at stash@{0} which is the default for stash actions.
...enabled for node. Installing nvm DigitalOcean has a HOWTO for installing nvm on Ubuntu (16.04, 18.04, 20.04) that I recommend. During the installation of node via nvm, a compatible version...
...to be done separatly for each node version on your system, though. Install yarn 1 system-wide via apt The yarn package depends on the nodejs debian package, but with...
attribute attr end validates *REQUIRED_ATTRIBUTES, presence: true validates *ALL_ATTRIBUTES, length: { maximum: 1000 } # From this you already get methods like `#valid?` and `#==`. # (optional) Here is the perfect place...
...Address instance: # without :mapping Rails uses keyword arguments Address.new(street_and_number: 'Foo St. 1', zip_code: '12345', city: 'Bar Town') # with a :mapping (even if that is just the...
...used for the same effect. Relation#to_sql # Rails 2 scope Post.scoped(:conditions => { :id => [1, 2] }).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" ^ # Rails 3 relation...
...Post.where(:id => [1, 2]).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" Implementation note: Rails 3+ implements #to_sql. Relation#to_id_query Site.joins(:user).where(:users...
...A-Za-z0-9]+> is easier to write but matches invalid tags such as <1>. Use \b[1-9][0-9]{3}\b to match a number between 1000 and...
...Use \b[1-9][0-9]{2,4}\b matches a number between 100 and 99999. Modes: Greedy, Lazy and Possessive Example string: This test is a first test string...