Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View revans's full-sized avatar
🤠
Building Businesses

Robert Evans revans

🤠
Building Businesses
View GitHub Profile
@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'
module Test
extend self
def name
@name ||= "My name"
end
def read
@name
end
@revans
revans / users_controller.rb
Last active August 29, 2015 14:14
Strong Params
class UserController < ApplicationController
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
...
else
...
end
@revans
revans / fixture_mock.rb
Created September 3, 2014 14:56
Rails Fixtures being used for Mocks
require 'ostruct'
require 'yaml'
#
# A quick and dirty example of something that could be inside of rails to provide
# a stupid simple mock for a model object that has an associated fixture.
#
# ==== Example
#
@revans
revans / demo.rb
Last active August 29, 2015 14:04
How to get the Next/Previous Record from an object. I'm using Rails 4.1.4, PostgreSQL 9.3.4 for the examples.
# Demo Database Object Schema:
#
# * name, string
# * status, integer
# * created_at, datetime
# * updated_at, datetime
#
class Demo < ActiveRecord::Base
include BaseScopes