Skip to content

Instantly share code, notes, and snippets.

View wu-s-john's full-sized avatar

John Wu wu-s-john

View GitHub Profile
module Reader = struct
type 't t = {reader: 't Pipe.Reader.t; mutable has_reader: bool}
let wrap_reader reader = {reader; has_reader= false}
let set_has_reader reader =
if reader.has_reader then raise Multiple_reads_attempted
else reader.has_reader <- true
let map reader ~f =
@wu-s-john
wu-s-john / hacks.sh
Created January 30, 2019 22:55
Cleaning annoying build incompatibility dependencies in CODA
remove_snark_() {
rm -rf _build/default/src/lib/snark_params
}
@wu-s-john
wu-s-john / 18-mutable_records_problem.ml
Created February 4, 2019 21:26
Problem 18 Mutable Records of Jane Street's Functional Programming Tutorail
open! Base
(* Sometimes rather than redefining the record you would like to have a field or
a set of fields that you can modify on the fly.
In OCaml if you want to have a field in a record that can be updated in place
you must use some additional syntax. The mutable keyword makes the field
modifiable.
Then you can use <- to set the record value to a new value. *)
@wu-s-john
wu-s-john / coda_hacks.ml
Last active February 21, 2019 18:36
Run a test of an individual file in dune
open Core
open Async
let get_directory filename = Core.Filename.dirname filename
let compilation_dir = "_build" ^/ "default"
let inline_test_runner_arg = "inline-test-runner"
let only_test_arg = "-only-test"
let%test "peers can provide transitions with length between max_length to \
2 * max_length" =
let logger = Logger.create () in
Thread_safe.block_on_async_exn (fun () ->
let%bind me = create_root_frontier ~logger Genesis_ledger.accounts in
let%bind peer =
create_root_frontier ~logger Genesis_ledger.accounts
in
let my_root = Transition_frontier.root me in
let peer_root = Transition_frontier.root peer in
@wu-s-john
wu-s-john / peano_ppx.ml
Last active May 29, 2019 05:36
Demo to easily create peano numbers with ppxs
open Ppxlib
open Asttypes
(** Ppx to create a type level form of a natural number
Usage:
type t = [%nat 3]
This will become
@wu-s-john
wu-s-john / database_demo.ml
Created August 18, 2019 17:17
Made postgres request using Postgres and Async
open Core
open Async
let () =
Sexp.to_string_hum [%sexp ([3;4;5] : int list)]
|> print_endline
let create_table =
Caqti_request.exec
Caqti_type.unit
@wu-s-john
wu-s-john / keybase.md
Created August 31, 2019 03:24
keybase.md

Keybase proof

I hereby claim:

  • I am wu-s-john on github.
  • I am johnswu (https://keybase.io/johnswu) on keybase.
  • I have a public key ASB3SRBomnIHmcE3mVsuyRp9KIpNOvdFQO_JYUxdAibq8wo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am wu-s-john on github.
  • I am johnswu (https://keybase.io/johnswu) on keybase.
  • I have a public key ASB3SRBomnIHmcE3mVsuyRp9KIpNOvdFQO_JYUxdAibq8wo

To claim this, I am signing this object:

User_command_insert

{"query": "mutation transaction_insert($user_commands: [user_commands_insert_input!]!)  {
insert_user_commands(objects: $user_commands, on_conflict: {constraint: user_commands_hash_key, update_columns: first_seen})  {
returning  {
id  
hash  
first_seen