Angel \”Java\” Lopez on Blog

April 28, 2016

Redis: Links, News And Resources (7)

Filed under: Links, NoSQL, Redis — ajlopez @ 8:43 am

Previous Post
Next Post

Securing Redis with Sedona – Will Urbanski on Vimeo

Announcement: Redis Monitoring in SPM | Sematext Blog

Running Redis as a Windows Service – CodeProject

Forrst | How I make models in Node.js (using Redis as database) – Some code from jackbach

Redis Cluster and limiting divergences. – Antirez weblog

Using Redis sorted sets to build a scalable real-time web waiting list. | The Carbon Emitter


High Scalability – High Scalability – How HipChat Stores and Indexes Billions of Messages Using ElasticSearch and Redis

Knossos: Redis and linearizability




Some fun with Redis Cluster testing – Antirez weblog

Redis as AP system, reloaded – Antirez weblog

Redis cluster tutorial – Redis

Redis Sentinel Documentation – Redis

My Links

Stay tuned!

Angel “Java” Lopez

April 25, 2016

Building A Blockchain (6)

Previous Post
Next Post

These days, I added transaction processing to my personal project:

In the previous post, I described the immutable Trie structure. Now, I have an AccountState that is saved by hash in a such Trie:

public class AccountState
    private BigInteger balance;

    public AccountState(BigInteger balance)
        if (BigInteger.Compare(BigInteger.Zero, balance) > 0)
            throw new InvalidOperationException("Invalid balance");

        this.balance = balance;

    public BigInteger Balance { get { return this.balance; } }

    public AccountState AddToBalance(BigInteger amount)
        return new AccountState(BigInteger.Add(this.balance, amount));

    public AccountState SubtractFromBalance(BigInteger amount)
        return new AccountState(BigInteger.Subtract(this.balance, amount));

I decided to implement the Ethereum way: having an account state, instead of inputs and outputs. The only property is Balance, but I will add more data. Notice that negative balances are rejeceted. Then, I added a TransactionProcessor:

public class TransactionProcessor
    private Trie<AccountState> states;

    public TransactionProcessor(Trie<AccountState> states)
        this.states = states;

    public Trie<AccountState> States { get { return this.states; } }

    public bool ExecuteTransaction(Transaction transaction)
        var states = this.states;

            foreach (var av in transaction.Inputs)
                var addr = av.Address.ToString();
                var state = states.Get(addr);
                var newstate = state.SubtractFromBalance(av.Value);
                states = states.Put(addr, newstate);

            foreach (var av in transaction.Outputs)
                var addr = av.Address.ToString();
                var state = states.Get(addr);
                var newstate = state.AddToBalance(av.Value);
                states = states.Put(addr, newstate);

            this.states = states;

            return true;
        catch (Exception ex)
            return false;

If the transaction is processed, a new account state trie is generated, and ExecuteTransaction returns true. If the transaction is rejected, the initial accout state trie still has the original values. A typical test:

public void ExecuteTransaction()
    var transaction = CreateTransaction(100);

    var addr1 = transaction.Inputs.First().Address;
    var addr2 = transaction.Outputs.First().Address;

    var states = new Trie<AccountState>(new AccountState(BigInteger.Zero));

    states = states.Put(addr1.ToString(), new AccountState(new BigInteger(200)));

    var processor = new TransactionProcessor(states);


    var newstates = processor.States;

    Assert.AreNotSame(states, newstates);

    Assert.AreEqual(new BigInteger(200), states.Get(addr1.ToString()).Balance);
    Assert.AreEqual(BigInteger.Zero, states.Get(addr2.ToString()).Balance);

    Assert.AreEqual(new BigInteger(100), newstates.Get(addr1.ToString()).Balance);
    Assert.AreEqual(new BigInteger(100), newstates.Get(addr2.ToString()).Balance);

The auxiliary CreateTransaction method creates a transaction with an amount, and two random addresses.

I’m thinking to have only one sender account and receiving account per transaction, as in Ethereum. The change is easy, I have all the TDD tests to help me to do redesigns without a lot of work.

Next topics: executing blocks with transactions, saving state in persistent store, virtual machine and its bytecodes, a simple compiler, etc…

Stay tuned!

Angel “Java” Lopez

April 23, 2016

ReactJS: Links And Resources (4)

