Instantly share code, notes, and snippets.

View demo.rb
# ruby 2.5.0p0 (2017-12-25 revision 61468)
class Demo
attr_reader :first_name
def initialize(first_name)
@first_name = first_name
def hi(myname = nil)
puts "Hello, #{first_name}"
View status_codes.rb
100 => :continue,
101 => :switching_protocols,
102 => :processing,
200 => :ok,
201 => :created,
202 => :accepted,
203 => :non_authoritative_information,
204 => :no_content,
View form.html
<form accept-charset="UTF-8" action="" method="POST" id="contact-form">
<input type="hidden" name="utf-8" value="">
<input type="text" class="col-md-6 col-xs-12 name" name="name" placeholder="Name *" required="">
<input type="text" class="col-md-6 col-xs-12 Email" name="email" placeholder="Email *" required="">
<input type="text" class="col-md-12 col-xs-12 Subject" name="subject" placeholder="Subject">
<textarea type="text" class="col-md-12 col-xs-12 Message" name="body" placeholder="Message *" required=""></textarea>
<div class="cBtn col-xs-12">
<!-- <li class="clear"><a href="#"><i class="fa fa-times"></i>clear form</a></li> -->
<li class="send"><a href="#" onclick="document.getElementById('contact-form').submit();"><i class="fa fa-share"></i>Send Message</a></li>
View development.rb
config.middleware.use RoutesReloader
View table_hack.rb
class Standin < ApplicationRecord
def self.set_table_name=(name)
self.table_name = name
def self.get_table_name
View ssh-open
#!/usr/bin/env bash
# About:
# If you use ~/.ssh/config often enough that you cannot remember the URLs
# anymore, but you do know the SSH Host names you gave each SSH entry,
# then this might be helpful. This script will find the Host and open
# the HostName up in a new browser window, using your default browser.
# Installation:

Finding a Ruby memory leak using a time analysis

When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.

There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the

View uploads_controller.rb
class Api::UploadsController < ApiController
def create
@upload =
View rails_route_recognizer.rb
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# ``
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize
View hooks_controller.rb
require 'md5'
class Chargify::HooksController < ApplicationController
protect_from_forgery :except => :dispatch
before_filter :verify, :only => :dispatch
EVENTS = %w[ test signup_success signup_failure renewal_success renewal_failure payment_success payment_failure billing_date_change subscription_state_change subscription_product_change ].freeze
def dispatch
event = params[:event]