Skip to content

Instantly share code, notes, and snippets.

View zerobearing2's full-sized avatar

Dave Bradford zerobearing2

View GitHub Profile
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@RandomEtc
RandomEtc / 1-make-key
Created September 16, 2011 16:35
generating SSL keys and Certificate Signing Requests for Heroku / Nginx / RapidSSL
Key was generated using:
tom% openssl genrsa -des3 -out example.com.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
..........................................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for example.com.key:
Verifying - Enter pass phrase for example.com.key:
%tom
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@vvalgis
vvalgis / gems_install.rb
Created November 23, 2011 11:28 — forked from sshirokov/gemit.rb
Install gems from a gem list dump
#!/usr/bin/env ruby
#gem_cmd = ENV["GEM_CMD"] || 'sudo gem'
gem_cmd = 'gem'
STDIN.map { |l| l.strip }.each { |l|
gem, versions = l.split(' ', 2)
versions = versions.gsub(/[\(\)]/, '').split(', ')
versions.each { |version|
cmd = "#{gem_cmd} install #{gem} -v #{version} --no-ri --no-rdoc"
@bgentry
bgentry / sequel_paranoia.rb
Created November 30, 2011 03:20
Sequel Paranoia plugin (i.e. acts_as_paranoid)
module Sequel
module Plugins
# The paranoia plugin creates hooks that automatically set deleted
# timestamp fields. The field name used is configurable, and you
# can also set whether to overwrite existing deleted timestamps (false
# by default). Adapted from Timestamps plugin.
#
# Usage:
#
# # Soft deletion for all model instances using +deleted_at+
@benfyvie
benfyvie / object_diagnostics.rb
Created December 22, 2011 17:30 — forked from eric/object_diagnostics.rb
Tools for debugging memory bloat using Ruby's built in ObjectSpace
module ObjectDiagnostics
extend self
#This is handy when you want to determine what types of objects are contributing to memory bloat
#returns the change in object counts since the last time this method was called
def change_in_object_counts
#this will start all counts at 0 for the initial run
@previous_counts ||= Hash.new(0)
@ahoward
ahoward / ruby.rb
Created February 7, 2012 06:34
/usr/bin/ruby # wraps system installed rbenv (available during ubuntu boot)
#! /bin/sh
# file: /usr/bin/ruby
#
# the normal 'rbenv global 1.9.3-p0' will affect this script but, unlike having *only* rbenv, this ruby will be available at low run levels (aka, for init scripts)
export RBENV_ROOT="/usr/local/rbenv"
export PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

@revans
revans / yaml_objects.rb
Created September 24, 2012 22:08
Yockeries - Factories and Mocks from YAML
# Yockeries - Yaml + Mocks + Factories(easy way to create them)
#
# Long ago there was an uprising against YAML fixtures in the rails world. Some
# people replaced them with things like FactoryGirl, Machinist, Fabrication, and a
# bunch of others.
#
# However, YAML is still the simpliest thing that works, because it comes with
# Ruby. When you load in a yaml file with YAML.load_file, the yaml data is
# converted into a hash, which again is simple to use and test. You can take
# that hash and create a new object with it: Person.new(yaml_converted_hash),