Skip to content

Instantly share code, notes, and snippets.

#
# Paperclip convert id => id_partition
#
require 'fileutils'
class PaperclipExtend
def self.obtain_class
class_name = ENV['CLASS'] || ENV['class']
uploads_path = ENV['UPLOADS_PATH'] || ENV['uploads_path']
raise "Must specify CLASS" unless class_name
@ingeniarius
ingeniarius / 0. nginx_setup.sh
Created July 10, 2012 14:11 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# download and build nginx from sources
https://gist.github.com/3083579
@ingeniarius
ingeniarius / setup_ruby19.sh
Created July 10, 2012 09:28
Install Ruby 1.9.x on Ubuntu from sources
echo "Install Ruby..."
sudo apt-get update
sudo apt-get install build-essential libssl-dev zlib1g-dev libreadline-dev
export ruby_version=1.9.3-p194
cd /usr/src
sudo wget "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-$ruby_version.tar.bz2"
sudo tar xf "./ruby-$ruby_version.tar.bz2"
sudo rm "./ruby-$ruby_version.tar.bz2"
@ingeniarius
ingeniarius / gist:2924959
Created June 13, 2012 15:57
DCI yet another approach
class User < ActiveRecord::Base
end
class Book < ActiveRecord::Base
end
module CustomerRole
end
class AddToCartContext
@ingeniarius
ingeniarius / nginx.conf
Created March 12, 2012 19:33
nginx upstart config
# nginx
description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/usr/sbin/nginx
env PID=/var/run/nginx.pid
@ingeniarius
ingeniarius / gist:1916625
Last active October 1, 2015 04:07
Disable rails 4 asset log messages
Rails::Rack::Logger.class_eval do
def call_app(request, env)
path = request.filtered_path
unless path.index("/assets/") == 0
# Put some space between requests in development logs.
if development?
logger.debug ''
logger.debug ''
end
@ingeniarius
ingeniarius / string_inquirer_patch.rb
Created February 24, 2012 19:56
Creation of inquirer methods on the fly for performance boost
module ActiveSupport
module StringInquirerPatch
def self.included klass
klass.send :remove_method, :method_missing
end
def method_missing method_name, *arguments
if method_name.to_s[-1,1] == "?"
is_eql_to_self = (self == method_name.to_s[0..-2])
@ingeniarius
ingeniarius / rails_guides_to_epub.rb
Created October 26, 2011 15:41 — forked from spap/rails_guides_to_epub.rb
Ruby on Rails Guides ePub convert ruby script
require 'rubygems'
require 'nokogiri'
require 'eeepub'
DOC_TITLE = 'Ruby on Rails Guides'
def get_pages(src_dir)
index_file = File.join(src_dir, 'index.html')
section = nil
pages = [{ :section => section, :title => DOC_TITLE, :path => index_file }]
@ingeniarius
ingeniarius / error output
Created September 25, 2011 07:35
Socket.IO benchmark
/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610
transport.payload(this.closed[data.id]);
^
TypeError: Object #<WebSocket> has no method 'payload'
at Manager.handleClient (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610:19)
at Manager.handleUpgrade (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:564:8)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:100:10)
at HTTPServer.emit (events.js:81:20)
at Socket.<anonymous> (http.js:1035:14)
at Socket._onReadable (net.js:683:27)
@ingeniarius
ingeniarius / american_date_monkey_patch.rb
Created September 9, 2011 11:21 — forked from ptzn/american_date_monkey_patch.rb
Use american date format as default in Ruby 1.9
# Date.parse() with Ruby 1.9 is now defaulting to the European date style where the format is DD/MM/YYYY, not MM/DD/YYYY
# patch it to use US format by default
if RUBY_VERSION >= '1.9'
class String
def to_date
if self.blank?
nil
elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
::Date.civil($3.to_i, $1.to_i, $2.to_i)
else