This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/escript | |
| %% -*- mode: erlang -*- | |
| main(Files) -> | |
| NumWorkers = 3, | |
| Parent = self(), | |
| Workers = [spawn_link(fun() -> worker(Parent) end) || _ <- lists:seq(1, NumWorkers)], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % 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, []). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -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}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2012 Erlware, LLC. All Rights Reserved. | |
| # | |
| # This file is provided to you under the Apache License, | |
| # Version 2.0 (the "License"); you may not use this file | |
| # except in compliance with the License. You may obtain | |
| # a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(channels). | |
| -compile(export_all). | |
| make() -> | |
| Ref = make_ref(), | |
| Pid = spawn(?MODULE, channel, [Ref]), | |
| {channel, Pid, Ref}. | |
| channel(Ref) -> | |
| receive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| search(Ch, Kind, Query) -> | |
| timer:sleep(random:uniform(100) + 10), | |
| enqueue(Ch, {Kind, Query}). | |
| fake(Kind) -> | |
| Ch = make(), | |
| fun(Query) -> | |
| spawn(?MODULE, search, [Ch, Kind, Query]), Ch | |
| end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% Pairing Heap implementation | |
| %% more information on wiki: | |
| %% http://en.wikipedia.org/wiki/Pairing_heap | |
| %% pq :: {pq, heap(), int()} | |
| %% heap :: nil | {Item, [heap()]} | |
| %% ============================= | |
| %% API | |
| %% ============================= |