...date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1...
...Here are two options by example on how to achieve this in Rails. Option 1 Time.use_zone('UTC') { Time.zone.parse('2020-08-09 00:00') } => Sun, 09 Aug...
In shell scripts you can use $1 to refer to the first argument, $2 for the second, etc. If you want to refer to all arguments (e.g. when writing a...
...and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...”. Use $@ instead, like in this script: $ cat welcome #!/bin/bash
...as #html_safe will lead to unexpected behavior. E. g. backreferences to captured groups ($1, $2) will be nil even if the group was matched. There is no universal workaround...
...to still be safe after using gsub on them. You can, however, fix the $1 gsub behavior on html_safe strings...
...1,2,3,4].sample # => e.g. 4 If you'd like to cheat and give different weights to each element in the array, you can use the attached initializer to...
[1,2,3,4].weighted_sample([1,1,1,1000])
...cause flaky tests Load rbenv on session create Load nvm on session create (part 1 and part 2) Add an open alias
...database in order to import the dump. If any problems occur, proceed as follows: 1. Figure out the original migration status of the dumpfile Convert your dump to plaintext: pg...
...git log --reverse ./db/migrate/20200729124233_add_users.rb commit d4848ad598b2f02cbca7580a2b928d02996abeb4 Author: Some user <some.user@example.com> Date: Thu Jul 30 16:07:51 2020 +0200 Add users commit 7b7fa26b838e576a70dee79d71f194f6a673c500 Author: Some user <some.user@example.com> Date: Tue Aug...
def all_tags virtual_tags + tags end end > Post.new.virtual_tags => [] # ✔ > Post.find(1).virtual_tags => nil # ☹ > Post.find(1).all_tags => Error: undefined method '+' for nil:NilClass
...file to use them (for example like this): file = @attachment.file.path file_extension = File.extname(file)[1..-1] options = {} options[:type] = Mime::Type.lookup_by_extension(file_extension).to_s send_file file...
...Cucumber uses mocha. This note shows to use RSpec stubs and mocks instead. Rspec 1 / Rails 2 Put the following into your env.rb: require 'spec/stubs/cucumber' Rspec 2 / Rails 3
When used to do: $> cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 15 model : 4 model name : Intel(R) Xeon(TM) CPU 3.00GHz stepping : 1
...Instead, on Solaris, use psrinfo(1M) $> psrinfo -v Status of virtual processor 0 as of: 09/17/2006 21:45:32 on-line since 08/24/2006 16:16:03. The i386 processor operates...
...other request like from ActionCable. Then just set the maximum number of workers to 1 and the other requests have to wait. UNICORN_WORKERS=1 rails server
...object, Ruby calls #to_a on the object: o = String.new('O') def o.to_a [1,2,3] end a, b, c = o # Implicit call to #to_a here
...can manually calculate the quarter index like (Date.parse('2011-02-10').month / 3.0).ceil #=> 1 Yes, you do actually divide by 3.0, not 4.0. MySQL has SELECT QUARTER...
...1...
When you need the DOM node of a tag (e.g. to read extra attributes, or to modify the DOM near it), you can usually reference it via document.currentScript. However, document.currentScript is unsupported in ancient browsers, like Internet Explorer 11 or wkhtmltopdf's Webkit engine. If you are not running async scripts, you can easily polyfill it: document.scripts[document.scripts.length - 1] It works because document.scripts grows with each tag that was evaluated. That is also the reason why this solution will not work reliably for async code. Demo: https://codepen.io/foobear/pen/poRLxQm
...This does not play too nice with Visor, because Visor will always be "window 1" for AppleScript. By modifying the script and replacing in window 1 with in window...
...number of blank forms: Number of actors Number of blank actor forms 0 5 1 5 2 5 3 5 4 6 5 7 6 8 Luckily, there's an...
...users GROUP BY name; With ONLY_FULL_GROUP_BY this now explodes with: ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated...
You need to make sure that any selected value is either (1) the value you group by or (2) passed to an aggregate function like MIN or...
...a rough estimate of the LOC. find app -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' | tail...
Resolve @{-1} to actual branch name. (Happens when merging "-".)
...can reduce the webdriver update interval and see if VCR complains: WD_CACHE_TIME=1 bundle exec cucumber Note: Newer Rails versions come with the webdrivers gem automatically...
...your ActiveRecord models with very little code. Traim assumes your API resources will map 1:1 to your ActiveRecord models and database tables. This assumption usually falls apart after a...
Coffeescript # wrong 'name' in {name: 'Horst'} # => false # correct 'name' of {name: 'Horst'} # => true 1 in [1,2,3] # => true
...use the bash script below by copying it somewhere to your .bashrc. # Usage: ptcommits 123456 function ptcommits { if test "$1" then local PTID=$(echo "$1" | grep "[0-9]*" -o) # Allow...
} alias ptcommit='ptcommits' Now you can use use the command like this: ptcommits 165086636 --stat. Up to three arguments are passed to git show. Example output: commit 048054b1df87576f7c59cc0161cc331c44d2ea6b