The linked GitHub repository is a bit like our "dev" cards deck, but groomed from a single person (Josh Branchaud). It includes an extensive list of over 900 TILs on many topics that might be interesting for most of us. (e.g. Ruby, Rails, Git, Unix..)
Ruby
Here is an excerpt of all the Ruby TILs Show archive.org snapshot that were new to me. I encourage you to take your time to skim over the original list as well!
-
Assoc For Hashes
Show archive.org snapshot
-
Hash#assoc
can be used to grab both the key and value from a hash
-
-
Rerun Only Failures With RSpec
Show archive.org snapshot
- RSpec can be configured to run only failed specs:
RSpec.configure do |config|
config.example_status_persistence_file_path = "tmp/failed_specs.txt"
end
# Then, run "rspec --only-failures"
-
Disassemble Some Codes
Show archive.org snapshot
-
RubyVM::InstructionSequence#compile
can be used to compile Ruby code on the fly. It offers a#disasm
method for further inspection.
-
- Destructuring Arrays In Blocks Show archive.org snapshot
{ key: [1,2] }.each { |key, (x, y)| puts "#{x}- #{y}" }
-
Defaulting To Frozen String Literals
Show archive.org snapshot
- This magic string auto-assigns
freeze
to constants of a given file
- This magic string auto-assigns
# frozen_string_literal: true
binding.local_variables.inspect
-
Limit Split
Show archive.org snapshot
-
String#split
takes a second argument to limit the number of applied splits
-
-
Last Raised Exception In The Call Stack
Show archive.org snapshot
- The
$!
global variable contains the last exception that was raised in the current call stack
- The
-
Identify Outdated Gems
Show archive.org snapshot
-
bundle outdated
compares the versions of all gem dependencies against the gem server
-
- Get Info About Your Ruby Gems Environment Show archive.org snapshot
gem environment
-
Mocking Requests With Partial URIs Using Regex
Show archive.org snapshot
- Note the elegant way to describe Regex URLs:
%r|/foo/bar|
- Note the elegant way to describe Regex URLs:
stub_request(:post, %r|/api/posts|)
-
Pass A Block To Count
Show archive.org snapshot
-
count
can be used like "count by":
-
[1,2,3].count { |x| x.odd? }
bundle install --jobs 4
-
Run An Older Version Of Bundler
Show archive.org snapshot
- Fun fact: This TIL links back to makandracard! :-)
bundle _1.16.6_ --version
puts "I am #@name"
-
Squeeze Out The Extra Space
Show archive.org snapshot
-
String#squeeze
is likeString#squish
but replaces multiple subsequent occurrences of a given character with a single one
-
- Use Tap For Better Test Data Setup Show archive.org snapshot
let(:order) do
create(:order, name: "My Order").tap do |order|
create(:item, name: "Burger", order: order, price: 4.99)
create(:item, name: "Fries", order: order, price: 2.99)
end
end
Float#next_float
Float#previous_float
Chrome
- On the developer console, copy data to the system clipboard with
copy('data')
.
Git
- Executing a bash command in each step of an interactive rebase Show archive.org snapshot
-
Finding a commit by commit message using regular expressions with
git show :/regex
Show archive.org snapshot -
Show commits touching a given line(s) with
git log -L12:25:README.md
Show archive.org snapshot -
Controlling
git add -p
with single key presses Show archive.org snapshot -
Stash unstaged changes only with
git stash -k
Show archive.org snapshot
JavaScript
Posted by Michael Leimstädtner to makandra dev (2020-04-27 13:44)