Skip to content

Instantly share code, notes, and snippets.

View shizzard's full-sized avatar

Denis Fakhrtdinov shizzard

View GitHub Profile
@shizzard
shizzard / gist:1280920
Created October 12, 2011 10:57
UTC time zones names
protected $_UtcNames = array(
'UTC-12' => 'Yankee',
'UTC-11' => 'X-Ray',
'UTC-10' => 'Whiskey',
'UTC-9' => 'Victor',
'UTC-8' => 'Uniform',
'UTC-7' => 'Tango',
'UTC-6' => 'Sierra',
'UTC-5' => 'Romeo',
'UTC-4' => 'Quebec',
@shizzard
shizzard / gist:3706867
Created September 12, 2012 14:11
test loop
-module(test_loop).
-export([start_link/0, init/0]).
-record(
state,
{
status = free :: free | busy
}
).
get_handler(Binary, AccountId, Uid) ->
try decode(Binary) of
{ok, Type, Priority, {M, F, A}} ->
{ok, Type, Priority, {M, F, A ++ [AccountId, Uid]}}
catch
error:Error ->
?ERROR("tpf_eva decoder reports bad binary input: ~p", [Error]),
{error, Error};
exit:{error, Why} ->
?ERROR("tpf_eva decoder reports ~p", [Why]),
Specs = [
{name, fun
(Data) when is_list(Data) -> ok;
(Data) -> {error, not_list}
end},
{age, fun
(Data) when is_integer(Data) -> ok;
(Data) -> {error, not_integer}
end}
],
-module(gen_tpf_eva_handler).
-export([get_module_name/3]).
-callback major_version() ->
integer().
-callback minor_version() ->
integer().
-callback handle(binary()) ->
ok | {error, any()}.
@shizzard
shizzard / my.erl
Created November 14, 2012 14:03 — forked from si14/my.erl
send_error(ReplyTo, UUID, RoutingKey, {invalid, protobuff}) ->
eva_tpf:generic_error(ReplyTo, UUID, RoutingKey, [
{source, 'CLIENT'},
{type, <<"INVALID_PROTOBUFF_BINARY">>},
{description, <<"Protobuff binary provided is invalid">>},
{permanent, true}
]);
send_error(ReplyTo, UUID, RoutingKey, {invalid, props}) ->
eva_tpf:generic_error(ReplyTo, UUID, RoutingKey, [
{source, 'CLIENT'},
[
{redis_pool2,{poolboy,start_link,[[{name,{local,redis_pool2}},{worker_module,ept_redis_worker},{size,10},{max_overflow,100}],["localhost",6402]]},permanent,5000,worker,[poolboy]},
{redis_pool1,{poolboy,start_link,[[{name,{local,redis_pool1}},{worker_module,ept_redis_worker},{size,10},{max_overflow,100}],["localhost",6401]]},permanent,5000,worker,[poolboy]},
{redis_pool0,{poolboy,start_link,[[{name,{local,redis_pool0}},{worker_module,ept_redis_worker},{size,10},{max_overflow,100}],["localhost",6400]]},permanent,5000,worker,[poolboy]}
]
init([Host, Port]) ->
try eredis:start_link(Host, Port) of
{ok, C} ->
{ok, #state{redis_conn = C}};
{error, Error} ->
?WARNING("Redis connection (~p:~p) failed: ~p", [Host, Port, Error]),
{ok, #state{}};
Else ->
?WARNING("Redis connection (~p:~p) failed: ~p", [Host, Port, Else]),
{ok, #state{}}
-module(handler_param_action).
-behaviour(gen_handler).
-include("ept.hrl").
-include("ept_hit.hrl").
-include_lib("cowboy/include/http.hrl").
-export([prepare/2, handle/1]).
curl "localhost:12330/counter?action=offer_complete&sid=123123123&hash=epttest&hashVar=epttest"
<<"{\"method\":\"completeOffer\",\"sid\":\"123123123\",\"hash\":\"epttest\",\"hashVar\":\"epttest\"}">>