Skip to content

Instantly share code, notes, and snippets.

View agibralter's full-sized avatar
:shipit:

Aaron Gibralter agibralter

:shipit:
View GitHub Profile
@chrisbloom7
chrisbloom7 / 01-validates-file-size-carrierwave.md
Last active November 18, 2024 16:56
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'

@jayzes
jayzes / Procfile
Created May 26, 2011 20:59
Thinking Sphinx and Foreman
sphinx: bundle exec rake ts:run_in_foreground
@MyArtChannel
MyArtChannel / development.rb
Created April 25, 2011 20:42
Use Pry as IRB replacement in rails 3 console
# Add this to the end of your development.rb and add
#
# gem 'pry'
#
# to your Gemfile and run bundle to install.
silence_warnings do
begin
require 'pry'
IRB = Pry
require 'rubygems'
require 'json'
require 'redis'
class RedisComments
def initialize(redis,namespace,sort_proc=nil)
@r = redis
@namespace = namespace
@sort_proc = sort_proc
end
var keyCodes = {
backspace: 8,
tab: 9,
enter: 13,
escape: 27,
left: 37,
up: 38,
right: 39,
down: 40,
delete: 46,
@gmarik
gmarik / expires_fix_2311.rb
Created April 4, 2011 22:13
:expire_after rails 2.3.11 workaround
# workaround for https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6634-railsrack-inconsistency-about-expires_afterexpires-cookie-option#ticket-6634-3
# expiration issue
# drop into RAILS_ROOT/config/initializers/expires_fix_2311.rb
#
require 'rack'
Rack::Utils.class_eval do
class << self
def set_cookie_with_expire!(header, key, value)
if value[:expires].blank? && value[:expire_after]
# Select only a sub-set of passed parameters. Useful for whitelisting
# attributes from the params hash before performing a mass-assignment.
def pick(hash, *keys)
filtered = {}
hash.each {|key, value| filtered[key.to_sym] = value if keys.include?(key.to_sym) }
filtered
end
require 'net/http'
require 'rubygems'
require 'nokogiri'
url = URI.parse 'http://memegenerator.net/Instance/CreateOrEdit'
res = Net::HTTP.post_form(url, {
'templateType' => 'AdviceDogSpinoff',
'text0' => ARGV[0],
'text1' => ARGV[1],
'templateID' => '165241',
@agibralter
agibralter / after_use
Created February 4, 2011 19:14
tmux ree script
#!/usr/bin/env bash
case "$rvm_ruby_string" in
ree*)
# export RUBY_HEAP_MIN_SLOTS=1000000
# export RUBY_HEAP_SLOTS_INCREMENT=1000000
# export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
# export RUBY_GC_MALLOC_LIMIT=1000000000
# export RUBY_HEAP_FREE_MIN=500000
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"