Today I Learned

Giant Monkeys Learning

3 posts about #Ruby

Construct an array with _ index

Blocksyntax:

years = Array.new(11) { Time.now.year + _1 }

Hier wird Array.new(11) verwendet, um ein Array mit 11 Elementen zu erstellen (einschließlich des aktuellen Jahres), und der Block { Time.now.year + _1 } berechnet das Jahr für jedes Element (beginnend mit dem aktuellen Jahr). _1 ist ein Platzhalter für den Index des Blocks (ab 0).

Copy-paste friendly executable comments in Ruby

Imagine this comment on top of a ruby file: ```ruby

usage:

reset and seed database

rake db:reset

get korona base data

rails runner 'Korona.synchronize_all!'

create valid day tickets in local development

rails runner rails-runner/create_valid_ticket_for_shop_tests.rb

It is supposed to document the usage and gives executable example lines. However to use them verbatim you have to copy-paste them line by line, removing the leading `#`.

There is a better alternative using the [mostly frowned upon](https://stackoverflow.com/a/3000121/1162143) `=begin` / `=end` comment style:
```ruby
=begin usage:
rake db:reset                                                   # reset and seed database
rails runner 'Korona.synchronize_all!'                          # get korona base data
rails runner rails-runner/create_valid_ticket_for_shop_tests.rb # create valid day tickets in local development
=end

Now it is possible to copy-paste the whole block into a shell to execute.

make firefox to accept puma-dev cert permanently

every time, firefox is restarted, and i'm opening https://gomus.test again, the cert has to be accepted manually again.

  • use open ~/Library/Application\ Support/io.puma.dev/ in terminal to show your local puma-dev certs folder
  • enter about:preferences#privacy into firefox url-bar
  • all the way at the bottom you’ll find Certificates
  • click on View Certificates
  • in the last Authorities tab, you can import the Puma-dev certificate you've revealed in first step
  • you only need to accept this for websites …

from now on, firefox will without any disturbance open local https:// puma-dev websites.