Skip to content

Instantly share code, notes, and snippets.

@alsor
alsor / stand_by_me_spec.rb
Created April 7, 2016 09:23
Stand by me
require 'rails_helper'
class Tear
end
class Me
attr_accessor :you
def afraid?
!you.present?
@alsor
alsor / ruby_trace
Created July 24, 2012 09:40
Tracing method invocations in ruby
#AMQP.logging = true
#set_trace_func proc { |event, file, line, id, binding, classname|
# if event == "call" && ((file.include?("lib/amqp") &&
# !file.include?("lib/amqp/buffer") &&
# #!file.include?("lib/amqp/frame") &&
# !file.include?("lib/amqp/spec")) ||
# file.include?("eventmachine"))
# printf "from %-130s\t%8s\t%-25s:%-4d\t%s\n", caller[2], event, File.basename(file), line, id
# end
#}
(defn transform-fields [m]
(into [] (flatten (for [[k v] m] [k {:type (keyword v)}]))))
(defn parse-json-config [s]
(let [jsn (keywordize-keys (json/parse-string s))
result (into {} (for [[idx cfg-map] jsn]
{idx (into {} (for [[k v] cfg-map]
(if (or (= :fields k) (= :attributes k))
{k (transform-fields v)}
{k v})))}))]