Skip to content

Instantly share code, notes, and snippets.

View brenoperucchi's full-sized avatar

Breno Perucchi brenoperucchi

View GitHub Profile
@brenoperucchi
brenoperucchi / gist:2042397
Created March 15, 2012 06:13 — forked from rlander/gist:1941157
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Cmd+C copy current line (if no selection)
Cmd+X cut current line (if no selection)
Ctrl+⇧+K delete line
Cmd+↩ insert line after
@brenoperucchi
brenoperucchi / Export Devise 1.0.x Database to new Devise 2.1.x
Created September 19, 2012 20:07
validate password devise 1.0.x to 2.x
#First you need to copy password_salt and encrypted_password to your new object model
#Using this because I have to export my database User to another application and old,
# app are using devise 1.0.x and new app using 2.1.x
Class User < ActiveRecord::Base
alias :devise_valid_password? :valid_password?
def valid_password?(password)
begin
@brenoperucchi
brenoperucchi / rbenv-howto.md
Created September 28, 2012 13:39 — forked from MicahElliott/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

# Paginate a collection
#
# Usage:
#
# {% paginate contents.projects by 5 %}
# {% for project in paginate.collection %}
# {{ project.name }}
# {% endfor %}
# {% endpaginate %}
#
@brenoperucchi
brenoperucchi / rails_bootstrap_delete_confirmation_modal.md
Created October 18, 2012 01:07 — forked from trey/rails_bootstrap_delete_confirmation_modal.md
A nice delete confirmation modal in Rails courtesy of Bootstrap

Here's what you get.

Some JavaScript

// Delete confirmation modals
$('#delete-confirm').on('show', function() {
  var $submit = $(this).find('.btn-danger'),
      href = $submit.attr('href');
  $submit.attr('href', href.replace('pony', $(this).data('id')));
@brenoperucchi
brenoperucchi / will_paginate.rb
Created July 3, 2013 20:56
WillPaginate customizes attributes of link_to (html a)
#Add in your project in config/initializers/will_paginate.rb
#in my case I'm adding the attribute page_number with value of target
WillPaginate::ActionView::LinkRenderer.class_eval do
def link(text, target, attributes = {})
attributes.merge!(page_number: "#{target}")
super text, target, attributes
end
end
@brenoperucchi
brenoperucchi / gist:6159298
Created August 5, 2013 20:26
Bash Prompt with GIT and RBENV Gemset and RubyVersion
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
source ~/.git-prompt.sh
eval "$(rbenv init -)"
source ~/.rbenv/completions/rbenv.bash
# prompt with ruby version
# rbenv version | sed -e 's/ .*//'
__rbenv_ps1 ()
{
class CostCenterPresenter
def initialize(object, query)
@object = object
@query = query
end
# results: [
#1# { text: "Western", children: [
#2# { id: "CA", text: "California" },
#2# { id: "AZ", text: "Arizona" }
# ] },
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
@brenoperucchi
brenoperucchi / paginate_tag.rb
Last active August 29, 2015 14:23
Paginate Tag with Liquid Filter using paginate gem
# Paginate a collection
#
# Usage:
#
# {% paginate contents.projects by 5 %}
# {% for project in paginate.collection %}
# {{ project.name }}
# {% endfor %}
# {% endpaginate %}