Skip to content

Instantly share code, notes, and snippets.

View jhbabon's full-sized avatar
🦊

Juan Hernández jhbabon

🦊
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / passman.sh
Created March 11, 2012 11:42
passman - Minimal password manager
#!/bin/sh
# passman - GPL3 - nibble <develsec.org> 2009
# Minimal password manager
# link: http://nibble.develsec.org/hg/toys/file/ddaf55c59fc7/passman
PASSFILE=~/.passmandb
TMPFILE=~/.passmandb.$$
trap "shred -fuz ${TMPFILE}" 0 2 15 &&
umask 177 &&
@jhbabon
jhbabon / pre-commit.sh
Created March 6, 2012 09:55
Pre commit git-hook that checks if there are changes that must not be committed. The changes should be marked with a NOCOMMIT flag.
#!/bin/sh
#
# Do not commit files with the flag: NOCOMMIT
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
@jhbabon
jhbabon / git_delete.sh
Created February 29, 2012 08:26
Remove deleted files from git index
# borrowed from: http://log.iany.me/post/16812080563/git-rm-deleted-files
git ls-files -d | xargs git rm
@jhbabon
jhbabon / perl_pattern_substitution_command.sh
Created February 15, 2012 23:33
Command line to substitute string patterns in a group of files
perl -e "s/old_pattern/new_pattern/g;" -pi.save $(ack -f path/to/files)
# NOTE: this will create *.save files. Remove them with: rm -f **/*.save