This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo
channel from user nickname
.
$ python pub.py foo nickname
PUBLISH to channel #foo
d3.transform = function(string) { | |
d3_transformG.setAttribute("transform", string); | |
var m = d3_transformG.transform.baseVal.consolidate().matrix; | |
if (m.a * m.d - m.b * m.c) return new d3_transform(m); // if invertible | |
}; | |
// Compute x-scale and normalize the first row. | |
// Compute shear and make second row orthogonal to first. | |
// Compute y-scale and normalize the second row. | |
// Finally, compute the rotation. |
/** | |
* 1. Original JS Implementation by Jeff Greenberg 2/2001 - http://home.earthlink.net/~kendrasg/info/js_opt/ | |
* 2. (fast duff's device) from an anonymous donor to Jeff Greenberg's site | |
* 3. (faster duff's defice) by Andrew King 8/2002 for WebSiteOptimization.com | |
* 4. bug fix (for iterations<8) by Andrew B. King April 12, 2003 | |
*/ | |
function duffsDevice (iterations) { | |
var testVal = 0, | |
n = iterations % 8; |
# source : http://code.google.com/p/natvpn/source/browse/trunk/stun_server_list | |
# A list of available STUN server. | |
stun.l.google.com:19302 | |
stun1.l.google.com:19302 | |
stun2.l.google.com:19302 | |
stun3.l.google.com:19302 | |
stun4.l.google.com:19302 | |
stun01.sipphone.com | |
stun.ekiga.net |
function worker() { | |
setInterval(function() { | |
postMessage({foo: "bar"}); | |
}, 1000); | |
} | |
var code = worker.toString(); | |
code = code.substring(code.indexOf("{")+1, code.lastIndexOf("}")); | |
var blob = new Blob([code], {type: "application/javascript"}); |
// = Requirements: freetype 2.5, libpng, libicu, libz, libzip2 | |
// = How to compile: | |
// % export CXXFLAGS=`pkg-config --cflags freetype2 libpng` | |
// % export LDFLAGS=`pkg-config --libs freetype2 libpng` | |
// % clang++ -o clfontpng -static $(CXXFLAGS) clfontpng.cc $(LDFLAGS) \ | |
// -licuuc -lz -lbz2 | |
#include <cassert> | |
#include <cctype> | |
#include <iostream> | |
#include <memory> |
Both command sourcing (CS) and event sourcing (ES) rely on determinism for correctness.
The correctness condition for ES is the determinism (purity) of the function State -> Event -> State
. Given that this function is deterministic, aka it always maps the same inputs to the same ouputs, we can rely on it to reconstitute state at any point in time. Determinism is typically achieved by ensuring that the Event
has all required information to make the state transition, ie no side effects. The Event
then is a sort of "closure" of all pertinent information about the event.
The correctness condition for CS is the determinism of the function State -> Command -> Event
. Herein lies one of the distinctions between command sourcing and event sourcing - a program can control its output, but it not its input. Since one can't control the input, aka command, one can't in general, enrich it with all required information to make the above function deterministic. A consequence of this is that you can't simply replay a
import logging | |
import uuid | |
import time | |
from mesos.interface import Scheduler | |
from mesos.native import MesosSchedulerDriver | |
from mesos.interface import mesos_pb2 | |
logging.basicConfig(level=logging.INFO) |
I've put together these notes as I read about DHT's in depth and then learned how the libtorrent implementation based on the Kademlia paper actually works.
400,000,000,000
(400 billion stars), that's a 4 followed by 11 zeros.
The number of atoms in the universe is estimated to be around 10^82
.
A DHT with keys of 160 bits, can have 2^160
possible numbers, which is around 10^48
import java.io.FileDescriptor; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.PrintStream; | |
public class HelloWorld{ | |
private static HelloWorld instance; | |
public static void main(String[] args){ | |
instantiateHelloWorldMainClassAndRun(); |