Skip to content

Instantly share code, notes, and snippets.

View foca's full-sized avatar
👋
Looking for work!

Nicolás Sanguinetti foca

👋
Looking for work!
View GitHub Profile
@foca
foca / gist:3267007
Created August 5, 2012 20:23
Pretty-print Adium transcripts from the terminal. Nice to pipe to `pbcopy`
#!/usr/bin/env ruby
require "nokogiri"
require "time"
module Purple
DIR = File.expand_path("~/Library/Application\ Support/Adium\ 2.0/Users/Default/Logs")
def self.transcripts(buddy, which=-1)
files = Dir.glob(File.join(DIR, "*/#{buddy}/**/*"))
@foca
foca / gist:3148204
Created July 20, 2012 02:03
Git hook to detect if a file changed after a checkout/merge/rebase and show the diff.
#!/usr/bin/env bash
#
# Install into:
# - .git/hooks/post-merge
# - .git/hooks/post-rewrite
# - .git/hooks/post-checkout
#
# And make sure all are executable.
#
# Then change the $file appropriately. Enjoy.
@foca
foca / wizard.html
Created July 10, 2012 05:12
Wizard navigation in CSS (using Twitter Bootstrap)
<ol class="wizard-nav">
<li class="done"><a href="#">Step 1</a></li>
<li class="done"><a href="#">Step 2</a></li>
<li class="active"><a href="#">Step 3</a></li>
<li><a href="#" data-disabled>Step 4</a></li>
<li><a href="#" data-disabled>Step 5</a></li>
</ol>
@foca
foca / how_to_use.md
Created July 7, 2012 02:36
new_rails_app is a script to quickly create pre-configured rails applications out of a template app.

new_rails_app

This script is my way of creating rails apps without much trouble. It works better for me than Rails' templates, so this is what I use.

Basically, it clones a template app and then changes the name of the app.

It's a very simple solution that I've been using for a while now.

Installation

@foca
foca / gist:2553330
Created April 29, 2012 21:22
Completely confounded by Rails 3.2.3, the asset pipeline, and a custom asset host :-(
# config/environments/production.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "//#{ENV.fetch("FOG_DIRECTORY")}.s3.amazonaws.com"
# app/views/layouts/application.erb
<%= javascript_include_tag :application %>
# Resulting HTML (in heroku, with RAILS_ENV=production):
@foca
foca / gist:2489279
Created April 25, 2012 12:11
cdgem is a small bash utility function to cd into a rubygem's directory
# cd into matching gem directory ("cd -" friendly)
#
# cdgem noko # will cd into the first gem matching noko
# cdgem ^rails- # will cd into the first gem starting with "rails-"
# vim $(cdgem noko) # will open the gem's directory in vim
cdgem() {
local gempath=$(gem env gemdir)/gems;
local gem=$(ls "$gempath" | grep "$1" | sort | tail -1);
if [ -z "$1" ]; then
@foca
foca / itau.rb
Created March 16, 2012 18:14
Scraper to get transactions out of my bank accounts
# encoding: UTF-8
require 'mechanize'
require 'money'
require 'ostruct'
module Itau
class Session < Struct.new(:ci, :pass)
def login
login_page = agent.get(itaurl)
# Is this a bad idea? I really dislike having to type
# Rails.application.routes.url_helpers.foo_path in my javascript templates.
#
# This turns it into SomeApp.routes.foo_path, which still is a bit much, but
# means it's less work.
module SomeApp
# Public: Shortcut to access named routes when needed. This is targeted at
# asset-pipeline templates, so we can use these helpers from javascript
# without all the ceremony.
@foca
foca / article.rb
Created February 24, 2012 17:10
[FIXED] Help me clean this up so one scope uses the other!
# FIXED: This is what I did in the end, after discussing it with @dcadenas.
# Check the previous versions of the gist to see how the problem looked before :)
#
# I have this AR model that has two scopes that should return complementary sets
# of rows: one returns all the rows that match certain conditions, the other
# returns all rows that DON'T match the same conditions.
#
# I would like to build the second scope using the first one. Something like:
#
# class Article
class Store::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# GET /store/auth/:provider/callback
def success
auth_hash = request.env.fetch("omniauth.auth")
user = User::Authorization.authorize(auth_hash)
sign_in_and_redirect user
end
# This is stupid, devise
alias_method :twitter, :success