Skip to content

Instantly share code, notes, and snippets.

View VictorTaelin's full-sized avatar

Victor Taelin VictorTaelin

View GitHub Profile
@VictorTaelin
VictorTaelin / ethereum_delayed_computations.md
Last active April 12, 2018 16:42
Make Ethereum massively scalable today with delayed computations

Make Ethereum massively scalable today with delayed computations

Suppose you're writing a contract which involves a huge amount of participants. As an example, think of an online, blockchain-based Trading-Card Game with tournaments. How would you program a playCard function? You might be thinking of something like this:

function playCard(uint player, uint card){
    ...
    else if (card == PROFESSOR_OAK){
        // shuffles the player's hand on his deck
 shuffleHand(player)
@VictorTaelin
VictorTaelin / c_doesnt_fuse.c
Created February 12, 2017 17:38
C doesn't fuse
#include <stdio.h>
#include <stdlib.h>
void add1(long len, long *array){
for (long i = 0; i < len; ++i)
array[i] = array[i] + 1;
}
long sum(long len, long *array){
long sum = 0;
@VictorTaelin
VictorTaelin / haskell_sometimes_fuses.hs
Created February 12, 2017 17:39
Haskell sometimes fuses
module Main where
import qualified Data.Vector.Unboxed as V
{-# INLINE add1 #-}
add1 :: V.Vector Int -> V.Vector Int
add1 = V.map (+ 1)
main :: IO ()
main = do
@VictorTaelin
VictorTaelin / bitcoin_moore_singularity_etc.js
Last active February 26, 2017 02:23
If Bitcoin's hashrate keeps increasing at the same rate, by the year 2025 private key cracking will be more rewarding than mining.
// Bitcoin's hash rate has been doubling once every 75 days in average. It
// varies a lot, though, but, assuming it keeps at least a similar pace, and
// assuming that guessing one private key has the same cost of a single hash,
// then, by the end of 2025, it will be more rewarding for miners to brute
// force private keys rather than mining.
let pow = x => Math.pow(2, x);
let log = x => Math.log(x) / Math.log(2);
let blockRate = block => Math.pow(2, 61.602060630030124) * 1.0000693171203765 * Math.pow(2, (block - 454667) / 10000);
@VictorTaelin
VictorTaelin / upload_a_pdf_with_swarm_js.js
Last active April 27, 2017 14:53
Upload a PDF with Swarm-js
// Various ways to upload a PDF with swarm-js
var swarm = require(".").at("http://swarm-gateways.net"); // use http://localhost:8500 if you're running swarm locally, or swarm.local(config, swarm => ...) if you want to run it with swarm-js
var fs = require("fs");
// Swarm can upload a PDF file directly from disk
// You can then access on browser bzz://hash
swarm.upload({path: "./sample.pdf", kind: "file"})
.then(console.log)
.catch(console.log);
@VictorTaelin
VictorTaelin / promise_monad.md
Last active October 24, 2024 01:25
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

-- Relevant resources:
-- http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html
-- http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html
-- This type allows expressing computations
-- with readLines and putLines inbetween.
-- It has nothing to do with Monads so far.
data Teletype a
= PutLn String (Teletype a)
@VictorTaelin
VictorTaelin / why.md
Last active August 12, 2017 22:54
What is wrong with the web and why we need Moon (draft)

What is wrong with the web and why we need Moon (draft)

A few days ago, I published an article about Moon, a fundamental building block of a decentralized browser that aims to solve many of Mist's problems. I've showed up some fancy features such as its decentralized package manager and a generalized monadic notation. I guess that made some people angry, wondering why the hell I made yet another programming language when we have so many of them. If you're on that group: you're right. I'm sorry. Believe me when I say I'm as tired of new languages as you, and I'm as pissed with myself as you are. But I'd not have done this if I didn't have a very good reason. Give me, thus, a chance to justify my sins. For one, I didn't actually invent a programming lang

all vars have different names:
((rename. (rename X.(a.(rename Y.(Y a)) X))) f.c.(f c))
-> (f.c.(f c) X.(a.(f.c.(f c) Y.(Y a)) X))
-> c.(a.c.(c a) c)
-> c.c.(c c)