Skip to content

Instantly share code, notes, and snippets.

View scottwater's full-sized avatar

Scott Watermasysk scottwater

View GitHub Profile
source :gemcutter
gem 'sinatra', '1.1.0', :git => 'http://github.com/sinatra/sinatra.git'
gem 'RedCloth', '4.2.3'
function mkgemset() {
mkdir $1
echo 'source :gemcutter' > $1/Gemfile
touch $1/Rakefile
echo 'rvm_gemset_create_on_use_flag=1\nrvm gemset use' $1 > $1/.rvmrc
cd $1
git init
mate .
}
private static IEnumerable<AuditParameter> GetParametersFromEnumeration(IEnumerable args)
{
var parameters = new List<AuditParameter>();
foreach(var arg in args)
{
var iaudit = arg as IAuditableParameter;
if(iaudit != null)
{
parameters.Add(new AuditParameter {Value = iaudit.AuditParameter});
continue;
public class BaseClass
{
public string STRING { get { return "Base"; } }
}
public class ChildClass : BaseClass
{
public new string STRING { get { return "Child"; } }
}
def friendly_name(user)
temp_name = if user.first_name.blank? && user.last_name.blank?
user.email
elsif user.first_name.blank?
user.last_name
elsif user.last_name.blank?
user.first_name
else
"#{user.first_name} #{user.last_name}"
@scottwater
scottwater / posts_controller.rb
Created April 7, 2011 14:15
Cookies Don't Seem To Work in RSpec
class PostsController < ApplicationController
def index
cookies[:index] = "INDEX"
session[:index] = "INDEX"
end
end
@scottwater
scottwater / secure_resqueue_server_1.rb
Created April 13, 2011 14:08
Quick samples on securing Resque::Server
require 'resque/server'
class SecureResqueServer < Resque::Server
before do
redirect '/' unless some_condition_is_met!
end
end
Site.joins(:user).select('sites.user_id, count(*) as count').group('sites.user_id')
<Site user_id: 1> #should have a count of 2
# returns only the user_id. If I cheat and name the 'count' column the same name as another column on my model it returned.
Site.joins(:user).select('sites.user_id, count(*) as id').group('sites.user_id') #BAD!
<Site id: 2, user_id: 1> #id == count in this result
@scottwater
scottwater / mail_queue.rb
Created April 26, 2011 14:24
A really simple general purpose mail queue for resque
module MailQueue
extend self
def queue
:default
end
def perform(options = {})
options = options.with_indifferent_access
@scottwater
scottwater / kapow.zsh
Created May 13, 2011 04:33 — forked from csexton/kapow.zsh
Zsh function to restart an app running under pow
# Restart a rack app running under pow
# http://pow.cx/
#
# Adds a kapow command that will restart an app
#
# $ kapow myapp
# $ kapow # defaults to current directory
#
# Supports command completion.
#