Skip to content

Instantly share code, notes, and snippets.

View archaelus's full-sized avatar

Geoff Cant archaelus

  • San Francisco, CA
View GitHub Profile
loop(Request) ->
try
process(Request)
catch
Class:Exception ->
Req:respond({500, [{"Content-Type", "text/plain"}],
io_lib:format("Couldn't process request ~p~n"
"Exception: ~p:~p~n"
"StackTrace:~p~n", [Request:dump(), Class, Exception,
erlang:get_stacktrace()])})
%%% ====================================================================
%%% This software is copyright (c) 2006-2007, Process-one.
%%%
%%% $Id$
%%%
%%% @copyright 2006-2007 Process-one
%%% @author Christophe Romain <christophe.romain@process-one.net>
%%% [http://www.process-one.net/]
%%% @author Bengt Kleberg <bengt.kleberg@ericsson.com>
%%% @version {@vsn}, {@date} {@time}
-module(orbited_app).
-behaviour(application).
-export([start/0, start/2, stop/1]).
start() ->
application:load(orbited),
{ok, Deps} = application:get_key(orbited, applications),
lists:map(fun application:start/1,
Deps),
application:start(orbited).
-module(mochiweb_signup_form_controller).
-export([serve_form/2]).
serve_form('GET', Req) ->
{ok, Form} = form:render(signup_form()),
Req:ok("text/html", Form);
serve_form('POST', Req) ->
Post = Req:parse_post(),
case form:valid_post(signup_form(), Post) of
%%%-------------------------------------------------------------------
%% @copyright Geoff Cant
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version {@vsn}, {@date} {@time}
%% @doc Experimental replacement for inet_dns
%% @end
%%%-------------------------------------------------------------------
-module(ginet_dns2).
%% API
resolve(Path) ->
filename:join(resolve(filename:split(Path), [])).
resolve([], Acc) ->
lists:reverse(Acc);
resolve([".." | Rest], [_ | Acc]) ->
resolve(Rest, Acc);
resolve([".." | Rest], []) ->
resolve(Rest, []);
resolve([This | Rest], Acc) ->
%%%-------------------------------------------------------------------
%% @copyright Process One inc.
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version 1.0, {@date} {@time}
%% @doc Tsung protocol module behaviour and edoc.
%% @end
%%%-------------------------------------------------------------------
-module(ts_protocol).
-export([init_dynparams/0,
info(Field, Rec) ->
Fields = fields(Rec),
FieldIdx = lists:zip(Fields, lists:seq(2,length(Fields)+1)),
element(proplists:get_value(Field,FieldIdx), Rec).
fields(#your_record{}) -> fields(your_record);
fields(your_record) -> record_info(fields, your_record).
to_proplist(R) ->
Keys = fields(R),
%%%-------------------------------------------------------------------
%% @copyright Geoff Cant
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version {@vsn}, {@date} {@time}
%% @doc Test process group server
%% @end
%%%-------------------------------------------------------------------
-module(groupsrv).
-behaviour(gen_server).
FindProcs = fun (Pid, Ign) ->
A = fun (F, Pid, Ignore) ->
Links = [P || P <- element(2, process_info(Pid, links)), is_pid(P), node(P) =:= node()],
Monitors = [P || {_, P} <- element(2,process_info(Pid, monitors)), is_pid(P), node(P) =:= node()],
New = lists:filter(fun (I) -> not lists:member(I, Ignore) end, Links++Monitors),
[Pid | lists:flatmap(fun (P) -> F(F, P, New ++ Ignore) end, New)]
end,
A(A, Pid, Ign)
end.