Skip to content

Instantly share code, notes, and snippets.

View mattpolito's full-sized avatar

Matt Polito mattpolito

View GitHub Profile
class PagesController < ApplicationController
before_filter :login_required, :except => [ :show ]
# GET /pages
# GET /pages.xml
def index
@pages = Page.find(:all)
respond_to do |format|
format.html # index.html.erb
# 1. Create dirs for unpacking your source code and installing your apps
mkdir $HOME/src
mkdir $HOME/apps
# 2. Install the latest version of git
cd $HOME/src
wget http://kernel.org/pub/software/scm/git/git-1.6.2.tar.gz
tar zxvf git-1.6.2.tar.gz
cd git-1.6.2
./configure --prefix=$HOME/apps NO_MMAP=1
# Patch Paperclip reprocess! and to_file methods to use binary mode (for Windows compatibility)
# Fixup content type on assignment
# Ensure the :original style is always processed first
module Paperclip
module Storage
module Filesystem
def to_file style = default_style
@queued_for_write[style] || (File.new(path(style), 'rb') if exists?(style))
end
alias_method :to_io, :to_file
# Patch Paperclip reprocess! and to_file methods to use binary mode (for Windows compatibility)
# Fixup content type on assignment
# Ensure the :original style is always processed first
module Paperclip
module Storage
module Filesystem
def to_file style = default_style
@queued_for_write[style] || (File.new(path(style), 'rb') if exists?(style))
end
alias_method :to_io, :to_file
class ImageModelsController < ApplicationController
before_filter :find_image_model, :only => [:update]
def update
if @image_model.update_attributes(params[:image_model])
@image_model.image.reprocess!
end
end
protected
# When a spammer wants to attack your site, they'll likely send an automated bot
# that will blindly fill out any forms it encounters. The idea of a "honeypot" is that
# you place a hidden field in a form. That's the honeypot. If this field is filled in, then
# it's almost certain to be a spammer (since a normal user wouldn't have even seen the
# field), and the contents of the form can safely be discarded.
# Normally, you would implement a "honeypot" in a Rails app with some combination of a
# special field in a particular form, and then some logic in the corresponding controller that
# would check for content in the "honeypot" field. This is somewhat of an inefficient
# approach, because it requires special code (not DRY), and bots are still going through an
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
verb = route.conditions[:method].to_s.upcase
segs = route.segments.inject("") { |str,s| str << s.to_s }
segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
// only outputs if console available and does each argument on its own line
function log() {
if (window && window.console && window.console.log) {
var i, len;
for (i=0, len=arguments.length; i<len; i++) {
console.log(arguments[i]);
}
}
}