Filed under: JavaScript, Links, React, Web Development — ajlopez @ 9:02 am

Previous Post
Next Post

Jed Watson – Going Mobile with React at react-europe 2015 – YouTube

Pure UI

Tag Archive for “javascript” | Scotch

Lee Byron – Exploring GraphQL at react-europe 2015 – YouTube

Dan Abramov – Live React: Hot Reloading with Time Travel at react-europe 2015 – YouTube

React Native Playground: Share and test your React Native code in the browser

WinJS 4.0 Is Compatible with AngularJS, React, Bootstrap and Knockout

Mutations in Relay // Speaker Deck

Harrison Harnisch: React native and Meteor — Devshop SF April 2015 – YouTube

Max Harris: Two weeks with React Meteor — Devshop SF March 2015 – YouTube

CS 294-101 01 Pete Hunt: React vs The World – YouTube

Reagent • TodoMVC

My Links

Stay tuned!

Angel “Java” Lopez

April 17, 2016

Building A Blockchain (5)

Filed under: Bitcoin, Blockchain, C Sharp, Ethereum, Test-Driven Development — ajlopez @ 10:02 am

Previous Post
Next Post

I was working a lot on my personal project:

implementing a blockchain in C#, using TDD (Test-Driven Development) workflow. One element I need to implement, is the store of account states (initially their balances). The balance of an account should be retrieved by account id (a hash). But in many use cases, I need to know the balances of accounts at a given time. It is not enough to have the LATESTS balances. So, I implemented a data structure, a trie, but with immutable properties.

A trie is a tree where the non-leaf nodes stores part of the key:

In the above example, the value V1 is associated with key AAA, and the value V5 is associated with key ACA. When I change the value associated with key ABC from V4 to V7, part of a new trie is created, so the original one persists without modification:

I can access the original key/values using the “old root”, and then, I can switch to use the “new root”, at any moment. If any node/root is not reachable from a variable, garbage collector will release the memory associated with that node.

I wrote a typed trie implementation, using TDD. An example test:

public void PutAndGetKeyValue()
    Trie<string> trie = new Trie<string>();

    var trie2 = trie.Put("012", "foo");

    Assert.AreNotSame(trie2, trie);
    Assert.AreEqual("foo", trie2.Get("012"));

An example that shows the persistent of tries after updates:

public void ReplaceValue()
    Trie<string> trie = new Trie<string>();

    var trie2 = trie.Put("012", "foo");
    var trie3 = trie2.Put("012", "bar");

    Assert.AreNotSame(trie2, trie);
    Assert.AreEqual("foo", trie2.Get("012"));

    Assert.AreNotSame(trie3, trie2);
    Assert.AreEqual("bar", trie3.Get("012"));

My idea is to use Trie<AccountState> as a store for account balances. At the end of a block (with transactions) processing, there is an account state trie. Ant the end of the next block processing, another trie will be generated. At any moment, I could retrieve the account balances at time “block 1”, and at time “block 2”, using the generated tries.

Stay tuned!

Angel “Java” Lopez

April 11, 2016

Building A Blockchain (4)

Filed under: Bitcoin, Blockchain, C Sharp, Ethereum, Open Source Projects — ajlopez @ 10:20 am

Previous Post
Next Post

In this post, I want to describe the key parts of a blockchain example I’m writing at:

using C# and TDD (Test-Driven Development). The essential things to be implemented are:

– Blocks
– Transactions

the concepts of:

– Account
– Account State
– Smart Contracts (executed in a virtual machine)

and utilities for:

– Encode/Decode entities to be transmited/received via the network of nodes
– Hash calculations
– Immutable tries
– Sign transactions
– Verify transaction sign
– Verify block integrity
– Verify transactions are valid
– Proof of Work calculation (as usual in Bitcoin and Ethereum implementations)
– Store some entities: complete blocks, partial blocks (block headers in Ethereum), account state, … in general, tries with storage

Some days ago, I started to write a Transaction class, having pairs of accounts and values. I adopted Ethereum approach: instead of having inputs/outputs as in Bitcoin, I have accounts with balances/states. Each account is identified by an address (actually a random hexadecimal string):

Each transaction can have one or more inputs and outputs. Each input/output has an account address and a value. The values are instances of BigInteger, so I can manage large integer numbers. It’s the way the criptocurrencies implementations allow the use of value fractions: the unity is a power of 10, and the amounts are expressed in integer quantity of minimal fractions.

