Skip to content

Instantly share code, notes, and snippets.

View alexandrebini's full-sized avatar

Alexandre Bini alexandrebini

View GitHub Profile
@alexandrebini
alexandrebini / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Git branch
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
export PS1='\[\e[1;37m\]\w\[\e[m\] $(parse_git_branch "(%s)" ) \[\e[1;32m\]\$ \[\e[m\]\[\e[1;37m\]'
<%= content_for(:javascript) do %>
<%= javascript_tag "save_related_category_src(#{@category.categories.any?})"%>
<%- for category in @category.categories do %>
<%= javascript_tag "add_new_related_category(#{category.id})" %>
<% end %>
<% end %>
require "config/environment.rb"
namespace :carrierwave do
task :destroy, :class, :mount_uploader, :version do |task,args|
desc "Destroy one image version"
eval(args[:class]).all.each do |r|
r.instance_eval(args[:mount_uploader].to_sym).instance_eval(args[:version].to_sym).remove!
end
end
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8
module WillPaginateHack
def self.included(base)
base.alias_method_chain :url, :hack
end
private
def url_with_hack(page)
if page > 1
url_without_hack(page)
else
namespace :backup do
task :set_name do
set :backup_folder, "/tmp"
set :backup_name, "#{application}-#{DateTime.now.strftime('%Y-%m-%d_%H-%M-%S')}"
set :backup_path, "#{backup_folder}/#{backup_name}"
end
task :db do
yml = YAML.load_file("#{repository}/config/database.yml")
@alexandrebini
alexandrebini / gist:1073029
Created July 8, 2011 22:56
get twitter kkey
def index
client = TwitterOAuth::Client.new( :consumer_key => 'key', :consumer_secret => 'key')
if session['token'].blank?
session['token'] = client.request_token(:oauth_callback => 'http://127.0.0.1:8000')
end
request_token = session['token']
if params['oauth_token'].blank?
redirect_to request_token.authorize_url
@alexandrebini
alexandrebini / pagseguro.pt-BR.yml
Created September 17, 2011 17:31
pagseguro.pt-BR.yml
pt-BR:
activemodel:
attributes:
pag_seguro/order:
abandon_url:
address: Endereço
address_city: Cidade
address_complement: Complemento
address_district: Bairro
address_number: Número