Skip to content

Instantly share code, notes, and snippets.

View shivabhusal's full-sized avatar

Shiva B. shivabhusal

View GitHub Profile
@shivabhusal
shivabhusal / rails-rails-view-template-test.rb
Created November 28, 2025 09:33
ERB partial locals parsing fails when locals comment spans multiple lines https://github.com/rails/rails/issues/56239
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'pry'
gem "rails", '~> 7.2.2.2'
# If you want to test against edge Rails replace the previous line with this:
# gem "rails", github: "rails/rails", branch: "main"
@shivabhusal
shivabhusal / notes-git-tutorial.md
Created September 26, 2023 06:33
Best Git Tutorial Links for Beginners

Title: Best Git Tutorial Links for Beginners

Are you new to Git and looking for the best resources to kickstart your journey into version control and collaborative software development? You're in luck! Git is a powerful tool used by developers worldwide, and there are numerous tutorials available to help you get started. To make your search easier, we've compiled a list of some of the best Git tutorial links for beginners.

  1. Beginner's Guide for Git by Shiva

    Shiva's comprehensive guide provides a step-by-step introduction to Git, making it an excellent starting point for beginners. You'll learn the basics of Git, including how to set it up, create repositories, and perform essential version control tasks.

  2. Git Documentation

@shivabhusal
shivabhusal / template.rb
Created July 9, 2017 17:23
A Rails template to generate config/database.yml files for specific database like `mysql` , `sqlite`, `pg`. You may fork it and add support for other databases as well
# ------------------- MySQL -------------------------------
MYSQL_CONFIG = <<-MYSQL
default: &default
adapter: mysql2
encoding: utf8
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
<% if mysql_socket %>
socket: <%= mysql_socket %>
@shivabhusal
shivabhusal / test_setup_and_gem_install_template.rb
Last active April 16, 2019 16:59
A Rails template for generating boilerplate configs for any new Rails app; viz. rspec, factory_girl_rails, db-cleaner,annonote etc are preconfigured. It saves me an hour everytime.
gem 'slim-rails'
gem 'sassc-rails'
gem 'any_login'
gem 'active_model_serializers', '~> 0.10.0'
gem 'responders'
gem_group :development do
gem 'annotate'
end
@shivabhusal
shivabhusal / find_bug.rb
Last active June 27, 2017 11:49
Run this code in your machine and find the bug
class Roulette
def method_missing(name, *args)
person = name.to_s.capitalize
3.times do
number = rand(10) + 1
puts "#{number}..."
end
"#{person} got a #{number}"
end
end
@shivabhusal
shivabhusal / include_class.rb
Last active June 23, 2017 17:30
Ruby creates an anonymous class with the name of the module you are including and puts it in the ancestors chain.
module Printable
def print(message)
puts message
end
end
class Animal
include Printable
def speak
print("##")
@shivabhusal
shivabhusal / string_refinement.rb
Created June 23, 2017 05:39
Using Refinements to monkey patch String class
module StringColorize
refine String do
def red
color_code = 31
"\e[#{color_code}m#{self}\e[0m"
end
def blue
color_code = 34
"\e[#{color_code}m#{self}\e[0m"
@shivabhusal
shivabhusal / opening_class_in_loop.rb
Last active June 21, 2017 16:47
class defn code is similar to normal code, but there is a little bit difference
3.times do
class A
puts "Class opened"
end
end
# => Class opened
# => Class opened
# => Class opened
@shivabhusal
shivabhusal / openclass_use_case.rb
Created June 21, 2017 16:07
# Some use case of OpenClass feature; Added color methods to String class
# Some use case of OpenClass feature
def red(string)
color_code = 31
"\e[#{color_code}m#{string}\e[0m"
end
def blue(string)
color_code = 34
"\e[#{color_code}m#{string}\e[0m"
end
@shivabhusal
shivabhusal / open_class_overwrite_when_old_object_case.rb
Last active June 21, 2017 15:28
What happens to existing behavior if older version object still exists
# What happens to existing behavior if older version object still exists
class MyClass
def print
puts 'This is still old behavior'
end
end
old_class = MyClass.new
# Modifying the original blue print or prototype