Skip to content

Instantly share code, notes, and snippets.

View arjones's full-sized avatar

Gustavo Arjones arjones

View GitHub Profile
# RAILS_ROOT/config/initializers/ordered_hash_hacks.rb
class OrderedHash
def method_missing(method_name, *args, &block)
method_name = :_id if method_name == :id
if self.keys.include?(method_name.to_s)
self.send('[]', method_name.to_s)
else
super
end
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.
require 'benchmark'
require 'logger'
class Module
def alias_method_chain( target, feature )
alias_method "#{target}_without_#{feature}", target
alias_method target, "#{target}_with_#{feature}"
end
end unless Module.public_method_defined?(:alias_method_chain)
#Author: Marcel Pinheiro Caraciolo
#Confusion Matrix Generator
#Version: 0.1
#email: caraciol at gmail . com
from pprint import pprint as _pretty_print
import math
class ConfusionMatrix(object):
@arjones
arjones / .gitignore
Created July 8, 2011 19:21 — forked from karmi/.gitignore
Donut Chart from ElasticSearch Terms Facet
.DS_Store
tmp/
@arjones
arjones / .gitignore
Created July 8, 2011 21:33 — forked from karmi/.gitignore
Visualizing timelines with Protovis and date histogram facet in ElasticSearch
.DS_Store
tmp/
@arjones
arjones / gist:1239358
Created September 24, 2011 14:01 — forked from stonegao/gist:1044641
MD5 in scala
object MD5 {
def hash(s: String) = {
val m = java.security.MessageDigest.getInstance("MD5")
val b = s.getBytes("UTF-8")
m.update(b, 0, b.length)
new java.math.BigInteger(1, m.digest()).toString(16)
}
}
@arjones
arjones / TowersOfHanoi.scala
Created April 3, 2012 03:23 — forked from jrudolph/TowersOfHanoi.scala
Scala-Metaprogramming: Towers of Hanoi
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
@arjones
arjones / L.scala
Created April 19, 2012 02:37 — forked from huynhjl/L.scala
Playing with Lucene QueryParser and Query classes
import org.apache.lucene.queryParser.QueryParser
import org.apache.lucene.search._
import org.apache.lucene.analysis._
import org.apache.lucene.analysis.en.EnglishAnalyzer
import org.apache.lucene.analysis.tokenattributes._
import org.apache.lucene.util.Version.LUCENE_35
case class TextQuery(analyzer: Analyzer) {
val parser = new QueryParser(LUCENE_35 , "dummyfield", analyzer)
def fromString(searchTerms: String) = {
@arjones
arjones / Folder Preferences
Created October 10, 2012 15:42 — forked from chrisyour/Folder Preferences
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern