...files to access their full history. Given a file "bar" that was previously named "foo": touch foo git add foo git commit -m "Add foo" mv foo bar
git commit -m "Rename foo to bar" git log bar commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow) Author: Michael Leimstaedtner <makmic@makandra.de> Date: Wed May 12 08:49:37 2021 +0200
This also works on hashes. However, mind the required syntax: { hello: 'universe', foo: 'bar' }.each_with_index do |(key, value), index| puts "#{index}: #{key} => #{value}" end # 0: hello => universe...
The reason is that each_with_index yields 2 elements to the block, and you need to deconstruct the first element (a tuple of key and value) explicitly...
...scope to pluck all the ids of the relation: # Modern Rails User.where("users.name LIKE 'Foo Bar'").ids # Rails 3.2+ equivalent User.where("users.name LIKE 'Foo Bar'").pluck(:id) # Edge rider equivalent...
User.where("users.name LIKE 'Foo Bar'").collect_ids
...will comment code so it will not be sent to the client: -# = link_to 'foo' 99% of the time you'll be adding notes for other developers, or disabling code...
...background-image: url('../images/foo.png') won't work any longer, because there is no public/assets/images. foo.png now lives directly in public/assets. Example app/assets/fonts app/assets/fonts/fonts_root.css app/assets/fonts/fonts_root.js app/assets/fonts/fonts_root.png app/assets/fonts/fonts_root.ttf app/assets/fonts/subfolder app/assets/fonts/subfolder/fonts_subfolder.css app/assets/fonts/subfolder/fonts_subfolder.js app/assets/fonts/subfolder/fonts_subfolder.png...
...in the first place. Simply use the SASS helper: .tile background-image: image-url('foo.png') Managing 3rd party assets You don't want to manually fix references in external libraries...
...care of the cleanup manually You can create a prefix and suffix e.g. Dir.mktmpdir(['foo', 'bar']) => /tmp/foo20220912-14561-3g93n1bar You can choose a different base directory than Dir.tmpdir e.g. Dir.mktmpdir('foo', Rails.root.join...
This card is just about creating simple PostgreSQL dumps. This is no instruction for a backup strategy nor a guide...
...or IIFEs) to prevent local variables from bleeding into an outside scope: (function() { var foo = "value"; // foo is scoped to this IIFE })(); In Coffeescript an IIFE looks like this: (->
...value" # foo is scoped to this IIFE )() There is also a shorthand syntax with do: do -> foo = "value" # foo is scoped to this IIFE You can also use do with...
options = { settings: { number_of_replicas: NUMBER_OF_REPLICAS}, } searchick **options ... end Class Foo < ActiveRecord::Base include DoesSearch ... Our operations team used to patch the number_of_replicas setting...
...an element "the container's width minus 20px on each side"? Here you go: .foo { width: calc(100% - (20px * 2)); } When using Sass, you need to interpolate Sass expressions:
.foo width: calc(100% - #{$margin}) Supported by all modern browsers and IE9...
...speed a like query that has a wildcard on the right side: SELECT * FROM foo WHERE field LIKE "bar%" # will be faster with an index It can not speed up...
...a query that has a variable left side: SELECT * FROM foo WHERE field LIKE "%bar%" # will not be faster with an index That also means if you use the ancestry...
...to keep your test output and logs clean. How to express page breaks, headers, footers, etc. There are concepts and formattings that only make sense on paper, so the question...
...These are things like: Paper form Print margins Repeating header on every page Repeating footer on every page You can actually execute JavaScript before the page is rendered to PDF...
...you need complex expectations on method arguments like this SomeApi.should_receive(:find).with(:query => '*foo*', :sort => 'timestamp ASC', :limit => 100).and_return(['some result']) This is not very flexible, and...
Instead, consider doing this: SomeApi.should_receive(:find) do |params| params[:query].should == '*foo*' params[:sort].should == 'timestamp ASC' params[:limit].should == 100 ['some result']
...logic, all perform almost equally: require 'benchmark/ips' # requires the 'benchmark-ips' gem GC.disable class Foo define_method("foo") { 10.times.map { "foo".length } } class_eval 'def bar; 10.times.map { "foo".length }; end'
...baz; 10.times.map { "foo".length }; end end Benchmark.ips do |x| foo = Foo.new x.report("define_method") { foo.foo } x.report("def via class_eval") { foo.bar } x.report("def") { foo.baz } end Warming up -------------------------------------- define_method...
Indent text by 4 spaces. This way it is recognized as code. def foo "hello!" end def foo "hello!" end You can also create code blocks GitHub-style: ```
"hello!" end ``` def foo "hello!" end Lists * Bullet list item 1 * Bullet list item 2 Bullet list item 1 Bullet list item 2 You can also use + or - instead...
...the nth-child within a subset of siblings matching a selector. For example: .container .foo %span.my-selector .bar %div.my-selector .container > *:nth-child(1 of .my-selector) color: red
...port 16380 --database 1 INFO memory | grep maxmemory_human maxmemory_human:512.00M Memory footprint If you want to calculate the estimated Redis memory usage of a job, you can...
...memory usage before and after the job was enqueued. For a simple job like Foo.perform_async(1) the memory footprint is around 508 bytes. Here is a short table to...
...either some Ruby code or your Rails app, use the differ gem. puts Differ.diff "foo", "boo" # => {"boo" >> "foo"} Usage There are several variants available, all using the base method diff...
Standard formatting is :ascii. You also have :html and :color formatting: diff = Differ.diff "foo", "boo" puts diff.format_as :html # => boo foo puts diff.format_as :color # => \e[31mboo\e[0m...
...helper from a controller using the helpers method: # Inside a controller action helpers.link_to 'Foo', foo_path In older Rails versions you can use view_context instead: # Inside a controller...
view_context.link_to 'Foo', foo_path
URLs can transport key/value pairs ("parameters") using this syntax: /path?foo=bar If the value is blank, mind these subtle differences: URL Meaning /path?foo= Parameters have a key foo...
...Its value is an empty string. /path?foo Parameters have a key foo. Its value is null. /path Parameters have no key foo...
...and you modify the copy, you will run into the following behavior: original_hash = { foo: { bar: 'original value' } } copied_hash = original_hash.dup copied_hash[:foo][:bar] = 'changed value' original_hash # => { foo...
...changed value" } This is, because { bar: 'baz' } is an object, which is referenced in :foo. The copy of original_hash still holds the reference to the same object, so altering...
...passes with [up-hungry] fragments. Targeting sibling elements now supports union selectors like .parent .foo, .parent .bar...
...getter/setter functions, and probably never will. However, you can define getters/setters using Object.defineProperty: object = {} fooValue = undefined Object.defineProperty object, 'foo', get: -> fooValue set: (newValue) -> fooValue = newValue Some people are also doing...
...would actually be longer than two lines: Dies ist ein Text mit mehreren Zeilen foo bar would be rendered as Dies ist ein Text mit mehreren Zeilen... I recommend building...