Skip to content

Instantly share code, notes, and snippets.

emacs -q --eval '(condition-case err (progn (load "~/.emacs") (kill-emacs 0)) (error (kill-emacs 1)))'
# Source http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/bed5b2bd8b237f5a?pli=1
['gift', 'encoding'].each do |param|
eval <<EOC
task["active_#{param}"]=="on" ? active_#{param} = true : active_#{param} = false
task["active_#{param}"] = active_#{param}
active_#{param} = true if task["active_#{param}"]
task, #{param} = separate_#{param}(task)
EOC
end
puts "#{active_gift} active_gift"
puts "#{active_encoding} active_encoding"
@sub
sub / gist:839014
Created February 22, 2011 17:21
metodo create iniziale
def create
puts "NEW"
offer = Offer.find(params[:offer_id])
if params[:offer_id]
task = JSON.parse(params[:tasks])
unless task.nil?
task["active_gift"]=="on" ? active_gift = true : active_gift = false
task["active_gift"] = active_gift
active_gift = true if task["active_gift"]
task, gift = separate_gift(task)
def separate_gift(task)
gift = {}
[:gift_quantity, :unit_price, :gift_type, :supplier].each do |prop|
gift["#{prop}"] = task["#{prop}"]
task.delete("#{prop}")
end
# task.delete("active_gift")
gift["task_id"] = task["id"]
[task, gift]
end
this is my test with cocode.io