Skip to content

Instantly share code, notes, and snippets.

View supairish's full-sized avatar
🏂
Shreddin

Chris Irish supairish

🏂
Shreddin
View GitHub Profile
@supairish
supairish / gist:1033379
Created June 18, 2011 18:32 — forked from bgkittrell/gist:704674
Reorder Multiple Elements ala Netflix
images = @album.image_assignments
changed = Array.new
# Get the images that changed order
for image in images
order = params["order_#{image.image_id}".to_sym]
if !order.blank? && order =~ /^\d+$/ && image.position.to_i != order.to_i
image.position = order.to_i
changed << image
@supairish
supairish / gist:1330161
Created November 1, 2011 08:37
Retryable method
# Options:
# * :tries - Number of retries to perform. Defaults to 1.
# * :on - The Exception on which a retry will be performed. Defaults to Exception, which retries on any Exception.
#
# Example
# =======
# retryable(:tries => 1, :on => OpenURI::HTTPError) do
# # your code here
# end
#
@supairish
supairish / gist:1521680
Created December 26, 2011 17:25 — forked from parndt/gist:1011435
How to cache pages and clear them in Refinery CMS
# put in config/application.rb
config.to_prepare do
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!
@supairish
supairish / arel_or.rb
Created January 30, 2012 08:16 — forked from philsmy/arel_or.rb
or scopes - add this to your model to be able to or scopes together (eg: Model.or(Model.scope1, Model.scope2). Stolen and adapted from fake_arel
__or_fn = lambda do |*scopes|
where = []
joins = []
includes = []
# for some reason, flatten is actually executing the scope
scopes = scopes[0] if scopes.size == 1
scopes.each do |s|
w = []
s.where_clauses.each do |where_clause|
@supairish
supairish / gist:2017691
Created March 11, 2012 19:03
Capybara Click At
Capybara::Node::Element.class_eval do
def click_at(x, y)
wait_until do
right = x - (native.size.width / 2)
top = y - (native.size.height / 2)
driver.browser.action.move_to(native).move_by(right.to_i, top.to_i).click.perform
end
end
end
@supairish
supairish / ubuntu_steps.sh
Created March 25, 2012 04:05 — forked from johnrees/_ubuntu_steps.sh
Standard Rails 3.* setup for Ubuntu 10.04 LTS 32
# As root user
# Update the OS
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
# Setup Hostname & TimeZone
echo "{{HOSTNAME}}" > /etc/hostname
hostname -F /etc/hostname
dpkg-reconfigure tzdata
@supairish
supairish / application.rb
Created May 18, 2012 00:18 — forked from steve9001/application.rb
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@supairish
supairish / installation.sh
Created June 6, 2012 16:56 — forked from mikhailov/installation.sh
nginx+passenger (real production config)
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.0.15.tar.gz
$ tar xzvf ./nginx-1.0.15.tar.gz
$ rm -f ./nginx-1.0.15.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
$ tar xzf openssl-1.0.1c.tar.gz && rm -f openssl-1.0.1c.tar.gz
@supairish
supairish / gist:2951524
Created June 18, 2012 23:58
Nginx - how to limit requests by User Agent
http {
map $http_user_agent $limit_bots {
default '';
~*(google|bing|yandex|msnbot) $binary_remote_addr;
}
limit_req_zone $limit_bots zone=bots:10m rate=1r/m;
server {
namespace :attachments do
task :migrate_to_s3 => :environment do
require 'aws/s3'
# Load credentials
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys
bucket = s3_options[:bucket_name]
# Establish S3 connection