This card is just about creating simple PostgreSQL dumps. This is no instruction for a backup strategy nor a guide...
...Date and Time to that list, but other classes could also make sense. data = {foo: 'bar'}.to_yaml ::YAML.safe_load(data) Psych::DisallowedClass: Tried to load unspecified class: Symbol
...load(data, [Symbol]) => {:foo=>"bar"} Pitfall 2: Psych::BadAlias Psych#dump will create aliases if you reference the same object more than one time. By default this is disabled by...
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...
def long_message puts(<<-EOT) Here goes a very long message... Sincerely, foobear EOT end <<-EOT will be somewhat of a placeholder: anything you write in the line...
...the example above will be " Here goes a very long message...\n Sincerely,\n foobear\n". Depending on where you use it, this may or may not be a problem...
...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...
...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
...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...
...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...
You want to prevent input to a form field, but all the solutions have side effects: The [readonly] attribute is...
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...
...when SomeException is raised Some advanced examples for scriptable breakpoints: debugger(pre: "info ;; puts @foo ;; info ;; bt ;; break @user.name") # starts debugging session after executing each of the pre commands
...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...
add_column :my_table, :search_text, :virtual, type: :text, as: search_text_expression(:foo, :bar, :baz), stored: true add_index :my_table, :search_text, using: :gin, opclass: :gin_trgm...
...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...
...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...
...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...
...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']
...method, created by a user in commit d47bf443: def hello 'world' end ^ $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello d47bf443 (Arne...
...is how Git blames those lines with and without the -w switch: $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello f5fae4c1 (Señor...
...prevents referencing closures, scopes, etc. from being garbage-collected. This code leaks memory: @app.directive 'foo', -> link: (scope, element, attributes) -> $(document).on 'click', -> # code here To prevent leaks you must manually...
...elements that are not your own descendants. This code does not leak memory: @app.directive 'foo', -> link: (scope, element, attributes) -> listener = -> # code here $(document).on 'click', listener scope.$on '$destroy', -> $(document...
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...
...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