Skip to content

Instantly share code, notes, and snippets.

# here's a quick recipe to run a performance test
# with this method, you can:
#-> easily choose the examples you want included from your existing specs
#-> define the target number of total iterations you'd like, no limit
#-> tune the transaction mix by specifying frequency metadata for each example
#-> be happy that the transaction mix is fairly homogeneous over the test interval
# (ideally you'd run this with acceptance (webrat/capybara) specs, but you
# could employ this technique for any rspec test)
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@stevenkolstad
stevenkolstad / gist:2907545
Created June 10, 2012 22:30 — forked from walterdavis/gist:1301612
Convert MP3 to OGG during upload using Paperclip
module Paperclip
# Converts ogg audio for Firefox
class Ogg < Processor
attr_accessor :whiny
# Creates an Ogg from MP3
def make
src = @file
dst = Tempfile.new([@basename, '.ogg'])
@stevenkolstad
stevenkolstad / README.md
Created May 6, 2012 13:34 — forked from chrisbloom7/README.md
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@stevenkolstad
stevenkolstad / avatar_uploader.rb
Created May 6, 2012 12:56 — forked from kirs/avatar_uploader.rb
Validation of image dimensions with CarrierWave
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
@stevenkolstad
stevenkolstad / gist:2032275
Created March 13, 2012 22:37 — forked from moneill/gist:1005105
Sample mongoid.yml generated from rails g mongoid:config (app name is 'appy')
defaults: &defaults
host: localhost
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
development:
<<: *defaults
@stevenkolstad
stevenkolstad / nginx_rails_3_1
Created March 1, 2012 14:44 — forked from shapeshed/nginx_rails_3_1
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@stevenkolstad
stevenkolstad / attachment.rb
Created September 23, 2011 22:55 — forked from Paxa/attachment.rb
video encoder snippet
class Attachment < ActiveRecord::Base
belongs_to :post
mount_uploader :filename, PostAttachmentUploader
VIDEO_FORMATS = %W{ogv mp4 webm}
PREVIEW_FORMAT = "jpeg"
before_save :set_metas
after_create :start_encoding!, :if => :video?
<p>Welcome some email!</p>
<p>You can confirm your account through the link below:</p>
<p><a href="http://localhost/admin/confirmation?confirmation_token=KSwxjJyzEZAWK4rx24jh">Confirm my account</a></p>
@stevenkolstad
stevenkolstad / prepare.txt
Created May 25, 2011 20:21 — forked from fortuity/gist:452364
Application generator template modifies a Rails app to use Mongoid & Devise
# Application Generator Template
# Modifies a Rails app to use Mongoid & Devise.
# Usage: rails new app_name -m http://gist.github.com/raw/991845/prepare.txt
# If you are customizing this template, you can use any methods provided by Thor::Actions
# http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html
# and Rails::Generators::Actions
# http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
puts "Modifying a new Rails app to use Mongoid & Devise..."