...it properly or you will "randomly" get errors like these: wrong number of arguments (1 for 0) (ArgumentError) wrong number of arguments (0 for 1) (ArgumentError) Take a look at...
def tp(objects, *method_names) terminal_width = `tput cols`.to_i cols = objects.count + 1 # Label column col_width = (terminal_width / cols) - 1 # Column spacing Array(method_names).map do...
...cells.map{ |cell| cell.to_s.ljust(col_width) }.join ' ' end nil end Usage examples: tp Video.where(key: '123'), :created_at, :updated_at, :published tp [album1, album2], :title, :image_count
...ve forked it so it works for Rails 2.3.x applications running on Ruby 1.9. [1] makandra/mongomapper is based on the "official" rails2 branch [2] which contains commits that were...
...added after 0.8.6 was released. Tests are fully passing on our fork for Ruby 1.8.7, REE, and Ruby 1.9.3. To use it, add this to your Gemfile: gem 'mongo_mapper...
I had this error: > gem install bundler Successfully installed bundler-2.0.1 1 gem installed > bundle install Traceback (most recent call last): 2: from /home/henning/.rbenv/versions/2.5.1/bin/bundle:23:in ` ' 1: from /home/henning/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb...
...Probably missing gem: ' + gem_name print 'Auto-install it? [yN] ' gets.strip =~ /y/i or exit(1) system(install_command) or exit(1) # retry Gem.clear_paths puts 'Trying again ...' require gem_name...
...By default, output is sorted by directory name, not size: du -h --max-depth=1 . 40K ./a 2.3G ./b 3.1M ./c 500M ./d 2.8G .
...h switch does the magic of understanding humanized size formats): du -h --max-depth=1 . | sort -h 40K ./a 3.1M ./c 500M ./d 2.3G ./b 2.8G .
A haml angular 1 template with .thing(class="is-{{:: item.type }}") will be compiled (by haml) to which is not what you want! It will also crash in angular (unless thing...
...with Error: [$parse:syntax] Syntax Error: Token 'thing' is an unexpected token at column 11 of the expression [item.type thing] Solution 1: Use ng-class instead of class
...linked article shows what current browsers do when you click a link like this: 1-562-867-5309 Spoiler: The current state is sad It's still the case that...
...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...
...code with Bundler versions < 2.0.2. It just looks like the task is frozen: Workaround 1: Just type your OTP code and hit enter, your gem is released afterwards.
If you need to release a gem with a legacy Ruby version like 1.8.7, the workarounds above won't work for you. In this case, switch to a modern...
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])
...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...
...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