typescript
typescript
git
How to remove a committed file from Git history forever
Committed an .env file with secrets to Git? Three steps remove it from history forever: add it to .gitignore, rewrite every commit with git filter-branch, then git push --force the cleaned history. Exact commands included, plus what the rewrite does to your repository.
ruby
Add commit message validator using Ruby and Lefthook
Enforce consistent commit messages with a small Ruby script and Lefthook: a commit-msg hook that reads .git/COMMIT_EDITMSG, validates prefixes like feat, fix, or docs against a regex, and rejects bad messages before they land. Full script and Lefthook config included.
Latest
How to work with JSONB column in pure Ruby on Rails
JSONB columns in Ruby on Rails without extra gems: use store_accessor to read and write keys like normal attributes, set sensible defaults, and validate required keys with a small module. Practical code you can drop into a PostgreSQL-backed Rails app.
Demystifying and writing own DSL in Ruby by examples - a practical guide
Ruby DSLs demystified by building three of them: a Minitest-like test framework, a Rails-style routes definition, and an RSpec-like spec syntax. See how blocks, instance_eval, and Ruby metaprogramming turn plain classes into a friendly mini-language.
Painting 'Lady with a weasel' using genetic algorithms and Ractor parallelism in Ruby
Genetic algorithms meet Ruby Ractors: a script that repaints Lady with a Weasel generation by generation. Follow the full lifecycle (mutation, fitness scoring, crossover), see how Ractor parallelism speeds up scoring specimens, and view the final result.
Understanding Record type in Typescript
The Record utility type in TypeScript builds object types with fixed keys and value types. A worked example shows Record<Keys, Type> with union keys: restricting IDs to chosen literals and mixing User and AdminUser values, so the compiler flags missing or extra entries.
What is ETag and how to use it in Rails for caching?
ETags let browsers skip downloading content that has not changed. What entity tags are in HTTP, then the Rails caching toolkit: stale?, fresh_when, expires_in, expires_now, public requests, and http_cache_forever, each shown with a concrete controller example.
Adjusting padding bottom for navigation in iOS and Android
Bottom navigation sitting too close to the screen edge on iPhone X and newer? The fix for iOS and Android PWAs is the safe area: use CSS env(safe-area-inset-bottom) to adjust the bottom padding so the bar clears rounded corners and the home indicator.
Understanding the Singleton Pattern in Javascript
The Singleton pattern in JavaScript ensures one shared instance with a global access point. A practical implementation using an object literal and Object.freeze, a shared bucket example, and where a singleton fits: configuration, logging, or a central data store.
What is instance and class variable in Ruby?
Instance variables versus class variables in Ruby: what @ and @@ actually mean, why an @ variable set at the class level stays empty when read from an instance, and how @@ values are shared by every instance. Short code samples make each behavior easy to verify.
Extend, prepend and include in Ruby
Extend, prepend, and include in Ruby each add module code to a class differently: prepend puts the module before the class so its methods win, extend adds class methods, include adds instance methods. Short runnable examples show how each changes the method lookup chain.
Understanding anonymous functions: Blocks, Procs, and Lambdas in Ruby
Blocks, procs, and lambdas in Ruby all wrap code you can pass around, but they differ in how they check arguments and handle return. Implicit and explicit blocks with yield, building reusable procs, and when a lambda is the safer pick, all shown with runnable examples.
Understanding TypeScript Function Generators
TypeScript function generators can pause and resume execution, returning values one at a time instead of all at once. What generators are, how yield works in a simple example, and a practical number sum generator that shows where they beat regular functions.
Ruby Hash destruction like from Javascript world (and reconstruction)
Ruby hash destructuring can feel as smooth as JavaScript: the rightward pattern matching syntax extracts values from a hash in one line, renames them, destructures arrays, groups elements, and rebuilds hashes afterwards. Practical examples for cleaner Ruby code.
Powerful switch statement with pattern matching in Ruby
Pattern matching in Ruby turns case statements into a precise switch over data shapes: match and destructure hashes from an API response, combine several patterns in one branch, capture values across patterns, and validate configuration. Ruby 2.7+ syntax examples.
Finding the slowest tests in Minitest and Rspec using profiler
Slow test suites usually hide a few expensive tests. Minitest and RSpec both ship a built-in profiler: bin/rails test --profile and rspec --profile 10 list your slowest examples with execution times, so you know exactly which tests to optimize first.
How to simplify TypeScript types and reduce documentation overhead
TypeScript types with many optional fields need comments to explain what goes together. Discriminated unions fix that: split a Task type into per-status variants so invalid combinations fail to compile and the type documents itself. Before and after code included.
How to set up XML in Grape API
XML support in Grape API takes two steps: register the additional content_type so endpoints accept and return application/xml, then change the root element name of the XML output. Complete Ruby examples built around a products endpoint you can adapt to your API.
Multiple ways to execute a shell command via Ruby
Running shell commands from Ruby: system, backticks, exec, the IO class, spawn, and Open3.popen3 compared with pros and cons, from quick one-liners to capturing stdout, stderr, and exit status, so you can pick the right method for scripts and production code.
Solutions to paginate data in your databse and which one is the best
Database pagination goes beyond LIMIT and OFFSET: ROW_NUMBER(), the FETCH clause, and keyset pagination each behave differently as tables grow. SQL examples for every approach, why offsets get slow on big datasets, and a verdict on which method scales best.
Database shrading and database partitioning in Rails
Database sharding in Rails step by step: create a separate database per shard, wire them up in database.yml, and query across them. Plus how sharding differs from partitioning, with a native PostgreSQL partitioning example done through Rails migrations.
Sidekiq basic_fetch and super_fetch differences
Sidekiq basic_fetch vs super_fetch: open source Sidekiq fetches jobs with BRPOP and loses them when a process crashes, while Sidekiq Pro's super_fetch uses RPOPLPUSH with private per-process queues to recover orphaned jobs. What that means for queue reliability.