Skip to content

Instantly share code, notes, and snippets.

View kisai's full-sized avatar

Sergio Diaz kisai

  • UNOSQUARE
  • Mexico
View GitHub Profile
@kisai
kisai / format_ruby_exception.rb
Last active August 29, 2015 14:05
How to format ruby exception with backtrace into a string
#Sample 1
puts "#{$@.first}: #{$!.message} (#{$!.class})", $@.drop(1).map{|s| "\t#{s}"}
#Sample 2
puts "#{e.backtrace.first}: #{e.message} (#{e.class})", e.backtrace.drop(1).map{|s| "\t#{s}"}
@kisai
kisai / ar_build_method_sample.rb
Last active August 29, 2015 14:05
activerecord :build method
Class Dog
has_many :tags
belongs_to :person
end
Class Person
has_many :dogs
end
d = Dog.new
#!/bin/bash
export JAVA_OPTS="-Xmx2048m -XX:ReservedCodeCacheSize=256m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -XX:NewRatio=3 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF-8 -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
export JRUBY_OPTS="--1.9 -J-noverify -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1"
torquebox run -b 0.0.0.0
(define (memoize f)
(define ht (make-hash))
(define (f-mem . args)
(if (hash-has-key? ht args)
(hash-ref ht args)
(begin
(hash-set! ht args (apply f args))
(hash-ref ht args))))
f-mem)
@kisai
kisai / movedir.clj
Created May 6, 2012 08:20
Move directory contents from source to destination
(use 'clojure.java.io)
(let [pred (every-pred
#(.isDirectory %)
#(not (.startsWith (.getName %) "."))
#(not (some (partial = (.getName %)) ["Exclude Name 0" "Exclude Name 1" "Exclude Name 2"])))
dest "/Path/to/Destination"
src "/Path/to/Source" ]
(doseq [f (filter pred (-> src file .listFiles seq))]
(.renameTo f (file dest (.getName f))) ))