Next steps: add transactions to blocks, apply transaction to account states, validate that input values are available, store states in an immutable trie,…

Stay tuned!

Angel “Java” Lopez

April 9, 2016

New Month’s Resolutions: Aprill 2016

Filed under: Blockchain, C Sharp, Ethereum, JavaScript, NodeJs, Open Source Projects, SimpleForth — ajlopez @ 4:34 pm

A new month started, and it’s time to write the new resolutions. And to review the past month ones:

– Improve AjGenesisNode-Express [pending]
– Work on CrysJS [complete] see repo
– Work on CrysSharp [pending]
– Improve my SimpleGA samples [pending
– Work on SharpGo [pending]
– Work on EthSharp [complete] see repo

Also I worked on:

– Improve SimpleForth in JavaScript [complete] see repo
– Start WangTiles in C# [complete] see repo
– Publish new version of SimpleArgs [complete] see repo
– Start BlockchainSharp in C# [complete] see repo
– Improve SimpleDT samples [complete] see repo
– Move AjGo to GitHub [complete] see repo
– Improve RuScript [complete] see repo
– Add Code Coverate to ethereumjs rlp [complete] see repo
– New Machine Learning in JavaScript presentation [complete] see repo see talk

My new resolutions:

– Improve WangTiles
– Improve BlockchainSharp
– Start Blockchain in JavaScript
– Work on EthSharp
– Improve SimpleGA
– Improve AjGenesisNode-Express
– Work on CrysJS
– Work on CrysSharp

Stay tuned!

Angel “Java” Lopez

April 8, 2016

Ethereum: Links, News And Resources (3)

Filed under: Bitcoin, Blockchain, Ethereum, Links — ajlopez @ 9:23 am

Previous Post

LE12: Sergio Lerner – RootStock and Smart Contract Platforms – Liberty Entrepreneurs Podcast

ConsenSys (@ConsenSysLLC) | Twitter

Christian Lundkvist (@ChrisLundkvist) | Twitter – Blockchain IoT

Eight Months Since Release, Ethereum Is Second Only To Bitcoin

– MANÐΞLΞIL – (@mandeleil) | Twitter

The Ether Review (@etherreview) | Twitter

The Ether Review #16 – Dominic Williams, Synthetic Assets by Arthur Falls

Microsoft’s Marley Gray: Ripple and ILP Will Be the Fabric of Multi-Chain Future | Ripple

Azure Blockchain as a Service update | Blog | Microsoft Azure

Dapp Developer Resources · ethereum/wiki Wiki

From Smart Contracts to Courts with not so Smart Judges – Ethereum Blog

Microsoft continues its blockchain-as-a-service push | ZDNet

Ethereum messaging for the masses (including fathers) – via infographic – Ethereum Blog

EthereumVibes (@EthereumVibes) | Twitter

Ukraine Embraces Ethereum Blockchain For Election Transparency – NEWSBTC


My Links

Stay tuned!

Angel “Java” Lopez

April 7, 2016

Clojure: Links, News And Resources (24)

Filed under: Clojure, Functional Programming, Links, Programming Languages — ajlopez @ 10:06 am

Previous Post

Clojure powered robot 3 of 3 – YouTube

Clojure powered robot 2 of 3 – YouTube

Clojure powered robot 1 of 3 – YouTube

OSCON 2013: Carin Meier, "The Joy of Flying Robots with Clojure" – YouTube

Macros vs. Monads

Functional Infrastructures: It’s All Fn until You Hit Production


Clojure-based, R-like statistical computing and graphics environment for the JVM

Hammock Driven Development – Rich Hickey – YouTube

Skills Matter : Clojure eXchange 2013 06-12-13

Clojure library for symbolic computation

cemerick/austin · GitHub
The ClojureScript browser-REPL rebuilt stronger, faster, easier.

justiniac/clotilde · GitHub
The Linda process coordination language written in Clojure.

mountain/knowledge · GitHub
combining wikidata and clojure core.logic

FRP in ClojureScript with Javelin

Concurrent Bayes Classifiers in Clojure | Ascii Rain

Cascalog – Clojure-based query language for Hadoop – The Changelog

symbols – In Clojure, how to define a variable named by a string? – Stack Overflow

Discrete Event Simulation Specification

Introduction to web application development in Clojure

MQTT in Clojure with the core.async library | Clojure in a bank

REST in Peace

My Links

Stay tuned!

Angel “Java” Lopez

April 4, 2016

Building A Blockchain (3)

Previous Post
Next Post

I added a lot of code to my simple blockchain implementation written in C#:

As usual, I followed TDD (Test-Driven Development) workflow, pursuing simplicity, doing baby steps. In the last post I mentioned the use of a DSL (Domain Specific Language) to specify some block processing tests that have complex setup.

Initially, I wrote tests like:

public void ProcessTwoBlocksAndTwoUncles()
    Block genesis = new Block(0, null);
    Block block = new Block(1, genesis.Hash);
    Block uncle1 = new Block(1, genesis.Hash);
    Block uncle2 = new Block(2, uncle1.Hash);

    BlockProcessor processor = new BlockProcessor();


    Assert.AreEqual(2, processor.BlockChain.BestBlockNumber);
    Assert.AreEqual(genesis, processor.BlockChain.GetBlock(0));
    Assert.AreEqual(uncle1, processor.BlockChain.GetBlock(1));
    Assert.AreEqual(uncle2, processor.BlockChain.GetBlock(2));

The idea is:

– Create some blocks

– Send the blocks to the block processor

– Check the blocks in the block chain

The created blocks are related by parent relationships. Sometimes, a competing block is created, so the block processor must deal with block branches.

But the setup code could be long and complex. So, I wrote a DSL, and now I have tests like:

public void SendTwoBlocksAndTwoUncles()
    var processor = new BlockProcessor();
    var dsl = new BlockProcessorDsl(processor);

    dsl.Run(new string[] 
        "chain g0 b1 b2",
        "chain b1 c2 c3",
        "send b1 b2",
        "send c2 c3",
        "top c3"

Each command is an string, with verb and arguments. The block g0 is the genesis block. The verb “chain” enumerates a list of blocks to be created, each block is child of its previous block. The verb “send” sends the created blocks to the block processor. The verb “top” checks if the specified block is the top block in the current blockchain.

The result should not depend on order of arriving blocks, ie:

public void SendTwoBlocksInReversedOrder()
    var processor = new BlockProcessor();
    var dsl = new BlockProcessorDsl(processor);

    dsl.Run(new string[] 
        "chain g0 b1 b2",
        "send b2 b1",
        "top b2"

I could add text files, each one specifying command lines to be executed as sentences of the DSL.

In the next posts: core implementations needed by a blockchain, byte serialization, and implementing immutable tries for storing states.

Stay tuned!

Angel “Java” Lopez

April 1, 2016

Clojure: Links, News And Resources (23)

Filed under: Clojure, Links, Lisp, Programming Languages — ajlopez @ 8:48 am

Previous Post
Next Post

clj-wamp ~ Clojure WebSocket subprotocol for HTTP Kit

Purely functional data structures in Clojure: Red-Black Trees – Leonardo Borges

Clojure and LLVM

Clojure, Neo4j and Domain Specific Languages Applied to Lisp and Cancer – Ola Bini in Hamburg in Hamburg | XING Events

7 Languages in 7 Workshops: Clojure – Cambridge Software Craftsmanship (Cambridge, England) – Meetup

Getting Started


Introducing HipHip (Array): Fast and flexible numerical computation in Clojure — Prismatic Blog

In Retrospect: QCon NYC 2013 (and a conversation with Rich Hickey on languages) « Inviting Epiphany

Clojure/West Content on InfoQ

Rock Paper Scissors with core.async : Pure Danger Tech

Blog | Rich Hickey and core.async – Podcast Episode 035 | Relevance

Clojure – The Last Programming Language by Robert C. Martin at NDC 2011 at Oslo, Norway –

Leiningen 2 – Humane build management for Clojure

Clojure, core.async and the Lisp advantage – Leonardo Borges


Using java.jdbc | Clojure Documentation | Clojure Docs


Pedestal Documentation – Application Introduction


Fluokitten – Category Theory in Idiomatic Clojure


My Links

Stay tuned!

Angel “Java” Lopez

« Newer PostsOlder Posts »

The Shocking Blue Green Theme. Create a free website or blog at


Get every new post delivered to your Inbox.

Join 73 other followers