Skip to content

Instantly share code, notes, and snippets.

% copied from Mochiweb's mochiweb_uitl.erl
-module(url_encoder).
-export([encode/1]).
-define(PERCENT, 37). % $\%
-define(FULLSTOP, 46). % $\.
-define(IS_HEX(C), ((C >= $0 andalso C =< $9) orelse
(C >= $a andalso C =< $f) orelse
(C >= $A andalso C =< $F))).
-define(QS_SAFE(C), ((C >= $a andalso C =< $z) orelse
-module(strre).
-author("Daniel Kwiecinski: lambder.com").
-purpose("string replace functionality").
-export([sub/3,gsub/3,test/0]).
sub(Str,Old,New) ->
RegExp = "\\Q"++Old++"\\E",
re:replace(Str,RegExp,New,[multiline, {return, list}]).
gsub(Str,Old,New) ->
%% @author Daniel Kwiecinski <[email protected]>
%% @copyright Daniel Kwiecinski author.
%% @doc Example of redirect webmachine_resource.
-module(redirect_resource).
-export([init/1, resource_exists/2, moved_temporarily/2, previously_existed/2]).
-include_lib("webmachine/include/webmachine.hrl").
init([]) -> {ok, undefined}.
-module(scroogle_scrapper).
-compile(export_all).
-define(SCROOGLE_URL, "https://ssl.scroogle.org/cgi-bin/nbbw.cgi").
-define(SCROOGLE_PEM, "[PATH_TO_SSL_SCROOGLE_ORG_PEM_CERTIFICATE]").
start() ->
inets:start(),
ssl:start().
% copied from Mochiweb's mochiweb_uitl.erl
-module(url_encoder).
-export([encode/1]).
-define(PERCENT, 37). % $\%
-define(FULLSTOP, 46). % $\.
-define(IS_HEX(C), ((C >= $0 andalso C =< $9) orelse
(C >= $a andalso C =< $f) orelse
(C >= $A andalso C =< $F))).
-define(QS_SAFE(C), ((C >= $a andalso C =< $z) orelse
-module(google_scrapper).
-compile(export_all).
-define(GOOGLE_URL, "http://www.google.co.uk/search?hl=en&btnG=Search&meta=&q=").
start() -> inets:start().
fetch_google_results(Q) ->
% In case of redirect lets erlang take care of this for us
#!/usr/bin/escript
%% -*- mode: erlang -*-
main(Files) ->
NumWorkers = 3,
Parent = self(),
Workers = [spawn_link(fun() -> worker(Parent) end) || _ <- lists:seq(1, NumWorkers)],
% connection supervisor
-module (connection_sup).
-behaviour (supervisor).
-export ([start_link/1, start_connection/0, init/1]).
start_link({Ip, Port, Options}) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, [Ip, Port, Options]).
start_connection () ->
supervisor:start_child (?MODULE, []).
-module(httpheaders_resource).
-export([init/1, to_html/2]).
-include_lib("webmachine/include/webmachine.hrl").
init([]) -> {ok, undefined}.
to_html(ReqData, Context) ->
Headers = mochiweb_headers:to_list(wrq:req_headers(ReqData)),
StringConvert = [{X,list_to_binary(Y)} || {X,Y} <- Headers],
Output = mochijson2:encode({struct, StringConvert}),
$ mkdir p1
$ cd p1/
$ rebar create-app appid=hotdo
$ ls
$ mkdir deps
$ touch rebar.config
$ # feeling rebar config file
$ wget -O rebar.config https://gist.github.com/kachayev/5657307/raw/fb9b0cd0d62e053efe54774bf2033e6e651c6622/hotdo.rebar.config
$ rebar get-deps
$ tree -L 2