Skip to content

Instantly share code, notes, and snippets.

View corntrace's full-sized avatar

Kevin corntrace

  • Shanghai, China
View GitHub Profile
@corntrace
corntrace / piece_of_rails.rb
Created November 15, 2009 07:43
Ruby meta handle constants
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
(self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const))
end
@corntrace
corntrace / simple_restful_connmunicate.rb
Created December 5, 2009 00:48
Post a form using Net::HTTP
# Post the email to the Rails app's restful service
res = Net::HTTP.post_form(URI.parse(service_url), {'params_name'=> params_value})
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
@corntrace
corntrace / gist:256985
Created December 15, 2009 14:39 — forked from holin/gist:256825
ascii print, useful guesture
puts <<ASCII
/´¯/)
,/¯ /
/ /
/´¯/' '/´¯¯`·¸
/'/ / / /¨¯\\
('( ´ ´ ¯~/' ')
\\ ' /
'' \\ _ ·´
\\ (
@corntrace
corntrace / dewip.sh
Created December 23, 2009 06:43 — forked from timriley/dewip.sh
cucumber tags filters
alias dewip="sed -E -i '' -e '/^[[:blank:]]*@wip$/d;s/,[[:blank:]]*@wip//g;s/@wip,[[:blank:]]*//g' features/**/*.feature"
@corntrace
corntrace / metacss.css
Created January 16, 2010 08:04
metacss file
/* Font */
.fwb {
font-weight: bold;
}
.fwn{
font-weight: normal;
}
.tdn{
@corntrace
corntrace / update_with_original_fork.sh
Created May 9, 2010 11:05
update you forked repo with the original repo
# add a remote branch point to the original repo. the original repo's branch usually be the master
$ git remote add --track master mleung git://github.com/mleung/feather.git
# the verify the remote branch
$ git remote
# to fetch all changes from the remote
$ git fetch mleung
# merge the remote changes
class Someone
class << self
def say
$stdin.each_line do |line|
$stdout << "someone says '#{line}' @ #{Time.now}"
end
end
end
end

== Scala 2.7.5

scalac shapes.scala shapes-actor.scala
scala shapes-actor-script.scala // it works

== Scala 2.8.0

scalac shapes.scala shapes-actor.scala
scala shapes-actor-script.scala // NOT works

scala -cp . shapes-actor-script.scala // NOT works

@corntrace
corntrace / lisp.rb
Created September 2, 2010 10:41 — forked from dahlia/lisp.rb
0 minutes Lisp in Ruby
# 30 minutes Lisp in Ruby
# Hong MinHee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
module Embedding
def embeds_many(association_id, options = {})
has_many association_id, options.merge(:dependent => :destroy)
accepts_nested_attributes_for association_id, :allow_destroy => true
end
def embeds_one(association_id, options = {})
has_one association_id, options.merge(:dependent => :destroy)
accepts_nested_attributes_for association_id, :allow_destroy => true
end