Skip to content

Instantly share code, notes, and snippets.

Avatar

Viet vietlq

  • United Kingdom
View GitHub Profile
@vietlq
vietlq / Playing-with-js_of_ocaml.md
Last active Nov 10, 2018
Playing with js_of_ocaml
View Playing-with-js_of_ocaml.md

Playing with js_of_ocaml

A few years ago, while picking up basic OCaml, I found this site by Andrew Ray: https://andrewray.github.io/iocamljs/full402.html . This page has in-browser OCaml notebook. I was trying to modernise it and compile with OCaml 4.06.1. The vital part of the page is an ability to evaluate OCaml at run time in Javascript inside your browser. This is done by Js_of_ocaml. Learn basics of Js_of_ocaml in this post.

Hello World

Let’s do tradition “hello world” exercise, create a new file hello.ml:

let () =  
@vietlq
vietlq / pipes.ml
Created Sep 26, 2018 — forked from rizo/pipes.ml
Coroutine pipes in OCaml. Slides: <http://odis.io/talks/ocaml-coro.pdf>
View pipes.ml
type void
(* Core pipe type *)
type ('a, 'b, 'r) pipe =
| Yield of ('b * (unit -> ('a, 'b, 'r) pipe))
| Await of ('a -> ('a, 'b, 'r) pipe)
| Ready of 'r
View bipschnorr-Multisignature.md
View bipschnorr-Threshold.md
@vietlq
vietlq / bad_cpp03.md
Created Jul 27, 2018
Free eye check for C++03 devs
View bad_cpp03.md

Free eye check for my fellow C++03 devs, what's wrong with this:

for (size_t idx = myVector.size() - 1; idx >= 0; ++idx)
{
    doSomething(myVector[idx]);     
}

for (size_t idx = myVector.size() - 1; idx >= 0; --idx)
{
View lavoisier.ml
module Peano = struct
type z = Zero
type 'a s = Succ
type 'a t =
| Z : z t
| S : 'a t -> 'a s t
and zero = z t
let zero : z t = Z
View TwoOfThree.sh
# Raw transaction API example work-through
# Send coins to a 2-of-3 multisig, then spend them.
#
# For this example, I'm using these three keypairs (public/private)
# 0491bba2510912a5bd37da1fb5b1673010e43d2c6d812c514e91bfa9f2eb129e1c183329db55bd868e209aac2fbc02cb33d98fe74bf23f0c235d6126b1d8334f86 / 5JaTXbAUmfPYZFRwrYaALK48fN6sFJp4rHqq2QSXs8ucfpE4yQU
# 04865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac09ef122b1a986818a7cb624532f062c1d1f8722084861c5c3291ccffef4ec6874 / 5Jb7fCeh1Wtm4yBBg3q3XbT6B525i17kVhy3vMC9AqfR6FH2qGk
# 048d2455d2403e08708fc1f556002f1b6cd83f992d085097f9974ab08a28838f07896fbab08f39495e15fa6fad6edbfb1e754e35fa1c7844c41f322a1863d46213 / 5JFjmGo5Fww9p8gvx48qBYDJNAzR9pmH5S389axMtDyPT8ddqmw
# First: combine the three keys into a multisig address:
./bitcoind createmultisig 2 '["0491bba2510912a5bd37da1fb5b1673010e43d2c6d812c514e91bfa9f2eb129e1c183329db55bd868e209aac2fbc02cb33d98fe74bf23f0c235d6126b1d8334f86","04865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac09ef122b1a9
@vietlq
vietlq / README.md
Created Jun 13, 2018 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@vietlq
vietlq / README.md
Created Jun 11, 2018 — forked from dpwright/README.md
Monadic operations in C++
View README.md

Monadic operations in C++

This began as a further attempt to implement the Maybe monad in C++, but quickly spiralled out of control and now includes an implementation of the List monad as well (using std::list!). This is really for my own amusement rather than to try and do anything useful with them. It also gave me an excuse to try out C++ 11 lambda functions for the first time.

My original implementation defined a macro called MBind which caused a number of problems -- thankfully [PJayB][pjayb] managed to find a way around that so

You can’t perform that action at this time.