Today I Learned

Quick tips, tricks, and discoveries from my daily coding adventures

Ruby's dig method for safe nested hash access

Use `dig` to safely navigate nested hashes without worrying about nil values: ```ruby user_data = { user: { profile: { name: 'John' } } } user_data.dig(:user, :profile, :name) # => 'John' us...

CSS Grid minmax() for responsive layouts

Create responsive grids without media queries: ```css .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; } ``` This automatically adjusts the ...

Git's --fixup and --autosquash for clean commits

Fix previous commits easily: ```bash # Create a fixup commit git commit --fixup HEAD~2 # Then rebase with autosquash git rebase -i --autosquash HEAD~3 ``` Git automatically reorders and marks...

Rails delegate method for cleaner code

Instead of creating pass-through methods, use delegate: ```ruby class Post < ApplicationRecord belongs_to :user # Instead of: # def username # user.name # end # Use: de...

PostgreSQL's EXPLAIN BUFFERS for query analysis

Get detailed information about query performance: ```sql EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM posts WHERE published = true; ``` This shows buffer usage, helping identify if queries are hi...