Skip to content

Instantly share code, notes, and snippets.

View hilios's full-sized avatar
🛠️
Breaking stuff

Edson Hilios hilios

🛠️
Breaking stuff
View GitHub Profile
@hilios
hilios / .htaccess
Created August 12, 2011 13:52
YSlow optimize DreamHost apache configuration (Gzip + Far late expire header)
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html M3600
ExpiresByType text/css M3600
ExpiresByType application/javascript M3600
ExpiresByType image/bmp M3600
ExpiresByType image/gif M3600
@hilios
hilios / email_validator.rb
Created August 24, 2011 20:10
Rails email validation
# http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp/
# lib/email_validator.rb
require 'mail'
module ActiveModel
module Validations
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain and that value is an email address
@hilios
hilios / .bash_profile
Last active September 27, 2015 04:48
Default configuration for bash
# ~/.bash_profile: executed by bash(1) for login shells.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
@hilios
hilios / gist:1284170
Created October 13, 2011 12:57
Nginx YSlow performance boost w/ Gzip + Far future expires Header
server {
# output compression saves bandwidth
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# make sure gzip does not lose large gzipped js or css files
@hilios
hilios / application.rb
Last active September 27, 2015 19:28
My default generators configuration
# Generators
config.generators do |generator|
generator.helper false
generator.stylesheets false
generator.javascripts false
generator.controllers true
generator.template_engine :haml
generator.integration_tool :rspec
generator.test_framework :rspec, controller_specs: false,
view_specs: false,
@hilios
hilios / action_dispatch_extensions.rb
Created October 28, 2011 13:26 — forked from tokland/action_dispatch_extensions.rb
How to add locale scope to i18n_routing
class ActionDispatch::Routing::Mapper
def localize_and_scope_for(locales, options = {}, &block)
scoped_locales = locales - Array(options[:skip_scope])
localized(locales) do
locale_regexp = Regexp.new(scoped_locales.join('|'))
scope("/:i18n_locale", :constraints => {:i18n_locale => locale_regexp}) do
yield
end
yield if options[:skip_scope]
@hilios
hilios / navigation_helper.rb
Created November 10, 2011 16:37
Navigation helpers
module NavigationHelper
# Create a link with confirmation message and method set to delete.
#
# Returns a link_to helper with options +:confirm+ and +:method+ setted,
# you can override the default values setting the options hash.
def link_to_destroy(*args, &block)
arg_index = if block_given? then 1 else 2 end
args[arg_index] ||= {}
args[arg_index][:confirm] = t('actions.delete.are_you_sure', :default => 'Are you sure?') unless args[arg_index].has_key? :confirm
args[arg_index][:method] = :delete unless args[arg_index].has_key? :method
@hilios
hilios / nested_form.js.coffee
Created May 9, 2012 21:28
Nested Form Helpers
$('[data-nested="add"]').live 'click', (e)->
e.preventDefault()
association = $(this).data('association')
fields = $(this).data('fields')
target = $("[data-association='#{association}_fields']")
regexp = new RegExp('new_' + association, 'g');
new_id = new Date().getTime();
fields = fields.replace(regexp, "new_" + new_id);
@hilios
hilios / .vimrc
Last active August 2, 2016 16:59
vimrc - Personalizado
set cursorline
set hlsearch
set number
set ruler
set shiftwidth=2
set tabstop=2
syntax on
@hilios
hilios / zone.sh
Created June 12, 2012 14:43
Connect to zone
#!/bin/bash
USER="username"
HOST=$1
BRIDGE=FALSE
while getopts "u:h:b": OPT; do
# echo "$OPT=$OPTARG"
case ${OPT} in
u) USER=${OPTARG};;
b) BRIDGE=TRUE;;