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'
@zoras
zoras / cygwin_setup.txt
Created July 28, 2011 17:22
install all the packages in cygwin
# install all the packages required for using ruby on rails in cygwin
# http://software.jessies.org/salma-hayek/cygwin-setup.html
# Cygwin is a Linux-like environment for MS Windows. You can read more about it on the Cygwin home page, but this page assumes you know what it is and have already decided that you want it. If you're a Unix user and you're stuck with a Win32 box, you probably do. It's quite a remarkable hack.
Download the Cygwin setup.exe from http://www.cygwin.com/setup.exe
# Packages
inetutils # telnet(1)
ncurses # see Terminator FAQ
openssh # SSH (client and server, though the server's not so great)
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 / ssh_snipets.bash
Created January 23, 2013 08:43
ssh snipets
deploy@li166-177:~$cd ~/.ssh/
deploy@li166-177:~/.ssh$ls -lh
deploy@li166-177:~/.ssh$ grep authorized_key /etc/ssh/sshd_config
#AuthorizedKeysFile %h/.ssh/authorized_keys
deploy@li166-177:~/.ssh$ vi authorized_keys
deploy@li166-177:~/.ssh$ ls -lh
deploy@li166-177:~/.ssh$ chmod 600 authorized_keys
deploy@li166-177:~/.ssh$ chmod 600 authorized_keys*
@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|