Skip to content

Instantly share code, notes, and snippets.

View jhbabon's full-sized avatar
🦊

Juan Hernández jhbabon

🦊
View GitHub Profile
@jhbabon
jhbabon / gist:2198506
Created March 25, 2012 17:33
rbenv install with Xcode 4.3
# set the gcc in the environment
env CC=/usr/bin/gcc rbenv install ruby-interpreter-here
@jhbabon
jhbabon / application_helper.rb
Created May 9, 2012 09:57
Useful Rails 2.3 view helpers
# -*- encoding: utf-8 -*-
module ApplicationHelper
def title(txt, show = true)
content_for(:title) { h(txt.to_s) }
@show_title = show
show_title
end
@jhbabon
jhbabon / application_helper.rb
Created May 10, 2012 09:27
Presenter pattern for Rails 2 apps
# -*- encoding: utf-8 -*-
# app/helpers/application_helper.rb
module ApplicationHelper
# code...
def present(object, klass = nil)
presenter = ::BasePresenter.build(object, self, klass)
@jhbabon
jhbabon / callbacks.rb
Created May 11, 2012 15:08
Callbacks module for Ruby classes
# encoding: utf-8
# Small module to add the ability to register callbacks at class level to use it at instace level.
# With this module you can create small DSLs on your classes.
#
# Example usage:
#
# class Person
# include ::Callbacks
#
@jhbabon
jhbabon / create_feeds.rb
Created May 14, 2012 12:44
Rails Feeds with SQL View and model: proof of concept
# copied from the texticle gem documentation:
# link: http://tenderlove.github.com/texticle/
class CreateFeeds < ActiveRecord::Migration
def self.up
sql = <<-SQL
CREATE VIEW feeds AS
SELECT articles.id AS feedable_id, articles.title AS title,
CAST ('Article' AS varchar) AS feedable_type
FROM articles
@jhbabon
jhbabon / output.txt
Created June 2, 2012 11:12
Extremely simple cache method system for ruby objects
Class cache
Output => -3400421267002374593 :: -1797544009241115821 :: 4
0.000000 0.000000 0.000000 ( 4.000965)
Output => -3400421267002374593 :: -1797544009241115821 :: 4
0.000000 0.000000 0.000000 ( 0.000068)
Output => -3400421267002374593 :: -1797544009241115821 :: 4
0.000000 0.000000 0.000000 ( 0.000069)
Output => -3400421267002374593 :: -2043295954666096465 :: 6
0.000000 0.000000 0.000000 ( 6.001122)
Output => -3400421267002374593 :: -2043295954666096465 :: 6
@jhbabon
jhbabon / git_tar.sh
Created June 13, 2012 09:12
archive a git repo
# link: http://linssen.me/entry/archive-your-git-repo-easily/
git archive HEAD | gzip > $PWD\.tar\.gz
@jhbabon
jhbabon / vim_installer.rb
Created June 24, 2012 17:37
Thor file for install vim in Mac OS X with Mercurial and rbenv
require 'thor'
class VimInstaller < Thor::Group
include Thor::Actions
def self.source_root
'/tmp'
end
def clean_up
@jhbabon
jhbabon / application.html.haml
Created August 2, 2012 16:55
Load javascript functions based on the current controller and action
-# Code...
%body{ :"data-controller" => controller_name, :"data-action" => action_name }
-# Code...
@jhbabon
jhbabon / proc_callback.rb
Created August 7, 2012 09:44
Block callbacks
# encoding: utf-8
#
# Extract from:
# @link: http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
# @link: http://techscursion.com/2011/11/turning-callbacks-inside-out
class ProcCallback
def initialize(callable, *args)
@callable = callable.to_s
@arguments = args.dup