Today I Learned
Short, practical notes from the OOZOU team: quick lessons from daily engineering and design work.
Run Claude Code Fully Autonomously with a YOLO Alias
The --dangerously-skip-permissions flag lets Claude Code run commands and edit files without confirmation prompts. Typing it every time gets old fast.
Run a command on your GNU/Linux dedicated Nvidia GPU (e.g. ollama)
To make sure a command (CLI) is using your NVIDIA GPU in GNU/Linux, you can use the environment variables \\NV\PRIME\RENDER\OFFLOAD=1 and \\GLX\VENDOR\LIBRARY\NAME=nvidiabefore your command.
Use Pundit Policies to manage permitted parameters, defaults and per action
To manage permitted params you can add permitted\attributes and permitted\attributes\for\#{action} in your policies e.g.
Use `requestSubmit` for form submits with Turbo
Turbo listens to submit events on form. Hence, always use requestSubmit to submit a form using JS.
Ignore bundled gems for Rubocop and ESLint in GitHub Actions
Rails projects will often install gems into the vendor directory in GitHub actions so we can cache them for the consecutive runs.
Add a macOS-style drop shadow to your "partial" screen captures or plain-bordered images
By default, and like it or hate it, the macOS keystrokes to capture full app screen (⇧- ⌘- 5) will add a subtle drop shadow around your saved image. This can make it more visually appealing when…
Create monochrome screen using overlay layers covered with hue fill effect
Create monochrome screen using overlay layers covered with hue fill effect
Hold ⌥option while click & drag along an input field to adjust sizing
Hold ⌥option while click & drag along an input field to adjust sizing
git check-ignore
This command lets you debug if a certain file/path is ignored and, with the -v flag, it also shows you the matching exclude pattern (Docs).
Allow pasting multiline ruby blocks in Pry when using leading dot notation
We use leading dot notation a lot now e.g.
Rails 6, Ruby 3, Bootstrap 5 and Hotwire
Extending the blogpost from Bootrails with Hotwire: All the fancy new things (as of when I'm writing this TIL):
Convert Text Object to Title Case in Figma
You can set Text box property to convert everything into Title Case automatically (along with other common text cases)
Reduce Heroku Slug Size
First, install the Heroku Repo plugin:
Run incognito/private commands for Bash and Zsh
Simply put a space before the command and it won't be saved to ~/.bash\_history. E.g. qrencode -o out.png "Some secret text"
Convert SVG to PNG
On MacOS, install inkscape (with brew) and use it like this:
CMD+Click behaviour in Figma
Holding ⌘CMD+Left Clicking in Designer mode will select the deepest layer resides within that frame/group whilst doing so in inspector/developer mode will select the outermost object/frame/group…
Rails Cache-Control
For enabling setting cache-control headers of static assets and using a CDN on Heroku:
Upgrade postgres database with homebrew
To upgrade postgres you can run
Fix input on Heroku's rails console
If you end up pasting lots of lines into a rails console on Heroku (or else where), you might get issues with the lines "bleeding" into each other.
Heredoc without interpolation
Sometimes you want to use Ruby's Heredoc without interpolation ('#{....}'). You can do this by adding single dashes around your keyword:
Unique ID for DOM in Rails
Rails has many great view helpers, one of which is dom\id:*
Add new types to Rails 5 attributes API
The Rails 5 attributes API allows us to build form objects very easily.
Add spacers to your macOS app dock to make groups
Open term (or equivalent) and paste the following one-liner:
Amazon AWS S3 CLI copy with set perms
Open term (or equivalent) and paste the following:
Angry Docker Purge
If you receive No Space left error on Docker this the brute force solution:
Attaching file to ActiveStorage without HTTP
If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this.
Automagical Intermediate-level Hashtables in Ruby
All intermediate-level hashtables will be created automagically
Back up a file with same name + prefix
NOTE: Actually you can use !#:1 in every command 'cause that's last argument passed to a command.
Bash aliases and magic
I have a seperate file in my user folder named ~/.aliases. I use this to store all of my bash aliases. I use aliases a lot and add new ones regularly so I created a bash function to add new aliases…
Calculate anagrams in Elixir
For example:
Change Ruby version for single command with rbenv
You can switch Ruby version temporarily with rbenv local
Change system names on macOS
From term (or equivalent), copy and paste:
Change VS Code Go to definition to Cmd+Click
Just open your user settings JSON file and use this option:
Check for IKEA item availability
If you're waiting for an IKEA item to restock, here's a practical solution to stay updated automatically. This guide explains how to use a shell script to check IKEA's stock availability and get…
Check if command exists with shell script
Check if command exists with shell script
Chrome tab manipulation
Sometimes I want to go back to the last page I viewed while still keeping the same one open. You can very easily achieve this with shortcuts
Cleanup stale formulas on brew
Use brew cleanup to get some spaces back!
Create a Hash from an Enumerable (Rails 6.0)
New method allowing you to create a Hash from an Enumerable:
Create idempotent migrations
When you want to write destructive migrations please use if\exists: true when you’re trying to remove a table and check for a table existence when you want to add or remove a column…
Create your own git commands (aliases)
Ever wanted to shorten a git command? You can go with shell alilas for sure but you have to always include context so that you don't forget what each ailas stands for but you can define your own…
Delete already-merged branchs in Git
You can safelist more branches in egrep -v 'master|develop|foo|bar'
Delete merged git branches
Handy git command for deleting all local git branches that already merged git branch --merged | egrep -v "(^\\|master|dev)" | xargs git branch -d*
Destructuring assignment in JS
Simple ones javascript const [a, b, ...c] = [10, 20, 100,200] // a= 10, b=20, c=[100,200] const { first, second } = { first: 1, second: 2 } // first = 1, second = 2
Diff a local file with remote version in Git
Easily run the below command and get a diff version from the remote
Find a branch based on a commit
c198bb715 Make default expired description logic pretty `
Force push previous commit to repo
If you push some code and want to force push a previous commit you can do so with shell git push origin +commit\sha^:branch\name
Get current git branch name
Get current git branch name
Get the password of the wifi you're on
password: "!forHackers" `
Go through a file Git history (GUI)
Go through a file Git history (GUI)
How to Create an HTML Element with Attributes in One Line in JavaScript
When working on a JavaScript project, it's common to create HTML elements dynamically. Traditionally, you might use several lines of code to create an element and set multiple attributes…
How to find god objects in your project (Rails)
Go to your project root and cd into app/models (using CLI obviously) then run wc -lw \ | sort -u*
How to quit Vim
1. Install latest version of Vim 2. Open a file in Vim 3. ⌘-Q and close the terminal 4. Reopen terminal
How to really!! quit vim
In terminal
How to save a file with sudo in VIM
How to save a file with sudo in VIM
HTML forms that submit to another action
I've known for a long time that you can submit values with submit buttons so you can track which button was used to submit the form e.g.
If you want to override previously set order
If you want to override previously set order (even through default\_scope), use reorder() instead.
Improve Bundler performance
Level up your bundler performance by running bundler tasks concurrently in jobs:
Kill rails that got stuck
I'd like to kill rails running w/specific port. (My laptop running several rails servers. )
Kill unresponsive SSH session
Occasionally an SSH session may become unresponsive. If I put my laptop to sleep this happens fairly often. Rather than killing the tab you can use SSH Escape Characters to kill the session
Limited has_many associations
Limited has_many associations
List directory structure except one or more dirs
Ever wanted to display the structure of the current directory except or two directories?
List your model names
NOTE: RUBYOPT=-W0 avoids verbosity when running rails command which suppresses warnnings.
make a pr from command line using hub
install hub first with brew: brew install hub then use a simple command, like at the example below: hub pull-request -m "best pr ever" -b oozou:develop -h feature/awesome-improvements
My most used slack shortcuts
⌘-K(or T) to open the channel switcher (I navigate channels solely with this shortcut and have my slack set to hide all channels without new messages)
optional relation + RSpec w/shoulda-matchers
User 1 - 0..1 Laptop
Postgres Functions & Non-sargable Queries
Using postgres functions inside a where clause can make a query non-sargable.
PostgreSQL UPDATE Join
This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;
Quickly move lines up and down in any Vim mode
I often move lines around in vim so I have created mappings to make this easier. These map to ⌘-j for move down and ⌘-k for move up. Works in normal, insert, and visual modes. vim nnoremap <D-j> :m…
Remove ruby 2.6 bundled bundler
Generating a rails 6 app with ruby 2.6+ when you have bundler v2 installed creates unusable binstubs. If you are seeing this error You must use Bundler 2 or greater with this lockfile. you can remove…
Remove unwanted commit from your branch
Remove unwanted commit from your branch
Rename files in VIM
Here's a handy function that I use to rename files in VIM (works in MacVIM and Neovim too)
Reset Postgres table sequence after DELETE
When deleting recent records from a table, you can reset it's sequence counter if auto-increment field continuity is important to you. Consider actions on the following table, users:
Restore a deleted file in Git
Restore a deleted file in Git
Run rubocop against your current branch
Run rubocop against your current branch
Run rubocop before commit
Git hooks are super powerful for automating tasks and enforcing coding standards in a Git repository. One common use case for Git hooks is to run automated tests and code analysis tools before…
Run same command on different input/inputs
If you have to run the same command repetitively over different input/inputs.
Scope or scope in Rails
scope :human, -> { user.or(author) } scope :terminator, -> { admin.or(robot) } `
See deleted files in previous commits [git]
See deleted files in previous commits [git]
Send messages to Slack using cURL
Slack allows you to send messages via the Webhooks service
Shallow clone a old repo
If you don't need the full git history for a repo you will be working on you can supply a clone depth to only clone x revisions of the repo.
Show TODO and other notes in your Rails app
Did you know you can show all TODOs/OPTIMIZE/FIXME in your rails app with rails notes?
Simple Flux architecture with Vue.js
For a small app that only needs a simple state management pattern. I always use one component to hold the state of the app, a container. This act as a single source of truth for an app to refer to…
Suppress rspec warnings
$ RUBYOPT=W0 bundle exec rspec spec/ ...
Tag rails logs with useful information
Just learned about tagged logging in rails. Did you know you can tag a log by using
Use capital letters in VIM mappings
NOTE: @joe this solves your problem :D
Use FFmpeg and Apple Script to compress videos
Build an application you can drag-and-drop videos onto to compress them significantely:
Use `host` to get more information about domains
You might be using dig to find out A/CNAME/MX etc records of a domain from DNS servers. But if you just want to get a quick overview, use host:
Use minItems/maxItems in collection JSON schemas
To make your collection JSON schemas more reilable use minItems and maxItems so that you can trust your API.
Use Neovim as a git difftool
Just paste this into your ~/.gitconfig
Using Git's aliases feature
Git allows you to create aliases internally through the config. Your global config should be located here ~/.gitconfig
Watch CI status on Github
When you have Github's hub installed, you can get the ci-status of your current branch like this:
You can use FactoryBot for non ActiveRecord models
You can use FactoryBot's initialize\with* method to initialize an object any way you like which allows you to factorize any of your objects at will
Zsh function to list file tree
When navigating through directories on the command line, it’s often helpful to see the structure of directories and subdirectories in a "tree" format. While there are plenty of tools out there, such…