Skip to content

Instantly share code, notes, and snippets.

def expand_url(url)
if url.first == '/'
url = request.protocol + request.host + (request.port=='80' ? '' : ":#{request.port}") + url
end
url
end
*.swo
*.swp
db/*.sqlite3
log/*.log
mkmf.log
nbproject
public/system/datas/*
tmp/*
#!/usr/bin/ruby
def git_branch
(%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* ([a-z0-9_]+)[[:space:]]+$/i, '\1')
end
def set_color color
"\033[#{color}m"
end
def print_result result
module Paperclip
class Attachment
def geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file(path(style))
end
end
end
ru:
devise:
sessions:
link: 'Войти'
signed_in: 'Вы вошли.'
signed_out: 'Вы вышли.'
unauthenticated: 'Вы должны войти или зарегистрироваться, прежде чем сможете продолжить.'
unconfirmed: 'Вы должны подтвердить Ваш аккаунт, прежде чем сможете продолжить.'
locked: 'Ваш аккаунт заблокирован.'
invalid: 'Неверный пароль или email.'
;(function($){
jQuery.fn.serializeJSON = function(){
var aData = $(this).serializeArray();
var result = {}
for(key in aData){
result[aData[key].name] = aData[key].value;
}
return result;
}
@sergio-fry
sergio-fry / jquery.extra.js
Created June 17, 2010 13:40
jquery.extra.js
;(function($){
jQuery.fn.serializeJSON = function(){
var aData = $(this).serializeArray();
var result = {}
for(key in aData){
result[aData[key].name] = aData[key].value;
}
return result;
}
#!/bin/sh
rsync -a --no-perms --no-owner --no-group -vz --exclude=".git" --exclude="*.swp" --exclude=".gitignore" --exclude="deploy.sh" ./ user@host:/path/to/htdocs/
@sergio-fry
sergio-fry / application_controller.rb
Created July 1, 2010 14:00
inherit_resources with cancan
class ApplicationController < ActionController::Base
# Add this to your application_controller
def self.authorized_inherited_resources
inherit_resources
before_filter :authorize_resource_with_cancan
define_method(:authorize_resource_with_cancan) do
case action_name.to_sym
when :new, :create
class Hash
def symbolize_keys!
self.each do |key, val|
self.delete(key)
if val.is_a? Hash
self[key.to_sym] = val.symbolyze_keys
elsif val.is_a? Array
self[key.to_sym] = val.map{|el| el.symbolyze_keys}
else