This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns oceanus.anduin.clj.consumer | |
(:gen-class) | |
(:import [kafka.consumer ConsumerConfig Consumer KafkaStream] | |
[kafka.javaapi.consumer ConsumerConnector] | |
[java.util Properties])) | |
(defn make-props | |
"convert a clojure map into a Properties object." | |
[m] | |
(let [props (Properties.)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for_each_line_in_file(Name, Proc, Mode, Accum0) -> | |
{ok, Device} = file:open(Name, Mode), | |
for_each_line(Device, Proc, Accum0). | |
for_each_line(Device, Proc, Accum) -> | |
case io:get_line(Device, "") of | |
eof -> file:close(Device), Accum; | |
Line -> NewAccum = Proc(Line, Accum), | |
for_each_line(Device, Proc, NewAccum) | |
end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% concat, binary | |
B1= <<1,2>>. | |
B2= <<3,4>>. | |
B3= <<B1/binary, B2/binary>>. | |
% <<1,2,3,4>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(tuple_util). | |
-export([is_element_of_tuple/2]). | |
is_element_of_tuple(Tuple, Element) -> | |
lists:member(Element, tuple_to_list(Tuple)). | |
% or like this: | |
is_element_of_tuple(E, Tuple) -> | |
is_element_of_tuple(E, Tuple, 1, tuple_size(Tuple)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base | |
def self.method_added(name) | |
if /hook/.match(name.to_s) or method_defined?("#{name}_without_hook") | |
return | |
end | |
hook = "def #{name}_hook\n p 'Method #{name} has been called'\n #{name}_without_hook\nend" | |
self.class_eval(hook) | |
a1 = "alias #{name}_without_hook #{name}" | |
self.class_eval(a1) |
NewerOlder