How to generate GIDs from an ActiveRecord scope
ActiveRecord provides the ids method to pluck ids from a scope, but what if you need to pluck Global IDs?
While you could just call map(&:to_global_id) on your scope, this approach would instantiate each record just to do that. When you have many records, this will at the very least be slow.
Here is a method that does it for you efficiently. It respects Single Table Inheritance (STI).
Put it in your project's ApplicationRecord to make it available on all models.
class ApplicationRecord
  ...
Chrome: Using browser notifications
Development
Google Chrome disables Notifications for insecure origins (i.e. those using HTTP). Only http://localhost is considered secure.
If you need to use browser notifications on other origins, you can set a flag: chrome://flags/#unsafely-treat-insecure-origin-as-secure. Enable the flag and add your origins. Remember that "origin" refers to the combination of protocol+hostname+port, e.g. "http://example.com:8088".
Git: Search for text in all branches
To find a version containing the regular expression foo in the history of any branch:
git grep foo $(git rev-list --all)
You may also limit the search to a file extension, e.g. Ruby files (.rb) like this:
git grep foo $(git rev-list --all) -- *.rb
Ruby Jard: Just Another Ruby Debugger
Ruby Jard provides a rich Terminal UI that visualizes everything your need, navigates your program with pleasure, stops at matter places only, reduces manual and mental efforts.
Workflow: How to use a key management service to encrypt passwords in the database
This is an extract from the linked article. It shows an approach on how to implement encrypted passwords with the AWS Key Management Service (KMS).
For most applications it's enough to use a hashed password with a salt (e.g. the gem devise defaults to this).
Upon password creation
- 
Generate hash as hash of password + salt.
 - 
Encrypt the hash with a public key from KMS (you can store the public key in your server code).
 - 
In your database sto...
 
Carrierwave: How to migrate to another folder structure
A flat folder structure can be cool if you have only a few folders but can be painful for huge amounts. We recently had this issue in a project with more than 100.000 attachments, where we used a structure like this /attachments/123456789/file.pdf.
Even the ls command lasted several minutes to show us the content of the attachments folder.
So we decided to use a more hierarchical structure with a limited maximum of folder per layer. Here are a few tips how to migrate your files to their new...
How to fix: Rails query logs always show lib/active_record/log_subscriber.rb as source
Rails 5.2+ supports "verbose query logs" where it shows the source of a query in the application log.
Normally, it looks like this:
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE ...
  ↳ app/controllers/users_controller.rb:42:in `load_users'
However, you may encounter ActiveRecord's LogSubscriber as the source for all/most queries which is not helpful at all:
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE ...
  ↳ activerecord (6.0.3.3) lib/active_record/log_subscriber.rb:100:in `debug'
While th...
Fixing AfterAll TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
This error occurs when passing an object instead of a string to Jasmine's describe():
# Bad
describe(HoverClass, function() { ... })
# Correct
describe('HoverClass', function() { ... })
Service Worker series by GoMakeThings
Learn how to create offline applications with service workers.
- The amazing power of service workers
 - Writing your first service worker with vanilla JS
 - Saving recently viewed pages offline with service workers and vanilla JS
 - Offline first with service workers and vanilla JS
 - Improving web font performance with service workers
 - How to set an expiration date for items in a service worker cache
 - How to update a service worker
 - How to trigger a service worker function from the front end with vanilla JS
 - How to immediately ...
 
RubyMine: Restore main menu in Ubuntu
After a recent Ubuntu update I didn't see the main menu bar of the RubyMine IDE (File | Edit | View | ...) anymore.
This could be solved by changing a RubyMine registry entry:
- Search "registry" within the "Actions" search
- press 
ctrl + alt + n> click onActions> typeregistry> click onRegistry... 
 - press 
 - Scroll down to 
