Skip to content

Instantly share code, notes, and snippets.

View uwiger's full-sized avatar

Ulf Wiger uwiger

View GitHub Profile
%% -*- erlang -*-
Dep =
fun(A,Cs) ->
Key = "dep_" ++ A,
case [U || [K, U] <- Cs, K =:= Key] of
[] -> error({not_found, Key});
[URI] ->
{list_to_atom(A), ".*", {git,URI,"HEAD"}}
end
end.
@uwiger
uwiger / gitvsns
Created March 28, 2013 09:23
A simple escript for checking git repositories (on disk) against a rebar.config file
#!/usr/bin/env escript
%% License: http://www.mozilla.org/MPL/2.0/
%% Author: Ulf Wiger <ulf@feuerlabs.com>
-mode(compile).
main([]) ->
{ok, Fs} = file:list_dir("."),
@uwiger
uwiger / ecall.escript
Last active December 10, 2015 14:28
A sketch for an escript that functions similarly to the now defunct erl_call.
#!/usr/bin/env escript
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% Copyright 2013 Ulf Wiger <ulf@wiger.net>
%% License: http://opensource.org/licenses/MIT
main(Args) ->
Options = check_args(Args),
start_dist(Options),
Result = rpc(Options),
@uwiger
uwiger / gist:2365439
Created April 12, 2012 07:29
make_node: escript for creating a node-local start directory
#!/usr/bin/env escript
%% -*- erlang -*-
%% Copyright 2011-12 Feuerlabs Inc.
%% License: "BSD New" (http://www.opensource.org/licenses/BSD-3-Clause)
%% Author: Ulf Wiger <ulf@feuerlabs.com>
-mode(compile).
-record(state, {target, rel, vm_args = []}).
@uwiger
uwiger / Jobs_pools_and_passive_queues.erl
Created January 13, 2011 18:10
Example of how to configure Jobs with a worker pool, drawing from a regular (passive) queue
Fun = fun() ->
io:fwrite("~p starting...~n",[self()]),
Res = jobs:dequeue(q, 3),
io:fwrite("Res = ~p~n", [Res])
end,
application:set_env(jobs, queues,
[{pool, producer, Fun,
[{regulators, [
{counter,[{limit,3}]}
]}
%% In Erlang, re. https://gist.github.com/723543
calc_price(Foo, [List|Rest]) ->
case get_price_for(Foo, List) of
undefined -> calc_price(Rest); % recurse
P -> adjust_price(Foo, P) % return
end.
%% Copyright 2010 Erlang Solutions Ltd (ESL). All rights reserved.
%% Redistribution and use in source and binary forms, with or without
%% modification, are permitted provided that the following conditions are met:
%%
%% 1. Redistributions of source code must retain the above copyright notice,
%% this list of conditions and the following disclaimer.
%%
%% 2. Redistributions in binary form must reproduce the above copyright
%% notice, this list of conditions and the following disclaimer in
%% the documentation and/or other materials provided with the distribution.