Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Watermasysk scottwater

View GitHub Profile
View Gemfile
source :gemcutter
gem 'sinatra', '1.1.0', :git => 'http://github.com/sinatra/sinatra.git'
gem 'RedCloth', '4.2.3'
View gist:624070
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 .
}
View blah.cs
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;
View gist:732163
public class BaseClass
{
public string STRING { get { return "Base"; } }
}
public class ChildClass : BaseClass
{
public new string STRING { get { return "Child"; } }
}
View name.rb
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 Apr 7, 2011
Cookies Don't Seem To Work in RSpec
View posts_controller.rb
class PostsController < ApplicationController
def index
cookies[:index] = "INDEX"
session[:index] = "INDEX"
end
end
@scottwater
scottwater / secure_resqueue_server_1.rb
Created Apr 13, 2011
Quick samples on securing Resque::Server
View secure_resqueue_server_1.rb
require 'resque/server'
class SecureResqueServer < Resque::Server
before do
redirect '/' unless some_condition_is_met!
end
end
View dummy.rb
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 Apr 26, 2011
A really simple general purpose mail queue for resque
View mail_queue.rb
module MailQueue
extend self
def queue
:default
end
def perform(options = {})
options = options.with_indifferent_access
@scottwater
scottwater / kapow.zsh
Created May 13, 2011 — forked from csexton/kapow.zsh
Zsh function to restart an app running under pow
View kapow.zsh
# 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.
#
You can’t perform that action at this time.