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
public class SimpleMapper<TDestination> where TDestination : class, new() | |
{ | |
public SimpleMapper() { } | |
public virtual List<TDestination> CreateFrom<TSource>(List<TSource> source) where TSource : class | |
{ | |
return source.ConvertAll<TDestination>(x => CreateFrom<TSource>(x)); | |
} | |
public virtual TDestination CreateFrom<TSource>(TSource source) where TSource : class |
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(set). | |
% An insert-only, distributed set that functions as a CRDT. By not allowing removal of elements in the set, we can | |
% provide Strong Eventual Consistency without a quorum algorithm. Requests can be served by any server without | |
% waiting for acknowledgment. Replication conflicts are impossible because all operations are commutative, | |
% associative, and idempotent. | |
% I think something like this should provide consistency even with up to N-1 failures. (Is this correct?) | |
% Note that this is very similar to the multi-master counter, except that the merge function is different. | |
-behaviour(gen_server). |
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(mmc). | |
% A multi-master counter implemented as a CRDT. Each server holds an array of counters (implemented as a dict here...) | |
% and Strong Eventual Consistency is acheived by using commutive increments on each of the counters. The current | |
% value read at any server is the sum of all the counter values (again, one per server) stored on that machine. | |
% As updates are synced between servers, all servers will eventually converge on a counter sum value with no | |
% conflicts possible. Also note that this does not use any consensus algorithm, so it remains fast as the number of | |
% servers scales. See http://research.microsoft.com/apps/video/default.aspx?id=153540&r=1 | |
-behaviour(gen_server). |
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
% If you have a string that contains a numeric value, but you don't know if it is a float or an integer, then the | |
% standard conversion functions list_to_integer/1 and list_to_float/1 are a pain. | |
% Using these functions is easier, since they check the types and convert correctly for you: | |
numeric_to_list(X) when is_float(X) -> float_to_list(X, [{decimals, 9}, compact]); | |
numeric_to_list(X) when is_integer(X) -> integer_to_list(X). | |
list_to_numeric(L) when is_list(L) -> | |
Float = (catch erlang:list_to_float(L)), | |
Int = (catch erlang:list_to_integer(L)), |
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
%%%------------------------------------------------------------------- | |
%%% @author Cole Fichter, www.colefichter.ca | |
%%% @copyright (C) 2014, | |
%%% @doc | |
%%% This module implements a round-robin priority queue with a client API similar to the standard Erlang queue. | |
%%% Items are added to the queue with a key (an integer, usually some kind of id). When requested to dequeue an | |
%%% item, the queue first picks a sub-queue by the key, then dequeues the first item under that key. The 'last key' | |
%%% is incremented, and the next dequeued item will come from the sub-queue for the updated key. | |
%%% | |
%%% Example use-case: preventing starvation while crawling multiple web sites. Suppose we're crawling three |
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
hash(Data) when is_atom(Data) -> hash(atom_to_list(Data)); | |
hash(Data) -> | |
Binary160 = crypto:hash(sha, Data), | |
hexstring(Binary160). | |
% Convert a 160-bit binary hash to a hex string. | |
hexstring(<<X:160/big-unsigned-integer>>) -> | |
lists:flatten(io_lib:format("~40.16.0b", [X])). |
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(ring). | |
% A simple process ring made up of a doubly-linked ring of processes. | |
% A message can be passed in either direction around the ring. | |
% | |
% Example usage in the Erlang shell: | |
% > c(ring). | |
% > First = ring:start(5). | |
% > ring:send_anti_cw("Hi", First, 10). | |
% > {relay,anti_clockwise,10,1,"Hi"} | |
% > <0.38.0> Relaying 1 "Hi" |
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(kv). | |
-export([start/0, stop/0, store/1, lookup/1, delete/1]). | |
-export([server_loop/1]). | |
%--------------------------------------------------------------------------------------------- | |
% Client API | |
%--------------------------------------------------------------------------------------------- |
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
Show hidden characters
{ | |
"cmd": ["./rebar compile eunit"], | |
"shell": true, | |
"working_dir": "${file_path}/../" | |
} |
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
<html> | |
<head> | |
<title>Diffie-Hellman Key Exchange</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<style> | |
.secret { | |
background-color: #ffa9a9; | |
} | |
th { | |
background-color: lightgray; |
NewerOlder