linux.native.menuand disable the checkbox 
After rebooting RubyMine, you'll have gotten the menu bar back.
Cucumber 4 and VCR integration
If you are trying to integrate VCR and Cucumber 4 and you're using the  use_scenario_name: true option you will run into an error like this:
undefined method `feature' for #<Cucumber::RunningTestCase::TestCase:0x00005650550ba080>
Currently the VCR integration and Cucumber 4 is broken, but you can find an open issue with details and a monkey patch here.
apt: how to prevent a package from upgrading
Sometimes new versions of software introduce new bugs. In this case you might not want the package to upgrade on a simple apt upgrade run. To do so, you can set the package on hold.
Hold a package:
sudo apt-mark hold <package-name>
Remove the hold:
sudo apt-mark unhold <package-name>
Show all packages on hold:
sudo apt-mark showhold
When you set a package on hold and you run apt upgrade you will see the following output which will remind you of the hold:
...
The following packages have been kept back:
...
Clean your Rails routes: grouping
In Ruby on Rails, all the routes of a given application can be found within the config/routes.rb file.
You add more and more routes in this file as your project grows.The problem here is that this file potentially becomes very complicated to manage over the time.
That’s why it’s important to find a way to order and maintain your routes.
See: Clean your Rails routes: grouping
Sometimes the routes.rb grows very fast and each line adds mo...
Ruby: Appending lines to a file in sync
When writing some logs to a file, that don't use Ruby's logger utility, it is often useful to sync them. So other process can read the output just in time.
Example with enabled sync
log_path = '/tmp/some_log.log'
log_file = File.open(log_path, 'a+')
log_file.sync = true
log_file.puts('Some log message')
File.read(log_path) #=> "Some log message\n"
log_file.puts('Some other message')
File.read(log_path) #=> "Some log message\nSome other message\n"
Example ...
Webpacker: Disable source maps
You can do this per environment, e.g. in config/webpack/test.js:
const environment = require('./environment')
const config = environment.toWebpackConfig()
config.devtool = 'none'
module.exports = config
Parallel cucumber: How to pass in cucumber arguments
Here is an example with the --tags option. You need to wrap them inside --cucumber-options option of parallel_cucumber.
DISPLAY=:17 bundle exec parallel_cucumber --cucumber-options '--tags @solo' features
See more details in the docs.
Chrome: how to fix window issues (maximize, minimize,...)
I experienced a lot of issues with google chrome that made it almost impossible to work with it. Here are some of them:
- minimized windows stay hidden
 - maximized windows overlap system bars (like the status bar of Ubuntu Mate on the top edge of the screen)
 - windows cannot be resized
 
I finally discovered a setting that fixed these issues for me:
- go to 
chrome://settings/appearance - activate 
Use system title bar and borders 
I'm not sure if this setting was changed by me or if it was the browser default.
Vortrag: Content Security Policy: Eine Einführung
Grundidee
CSP hat zum Ziel einen Browser-seitigen Mechanismus zu schaffen um einige Angriffe auf Webseiten zu verhindern, hauptsächlich XSS-Angriffe.
Einschub: Was ist XSS?
XSS = Cross Site Scripting. Passiert wenn ein User ungefiltertes HTML in die Webseite einfügen kann.
<div class="comment">
  Danke für den interessanten Beitrag! <script>alert('you have been hacked')</script>
</div>
Rails löst das Problem weitgehend, aber
- Programmierfehler weiter möglich
 - manchmal Sicherheitslücken in Gems oder Rails
 
Lösungsid...
How to check if a file is a human readable text file
Ruby's File class has a handy method binary? which checks whether a file is a binary file. This method might be telling the truth most of the time. But sometimes it doesn't, and that's what causes pain. The method is defined as follows:
# Returns whether or not +file+ is a binary file.  Note that this is
# not guaranteed to be 100% accurate.  It performs a "best guess" based
# on a simple test of the first +File.blksize+ characters.
#
# Example:
#
#   File.binary?('somefile.exe') # => true
#   File.binary?('somefile.txt') # => fal...
How to cycle through grep results with vim
grep is the go-to CLI tool to accomplish tasks like filtering large files for arbitrary keywords. When additional context is needed for search results, you might find yourself adding flags like -B5 -A10 to your query. Now, every search result covers 16 lines of your bash.
There is another way: You can easily pipe your search results to the VIM editor and cycle through them.
Example: Searching for local occurrences of "User"
vim -q <(grep -Hn -r "User" .)
# vim -q starts vim in the "quickfix" mode. See ":help quickfix"
# grep...
How to migrate CoffeeScript files from Sprockets to Webpack(er)
If you migrate a Rails application from Sprockets to Webpack(er), you can either transpile your CoffeeScript files to JavaScript or integrate a CoffeeScript compiler to your new process. This checklist can be used to achieve the latter.
- If you need to continue exposing your CoffeeScript classes to the global namespace, define them on 
windowdirectly: 
-class @User
+class window.User
- Replace Sprocket's 
requirestatement with Webpacker's... 
The State of Ruby 3 Typing | Square Corner Blog
We're pleased to announce Ruby 3’s new language for type signatures, RBS. One of the long-stated goals for Ruby 3 has been to add type checking tooling. After much discussion with Matz and the Ruby committer team, we decided to take the incremental step of adding a foundational type signature language called “RBS,” which will ship with Ruby 3 along with signatures for the stdlib. RBS command line tooling will also ship with Ruby 3, so you can generate signatures for your own Ruby code.
Ruby 3 is coming, and it will have optional type sign...
Geordi 4 released
4.0.0 2020-07-30
Compatible changes
- Improved documentation; README now includes command options.
 - Improvement #90: geordi console, geordi deploy, geordi rake and geordi shell now work correctly if the project hasn't been bundled before
 - Use binstubs if present – breaks Geordi execution when a binstub is not working
 
Breaking changes
- Removed deprecated executables