Skip to content

Instantly share code, notes, and snippets.

View foca's full-sized avatar

Nicolás Sanguinetti foca

View GitHub Profile
@foca
foca / .vimrc
Created August 10, 2012 18:32
Per project .vimrc files. See http://coderwall.com/p/tqns-w
autocmd User Rails Rnavcommand form app/forms -glob=**/* -suffix=_form.rb
autocmd User Rails Rnavcommand service app/services -glob=**/*.rb -suffix=_service.rb
autocmd User Rails Rnavcommand uploader app/uploaders -glob=**/*.rb -suffix=_uploader.rb
autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb
autocmd User Rails Rnavcommand factories -default=test/support/factories -suffix=.rb
autocmd FileType ruby,eruby,javascript,html set shiftwidth=2 softtabstop=2 expandtab
@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 / 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
# 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
@foca
foca / deploy.rake
Created January 21, 2012 17:21
Rake task to synchronize assets to S3 (via asset_sync) and deploy to heroku, optionally migrating the database if that needs doing.
# This is inspired by http://ckdake.com/comment/reply/362
desc "Deploy ALL the targets"
task :deploy => ["deploy:assets", "deploy:heroku"]
namespace :deploy do
desc "Synchronize assets to S3"
task assets: [:environment,
:load_config,
"assets:precompile",
@foca
foca / singleton.coffee
Created January 18, 2012 22:39
Small implementation of Singletons for Backbone
# Public: generates a mixable singleton implementation dependent on a model key.
# Once you mix it into a model, your model gains an .instance method that will
# generate an object and cache it. Further calls to the .instance methods will
# return the same object.
#
# key - The name of the attribute we use to index instances. Defaults to "id".
#
# Example
#
# # Called without arguments uses the "id" as key.