Skip to content

Instantly share code, notes, and snippets.

View revans's full-sized avatar
🤠
Building Empires

Robert Evans revans

🤠
Building Empires
View GitHub Profile
@revans
revans / status_codes.rb
Last active January 19, 2018 23:27
Rails Status Codes
STATUS_CODES = {
100 => :continue,
101 => :switching_protocols,
102 => :processing,
200 => :ok,
201 => :created,
202 => :accepted,
203 => :non_authoritative_information,
204 => :no_content,
<form accept-charset="UTF-8" action="https://moonshine-app.herokuapp.com/f/abc" 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">
<ul>
<!-- <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>
config.middleware.use RoutesReloader
@revans
revans / table_hack.rb
Created December 17, 2015 21:27
Fun little hack that allows you to use 1 model to access any table in the database.
class Standin < ApplicationRecord
def self.set_table_name=(name)
self.table_name = name
end
def self.get_table_name
self.table_name
end
end
@revans
revans / ssh-open
Created November 30, 2015 23:22
SSH Config - Open HostNames in a Browser window
#!/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:
@revans
revans / README.md
Created November 30, 2015 20:12 — forked from wvengen/README.md
Ruby memory analysis over time

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

class Api::UploadsController < ApiController
def create
@upload = Upload.new(upload_params)
ensure
clean_tempfile
end
private
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# `RouteRecognizer.new.initial_path_segments`
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize
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]
# Instance Methods
class Demo
def say_hi
puts "hi"
end
end
Demo.new.say_hi # => 'hi'