Skip to content

Instantly share code, notes, and snippets.

View zoras's full-sized avatar
🏠
Working remotely 🌏 Available for Hire

Saroj Maharjan zoras

🏠
Working remotely 🌏 Available for Hire
View GitHub Profile
@zoras
zoras / custom-html-attributes-in-options-for-select.md
Created September 28, 2023 05:26
Custom HTML attributes in options_for_select

The Rails documentation doesn't seem to mention this, but it's possible to add your own custom HTML attributes to the option tags generated using options_for_select

In our case, we wanted to add custom HTML5 data attributes to our options tags we could use unobtrusive javascript to notice when the the user made a new selection and update another part of the page with the contents of the selected option tag's data attribute

I found someone else actually recommend doing a copy/paste/rewrite of options_for_select, but if you dig into the Rails code a bit you'll find this is totally unnecessary. This is from form_options_helper.rb

  • the two methods that get called on each element of the array you pass to
@zoras
zoras / .solargraph.yml
Created November 14, 2022 21:17 — forked from searls/.solargraph.yml
My config with steps to use solargraph for Rails projects in VS Code (WIP)
---
include:
- ".solargraph_definitions.rb"
- "app/**/*.rb"
- "config/**/*.rb"
- "lib/**/*.rb"
exclude:
- test/**/*
- vendor/**/*
- ".bundle/**/*"
source 'https://rubygems.org'
gem 'rspec'
For bundler I did the following on Catalina
$ brew install v8@3.15
$ gem install libv8 -v 3.16.14.15 -- --with-system-v8
$ gem install therubyracer -v 0.12.2 -- --with-v8-dir=/usr/local/Cellar/v8@3.15/3.15.11.18_1
$ bundle install
@zoras
zoras / devops_training.txt
Created November 28, 2019 08:50 — forked from ssmythe/devops_training.txt
Training materials for DevOps
======
Videos
======
DevOps
What is DevOps? by Rackspace - Really great introduction to DevOps
https://www.youtube.com/watch?v=_I94-tJlovg
Sanjeev Sharma series on DevOps (great repetition to really get the DevOps concept)
@zoras
zoras / ruby-predefined
Created July 5, 2019 05:40 — forked from amingilani/ruby-predefined
A list of constants and variables predefined in Ruby.
$! --- The exception information message set by 'raise'.
$@ --- Array of backtrace of the last exception thrown.
$& --- The string matched by the last successful match.
$` --- The string to the left of the last successful match.
$' --- The string to the right of the last successful match.
$+ --- The highest group matched by the last successful match.
$1 --- The Nth group of the last successful match. May be > 1.
$~ --- The information about the last match in the current scope.
$= --- The flag for case insensitive, nil by default.
$/ --- The input record separator, newline by default.
@zoras
zoras / bench_rails_memory_usage.rb
Created September 3, 2018 10:30 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@zoras
zoras / enumerator_to_json.rb
Created September 3, 2018 10:29 — forked from brianhempel/enumerator_to_json.rb
Lazily convert an Enumerator or Enumerator::Lazy to a JSON array. Save as config/initializers/enumerator_to_json.rb
# Natively, Enumerators get JSONized like "#<Enumerator::Lazy:0x007f8714807080>", or they explode, either of which is a problem.
# We want them to make an array, and do it lazily so we don't have to keep the items in memory!
class Enumerator
def to_json(state)
state.depth += 1
string = "[\n"
first_item = true
self.each do |item|
@zoras
zoras / git_branch_naming.md
Created May 15, 2018 08:20 — forked from revett/git_branch_naming.md
Git Branch Naming Conventions

<type>/<name>

<type>

bug    - Code changes linked to a known issue.
feat   - New feature.
hotfix - Quick fixes to the codebase.
junk   - Experiments (will never be merged).