Skip to content

Instantly share code, notes, and snippets.

@abhijith
abhijith / foo.erl
Created March 7, 2014 09:43
Pattern matching differences between ocaml and erlang
-module(foo).
-export([drop/2]).
drop([], Elem) -> [];
drop([Elem|T], Elem) -> drop(T, Elem);
drop([H|T], Elem) -> [H | drop(T, Elem)].
;; Without using partial
(defn sums-to-n? [n]
(fn [coll]
(= n (reduce + coll))))
(def f (sums-to-n? 10))
(f [1 2 3]) ; false
(f [1 2 3 4]) ; true
-module(foobar).
-behaviour(gen_fsm).
-define(SERVER, ?MODULE).
-export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4, one/2, two/2, three/2, first/0, second/0, third/0]).
-compile(export_all).
start_link() ->
gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], []).
%%% subscribing process
-module(subscribe_madi).
-export([test/0]).
test() ->
mnesia:subscribe({table, nick, simple}),
loop().
loop() ->
-module(migrate).
-compile(export_all).
-include("v.hrl").
gah() ->
Transformer = fun({v, Name, Parent}) ->
#vm{name = Name, parent = Parent, group = undefined}
end,
mnesia:transform_table(v, Transformer, [name, parent, group]).
-module(kicker).
-compile(export_all).
sleeper() ->
spawn(fun() -> loop() end).
loop() ->
receive
Any ->
io:format("Message ~p~n", [Any]),
is_table_defn_updated() ->
mnesia:table_info(version1, attributes) =/= record_info(fields, version1).
upgrade_version_table() ->
case is_table_defn_updated() of
false -> ok;
true ->
NewAttrs = record_info(fields, version1),
{ atomic, ok } = mnesia:transform_table(version1, (fun transformer/1), NewAttrs)
end.
(def x (ref 0)
(def agents (for [i (range 0 1000)] (agent x)))
(map #(send %1 (fn [x] (dosync (alter x inc)))) agents)
@abhijith
abhijith / check-hbase-status.rb
Created April 13, 2012 10:57
sensu check-hbase-status plugin
#!/usr/bin/hbase org.jruby.Main
#
# HBase status plugin
# ===
#
# This plugin checks if any of the regionservers are down
#
# Copyright 2012 Runa Inc
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
@abhijith
abhijith / test0.rb
Created November 19, 2012 06:22
ironfan cluster config
Ironfan.cluster 'test0' do
cloud(:ec2) do
permanent false
availability_zones ['us-east-1d']
flavor 't1.micro'
backing 'ebs'
image_name 'natty'
bootstrap_distro 'ubuntu10.04-ironfan'
chef_client_script 'client.rb'
mount_ephemerals