Skip to content

Instantly share code, notes, and snippets.

@et4te
et4te / stub.js
Created January 15, 2019 15:39
Wrap the compiled js_of_ocaml with a function (here I called it OCamlLoader()), load some dependencies and then load the OCaml
let HACL = HaclLoader();
let sha256_init = HACL._Hacl_SHA2_256_init;
let sha256_update = HACL._Hacl_SHA2_256_update;
let sha256_finish = HACL._Hacl_SHA2_256_finish;
let state
let state_buffer
let message
let message_buffer
@et4te
et4te / rpc
Created January 10, 2019 22:35
>>>>0: http://127.0.0.1:3334/chains/main/blocks/head/helpers/preapply/block?timestamp=1547159688
{ "protocol_data":
{ "protocol": "Psja6zej992fWzGrpHWcPogr7hHdYruacv55eVNxK5xbkdzgTFu",
"content":
{ "command": "activate",
"hash": "PsgE752NCVtx2nxEFtBw2LS6i6ZMXzuFwtfebAsHTGxpYR2ygrn",
"fitness": [ "00", "0000000000000001" ],
"protocol_parameters":
"000005a8a805000004626f6f7473747261705f6163636f756e747300cc01000004300058000000023000370000006564706b75426b6e5732386e5737324b4736526f48745957377031325436474b63376e4162775958356d385764397344564339796176000231000e00000034303030303030303030303030000004310058000000023000370000006564706b747a4e624441556a556b36393757376759673243527542516a79507862456738644c63635959774b534b766b50766a745639000231000e00000034303030303030303030303030000004320058000000023000370000006564706b7554586b4a4447634664356e683656764d7a38706858785533426937683668716779774e466931765a5466514e6e53315256000231000e0000003430303030303030303
@et4te
et4te / resource_unavailable.ml
Created January 9, 2019 15:54
Reads by forcing non-blocking on the fd and doesn't explicitly retry on the errors
open Lwt
open Lwt_unix
let read fd =
let maxlen = 1024 in
let buf = Bytes.create maxlen in
Lwt.catch
(fun _ ->
Lwt_log.info "reading" >>= fun () ->
let len = Unix.read (Lwt_unix.unix_file_descr fd) buf 0 maxlen in
@et4te
et4te / timeout.ml
Created December 12, 2018 01:29
Times out if can't read
open Lwt
open Lwt_unix
let read fd =
let maxlen = 1024 in
let buf = Bytes.create maxlen in
Lwt.catch
(fun _ ->
Lwt_log.info "reading" >>= fun () ->
Lwt.pick [
@et4te
et4te / michelson-mode.el
Created August 4, 2018 16:40
Removed lexical-lets from the source (doesn't work on later versions of emacs than 24.1)
;; Major mode for editing Michelson smart contracts.
(require 'cl-lib)
(require 'deferred)
(require 'font-lock)
(defvar michelson-mode-hook nil)
(defgroup michelson nil
"Major mode for editing Michelson smart contracts."
@et4te
et4te / htlc.ml
Last active August 5, 2018 09:36
Tezos Atomic Swap
[%%version 0.3]
type storage =
{ version : string;
secret_hash : bytes;
issuer : address;
issuer_hash : key_hash;
recipient_hash : key_hash;
timeout : timestamp;
}
@et4te
et4te / install_nix.md
Last active June 23, 2018 17:14
Preparing for betanet launch with Nix and the Ledger Nano S

Preparing for betanet launch with Nix and Ledger Nano S

This guide is for users of the Nix package manager and assumes you have a Ledger Nano S updated with the latest firmware (at this time 1.4.2).

NOTE If you are not on NixOS, skip the sections which have NixOS at the start of the heading.

NixOS Binary Cache Configuration

To hasten the build process (it could take days to build without this), add the following to /etc/nixos/configuration.nix if you are on NixOS.

@et4te
et4te / salsa20_hash.rs
Created October 5, 2017 19:25
salsa20
#![feature(slice_patterns)]
pub fn quarter_round(y: [u32; 4]) -> [u32; 4] {
let z1 = y[1] ^ (y[0].wrapping_add(y[3])).rotate_left(7);
let z2 = y[2] ^ (z1.wrapping_add(y[0])).rotate_left(9);
let z3 = y[3] ^ (z2.wrapping_add(z1)).rotate_left(13);
let z0 = y[0] ^ (z3.wrapping_add(z2)).rotate_left(18);
[z0, z1, z2, z3]
}
#[derive(Debug)]
enum BinaryTree<T: Ord> {
Leaf {
lhs: Box<BinaryTree<T>>,
rhs: Box<BinaryTree<T>>,
val: (T, Value),
},
Empty,
}
@et4te
et4te / perfomEventAsync.hs
Last active August 26, 2017 14:08
An example of performEventAsync use Reflex
performHash :: (MonadWidget t m) => (Either String Hash -> IO ()) -> Event t Text -> m (Event t (Either String Hash))
performHash cb e = do
evHash <- performEventAsync $ ffor e $ \p cb -> void $ newHash p $ liftIO . cb
return evHash
where
newHash p = liftIO . hash (defaultOptions p "some_salt")