View my_configs.vim
set pastetoggle=<F3>
set nu
"""""""""""""""""c/cpp/cu settings""""""""""""""""""""""""""""""""""
" check cpp code applying c++11 standard
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libc++'
" on some system:
" let g:syntastic_cpp_compiler = 'g++'
View cmake_clean.sh
# Find and then delete all files under current directory (.) that:
# 1. contains cmake (case-&insensitive) in it's path (wholename)
# 2. name is not CMakeLists.txt
find . -iwholename '*cmake*' -not -name CMakeLists.txt -delete
View reliable_word_count.clj
(ns storm.starter.clj.word-count2
(:import [backtype.storm StormSubmitter LocalCluster])
(:use [backtype.storm clojure config log])
(:gen-class))
(def id-count (atom 0)) ;; tuple counter for debugging -- something to make ids out of
(defspout sentence-spout ["sentence"]
[conf context collector]
(let [sentences ["a little brown dog"
View gist:6862398
(defn mkdirs [absolute-path]
(loop [levels (clojure.string/split absolute-path #"/")
current ""]
(when (not (empty? levels))
(let [next-level (str current (first levels) "/")]
(.mkdir (java.io.File. next-level))
(recur (rest levels) next-level)))))
View consumer.clj
(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.)]
View read_lines.erl
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.
View concat_binary.erl
% concat, binary
B1= <<1,2>>.
B2= <<3,4>>.
B3= <<B1/binary, B2/binary>>.
% <<1,2,3,4>>
View is_element_of_tuple.erl
-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)).
View method_hook.rb
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)
View ssl.rb
ACCESS_TOKEN_URI = 'https://apis.live.net/v5.0/me'
params = { :access_token => token }
uri = URI.parse(ACCESS_TOKEN_URI)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
request = Net::HTTP::Post.new(uri.path)
request.set_form_data(params)
http.request(request).body