Skip to content

Instantly share code, notes, and snippets.

View tejasbubane's full-sized avatar
💭
WFH 🏡

Tejas Bubane tejasbubane

💭
WFH 🏡
View GitHub Profile
@tejasbubane
tejasbubane / safelist_per_api_key.rb
Last active April 11, 2025 16:04
Add IP restriction on Rack app for specific accounts
# frozen_string_literal: true
# Read the blog:
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rack-attack", "~> 6.7.0"
@tejasbubane
tejasbubane / pattern_matching_custom_objects.rb
Created April 6, 2025 17:27
Pattern matching on custom objects in Ruby
require "minitest/autorun"
require "minitest/spec"
class Event
attr_reader :name, :venue
def initialize(name, venue)
@name = name
@venue = venue
end
@tejasbubane
tejasbubane / postgresql_database_constraints.rb
Last active March 25, 2025 18:57
PostgreSQL database constraints in Rails
# frozen_string_literal: true
# Read the blog: https://tejasbubane.github.io/posts/using-postgres-database-constraints-in-rails/
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@tejasbubane
tejasbubane / sidekiq_nested_test.rb
Created January 20, 2022 19:47
Testing nested workers in sidekiq
# Prepared for https://stackoverflow.com/questions/70790708/testing-enque-of-nested-worker-from-another-sidekiq-worker
require 'sidekiq'
require 'sidekiq/testing'
require 'rspec'
class WorkerOne
include Sidekiq::Worker
def perform(arg_1, arg_2)
@tejasbubane
tejasbubane / generated_columns.rb
Last active December 30, 2021 08:20
Postgres generated columns
# frozen_string_literal: true
# Read the blog: https://tejasbubane.github.io/posts/2021-12-18-rails-7-postgres-generated-columns/
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@tejasbubane
tejasbubane / identical_equality_offenses.txt
Created February 21, 2021 11:53
Offenses for `RSpec/IdenticalEqualityAssertion` on https://github.com/pirj/real-world-rspec
Offenses:
brew/Library/Homebrew/test/pkg_version_spec.rb:20:5: C: RSpec/IdenticalEqualityAssertion: Identical expressions on both sides of the equality may indicate a flawed test.
expect(described_class.parse("1.0_1")).to be == described_class.parse("1.0_1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
canvas-lms/gems/adheres_to_policy/spec/adheres_to_policy/class_methods_spec.rb:51:5: C: RSpec/IdenticalEqualityAssertion: Identical expressions on both sides of the equality may indicate a flawed test.
expect(@some_class.policy).to eql(@some_class.policy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
canvas-lms/spec/controllers/gradebooks_controller_spec.rb:2883:7: C: RSpec/IdenticalEqualityAssertion: Identical expressions on both sides of the equality may indicate a flawed test.
expect(@controller.post_grades_ltis).to eq(@controller.post_grades_ltis)
@tejasbubane
tejasbubane / arch-cleanup.sh
Created December 19, 2020 19:28
Arch system maintenance
# No need to run this everyday - once a month should be fine
# Remove cache:
sudo pacman -Scc
yay -Scc
# Remove unwanted dependencies:
yay -Yc
# Remove orphan packages
@tejasbubane
tejasbubane / test.rb
Created December 10, 2019 10:31
Rails single-table inheritance issue reproduction
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
@tejasbubane
tejasbubane / haskell_uninstall.sh
Last active December 2, 2019 07:17
Uninstall all haskell version
# Thanks to this mailing list message: https://mail.haskell.org/pipermail/haskell-cafe/2011-March/090170.html
# Note: This removes ALL haskell versions & anything related to it
sudo rm -rf /Library/Frameworks/GHC.framework
sudo rm -rf /Library/Frameworks/HaskellPlatform.framework
sudo rm -rf /Library/Haskell
rm -rf .cabal
rm -rf .ghc
rm -rf ~/Library/Haskell
find /usr/bin /usr/local/bin -type l | \
@tejasbubane
tejasbubane / middleware.rb
Last active November 13, 2019 09:10
Unit testing rack middlewares
# Make sure rack & rspec are installed -> gem install rack rspec
# Run this script using rspec -> rspec middleware.rb
require 'rack'
class BlockActions
def initialize(app)
@app = app
end