Skip to content

Instantly share code, notes, and snippets.

@fabiokung
fabiokung / project.clj
Created August 6, 2011 06:35
Template for heroku java/war projects (using the cedar stack + clojure support)
(defproject project-name "0.0.1"
:dependencies
[[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[lein-mvn "0.1.0"]
[lein-herokujetty "0.1.0"]]
:eval-in-leiningen true)
(require 'heroku-autobuild)
@fabiokung
fabiokung / heroku_autobuild.clj
Created August 6, 2011 06:18
Adding a "compilation phase" to Heroku's publishing process (a.k.a. slug compilation)
(use 'robert.hooke)
(require 'leiningen.deps)
(require 'lancet.core)
(import (java.io File)
(java.net URL URLClassLoader)
(java.lang.reflect Method))
;; based on code from leiningen.deps (version 1.6.1)
(defn- find-lib-jars [project]
(.listFiles (File. (:library-path project))))
@fabiokung
fabiokung / debundler
Created May 18, 2011 10:09
deb packaging for applications using bundler
#!/bin/bash
@fabiokung
fabiokung / HashMap.java
Created March 26, 2011 21:32
snippet of HashMap's default implementation, from Sun's JVM (Mac OSX build 1.6.0_24-b07-334-10M3326)
/**
* Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions. This is critical
* because HashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ
* in lower bits. Note: Null keys always map to hash 0, thus index 0.
*/
static int hash(int h) {
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
@fabiokung
fabiokung / fork.rb
Created October 27, 2010 18:01
fork and copy on write behavior
n = 10
fork do
n = 20
puts n #=> 20
end
fork do
n = 30
puts n #=> 30
function t3hClosure() {
var globalVariablesSux = "non global";
return function() {
alert(globalVariablesSux);
}
}
closure = t3hClosure();
Memory access offset=0 size=9 is out of bounds
.../gems/ffi-0.6.3/lib/ffi/memorypointer.rb:34:in `put_string'
@fabiokung
fabiokung / insert_utf-8_encoding_line.sh
Created June 26, 2010 23:49
shell one-liner to include encoding annotations in all ruby files
grep -F "# -*- coding: UTF-8 -*-" -L app/**/*.rb | while read file; do sed -e '1i\
# -*- coding: UTF-8 -*-\n' -i '' $file; done
class Nando:
def __ass__(dick):
print dick
module ActiveRecord
class Base
def self.meu_named_scope_comum(*args)
named_scope(com_os_argumentos_que_precisar)
end
end
end
# aí nos models que precisar usar isso...