Skip to content

Instantly share code, notes, and snippets.

def okx_signing(config, %{url: url, body: body, method: method}) do
secret = config["okx_secret_key"]
access_key = "your access key"
timestamp = DateTime.utc_now() |> DateTime.truncate(:millisecond) |> DateTime.to_iso8601()
%{path: path, query: query} = URI.new!(url)
data = timestamp <> method <> path <> "?" <> query <> body
sign = :crypto.mac(:hmac, :sha256, secret, data) |> Base.encode64()

cryptopals.com

Untitled

defmodule CryptoPals do
  def base16to64(x) do
    x
    |> Base.decode16!(case: :lower)
    |> Base.encode64()

bsv

Mix.install([
  {:bsv, "~> 2.1"}
])

Section

@Ljzn
Ljzn / ubuntu.sh
Created September 22, 2022 06:07
to fix ssl error on ubuntu:latest
curl -Lo roots.pem https://pki.google.com/roots.pem
export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem"
apt-get install ca-certificates
@Ljzn
Ljzn / compile.sh
Created September 10, 2022 01:04
compile bitcoind on ubuntu20
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils libboost-all-dev
./autogen.sh
mkdir build
cd build
../configure --disable-wallet
make
@Ljzn
Ljzn / sql_db.ex
Created January 15, 2021 10:26
benchmark BTree vs List
defmodule SqlDb do
@moduledoc """
# Benchmark of Save and Find
Name ips average deviation median 99th %
btree 50.43 0.0198 s ±6.77% 0.0197 s 0.0268 s
list 0.85 1.18 s ±0.28% 1.17 s 1.18 s
Comparison:
btree 50.43
@Ljzn
Ljzn / playground.rs
Created August 1, 2020 08:04 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
// Linjie Zhang 2020
//
// 3-state busy beaver
// https://en.wikipedia.org/wiki/Turing_machine
let rules = vec!["A01RB", "A11LC", "B01LA", "B11RB", "C01LB", "C11RH"]
.iter()
.map(|x| x.chars().collect::<Vec<char>>())
.collect::<Vec<_>>();
@Ljzn
Ljzn / playground.rs
Created August 1, 2020 06:01 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
// Linjie Zhang 2020
//
// T simple turing machine
//
// https://plato.stanford.edu/entries/turing-machine/#DefiTuriMach
#[derive(Debug)]
struct Machine {
<mxfile host="localhost" modified="2020-05-18T07:49:48.710Z" agent="5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.45.0 Chrome/78.0.3904.130 Electron/7.2.4 Safari/537.36" etag="lm6PZiSR0-wQZ33-puXF" version="13.0.9">
<diagram id="6hGFLwfOUW9BJ-s0fimq" name="Page-1">
<mxGraphModel dx="483" dy="592" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;curved=1;" edge="1" parent="1" source="12" target="13">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="15" style="edgeStyle=orthogonalEdgeStyle;curved=1;rounded=0;