MIT License
Copyright 2023 Maxim Chernyak
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Date
July 14, 2023
Links to this post
SaveIf concern for Rails optimistic locking without lock_version
I wrote a proposal for Rails to implement an optimistic locking feature that doesn’t require lock_version column. There are some use cases where
Camelize JSON keys in Rails
Works well with portrayal, and narrative Rails app design. Add to your lib/camelize_json_keys.rb, then require and use as needed. Code snippets in
Compiling Go binary for Linux when on a Mac with Apple Silicon
Code snippets in this post are covered by MIT License
Custom Puma executable for a Ruby app
Sometimes I don’t like having to create required files and directories. This executable can serve your app via puma without having to create
Good shell script template
The article Shell Script Best Practices (also saved in my History Book app) has a great template/explanation on how to write shell scripts. Code
Camelize (camel case) ruby string
First letter: upper First letter: lower See also: Underscore ruby strings Code snippets in this post are covered by MIT License
A way to enforce contracts in Portrayal rubygem
portrayal code, portrayal gem New way (based on version 0.9.0): https://gist.github.com/maxim/4dc1765d9f81ac849325d166d14d2dfa Blog post:
Inspect and install a deb package
Check meta info about a package: List files the package will create: Extract deb package into a local folder: Install the package with dependencies:
Helper for creating table and model in Rails tests
Here’s a simple method that you can throw into your test_helper.rb (or wherever helpers go in your test framework) that works correctly as of Rails
Iterate over sorted enumerables preserving order
Better optimized, no indexes Code snippets in this post are covered by MIT License
How my LaunchD demon was setup
I switched to crontab now, and it seems to work much better, but before I was trying to run periodic job with this daemon setup. From
Preferences for Rubocop ruby formatting
Canonical place for my up-to-date rubocop settings now lives in narrative Rails template repo. Code snippets in this post are covered by MIT License
Install command line tools on MacOS
Code snippets in this post are covered by MIT License
Transferring files over ssh with scp
Upload: Download: Note: add flag -C to compress files. Code snippets in this post are covered by MIT License
Underscore ruby strings
Code snippets in this post are covered by MIT License
Working with systemd units
Add new systemd service (will symlink your file): Remove existing systemd service (will remove symlinked files): Reload after changing your
Ruby barewords are insidious
The problem with ruby barewords is that you cannot tell by looking at them what’s going on in them. They hide whether something returns a stored
Support rails generator testing in Rspec
This goes into spec/support/generator_specs_support.rb: In spec/rails_helper.rb add the following: Specs should go into
GemPatch: monkeypatch rubygems responsibly
If you must extend or change a gem’s functionality, it’s a good idea to make sure that your change won’t break with the next update. There isn’t
Serve static files in Rails
This shows a way to mount a directory from which Rails will serve static files. By default, path/ will serve index.html if present. Code snippets in
Procfile.dev docker postgres
Start postgres in docker as a process in Procfile.dev Code snippets in this post are covered by MIT License
Find out RAM timings (like CAS) and manufacturer on Ubuntu
I honestly don’t know how this works, but got it from this SO answer. (The only one that worked for me.) P.S. Probably the same on Debian. Code
Assertion assert_enqueued_email_with with matcher support
I made a PR into Rails to add matcher support for assert_enqueued_email_with. Until that PR is merged, here’s a custom assertion
Print Rails db schema or structure
These simple bash functions let you conveniently see schemas of your Rails models by printing them from schema.rb or structure.sql files. schema