Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
# 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")
@virtualstaticvoid
virtualstaticvoid / delete_svn.sh
Created March 25, 2011 06:41
Delete ".svn" directories
#!/bin/sh
rm -rf `find . -type d -name .svn`
@virtualstaticvoid
virtualstaticvoid / schema_utils.rb
Last active September 25, 2015 07:47
Multi-schema support for migrations in Rails
#
# http://www.developerit.com/2010/05/07/creating-a-multi-tenant-application-using-postgresqls-schemas-and-rails
#
module SchemaUtils
def self.add_schema_to_path(schema)
conn = ActiveRecord::Base.connection
conn.execute "SET search_path TO #{schema}, #{conn.schema_search_path}"
end
def self.reset_search_path
@virtualstaticvoid
virtualstaticvoid / access_control.rb
Created March 26, 2011 15:28
Simple role based access control
module AccessControl
extend self
def configure(&block)
instance_eval(&block)
end
def definitions
@definitions ||= Hash.new
end
module ActiveSupport
module Callbacks
module ClassMethods
def define_callbacks(*callbacks)
config = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
callbacks.each do |callback|
class_attribute "_#{callback}_callbacks"
send("_#{callback}_callbacks=", CallbackChain.new(callback, config))
__define_runner(callback)
end
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
#!/bin/bash
# ***************************************************************
# Name: install_chef_client.sh
# Purpose: Install chef client and register with the chef
# server.
# Notes: This script must be run as root
# This script installs the chef repo in the /root home
# directory
# Assumes these files exist in the same directory:
# <-c input>.pem
# http://rubypond.com/blog/useful-flash-messages-in-rails
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def flash_messages
return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)}
formatted_messages = messages.map do |type|
content_tag :div, :class => type.to_s do
message_for_item(flash[type], flash["#{type}_item".to_sym])
end
@virtualstaticvoid
virtualstaticvoid / .irbrc
Created June 8, 2011 13:21 — forked from wtnabe/.irbrc
A model dumper for rails console ( Rails 3 or later ) and .irbrc for rails env
# -*- mode: ruby; coding: utf-8 -*-
if defined? Rails
railsrc = __FILE__ + '.rails'
load railsrc if File.exist? railsrc
envrc = File.join( Rails.root, '.irbrc' )
load envrc if File.exist? envrc
end
@virtualstaticvoid
virtualstaticvoid / iptables_rules.sh
Created June 14, 2011 08:58
25 Most Frequently Used Linux IPTables Rules Examples
# Modify this file accordingly for your specific requirement.
# http://www.thegeekstuff.com
# 1. Delete all existing rules
iptables -F
# 2. Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP