Skip to content

Instantly share code, notes, and snippets.

View albertoperdomo's full-sized avatar

Alberto Perdomo albertoperdomo

View GitHub Profile
@albertoperdomo
albertoperdomo / Instructions.markdown
Last active September 26, 2015 17:38
Setting up a new machine

Setting up a new Mac for web development with Rails

This is my own howto to setup new machines, but you might find it helpful as well.

## General settings

  • In Finder -> Preferences set it to show your home folder, hard drives, external drives, filename extensions, etc.
  • Make Finder show Library: run chflags nohidden ~/Library/ within a terminal
  • Disable holding key pressed to display accents and enable repeat keys: defaults write -g ApplePressAndHoldEnabled -bool false
  • In Preferences->Dock Select "Scale Effect" in the "Minimize Using" field and deselect the "Animate Opening Applications" option.
# app/controllers/application_controller.rb
# Rescue from RoutingError
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActionController::RoutingError, :with => :render_routing_error
def render_routing_error
render :text => "Rescued from routing error.", :status => 404
@albertoperdomo
albertoperdomo / extend.rb
Created April 7, 2011 14:46
#scotruby exercise with extend
module MyAttributes
@@attributes = []
def my_accessor(field)
@@attributes << field
attr_accessor(field)
end
def my_attributes
@@attributes
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
attr_accessor :app_server
def app_server
@app_server_config ||= AppServer.new
yield @app_server_config if block_given?
@app_server_config
end
end
@albertoperdomo
albertoperdomo / binding_exercise.rb
Created April 7, 2011 10:03
ScotRuby 2011 - Charity tutorial Excercise with bindings
def counter(start=0, increment=1)
count = nil
Proc.new do
count = count ? count+increment : start
end
end
result = counter(2,3)
puts result.call #2
@albertoperdomo
albertoperdomo / xvfb
Created December 20, 2010 16:08
xvfb init script
DISPLAY=:99
XVFB=/usr/bin/Xvfb
XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
@albertoperdomo
albertoperdomo / 960_plain_small_example.html
Created September 22, 2010 11:08
Short example of 960.gs vs. Compass + 960.gs
// HTML using 960.gs
<body>
<div class="container_16">
// more stuff
<div class="grid_4">
Sidebar
</div>
// Snippet by @ayosec on IM - Thx ayose! :)
//:ruby
//= form.input :city_id, :as => :string, :input_html => { :value => resource.city_id }
//:javascript
jQuery(function() { city_autocompleter("#resource_city_id", "#{escape_javascript resource.localized_city_long_name || params[:city]}") });
@albertoperdomo
albertoperdomo / accent_query_translate_using_translate.rb
Created September 14, 2010 21:31
Normalize terms for search in DB
#Así he implementado tu propuesta como scope:
named_scope :normalized_name_begins_with, lambda { |term|
map = [
"âãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮñÑçÇüÜ".mb_chars,
"aaaaaaaaaaaaaaaeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuunnccuu"]
# ActiveSupport::Multibyte::Chars#tr broken?
adapted_word = "%#{term.mb_chars.split(//).map {|e| (p = map[0].index(e)) ? map[1][p,1] : e.to_s }.join.downcase}%"
{