Skip to content

Instantly share code, notes, and snippets.

View heri16's full-sized avatar

heri16 heri16

View GitHub Profile
@heri16
heri16 / erlang-macos.sh
Created July 27, 2023 19:45
Erlang for bun:ffi
# Install asdf
brew install coreutils git
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0
cat <<EOF >> ~/.zshrc
. "$HOME/.asdf/asdf.sh"
# append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)
# initialise completions with ZSH's compinit
autoload -Uz compinit && compinit
EOF
@heri16
heri16 / Dockerfile
Last active April 6, 2023 08:53
Automate login to keybase using Expect TCL
FROM keybaseio/client:stable-slim
RUN apt-get update && apt-get install -y expect
COPY keybase-provision.sh /provision.sh
RUN chmod +x /provision.sh
CMD ["/provision.sh", "keybase", "chat", "send", "--channel", "'#general'", "stockbitcrypto", "'Hello World from bot'"]
package main
import (
"fmt"
"net/http"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@heri16
heri16 / README.md
Last active October 19, 2021 10:56
Binary encoding of OUCH messages in Elixir

Reuse logic in Elixir

Here are commons ways to reuse logic in Elixir:

1a. Move Function to other module (guards, pattern-matching) 1b. Protocol - Polymorphism

  1. Behaviour Dynamic-func - with def method_name(implemetation, args)
@heri16
heri16 / flatten_array.ex
Created August 26, 2021 16:19
Elixir Flatten array (with tail recursion)
defmodule FlattenArray do
@doc """
Accept a list and return the list flattened without nil values.
## Examples
iex> FlattenArray.flatten([1, [2], 3, nil])
[1,2,3]
iex> FlattenArray.flatten([nil, nil])
@heri16
heri16 / .README.md
Last active October 2, 2021 17:24
Install Elixir on macOs

Instructions

brew update
brew install asdf [email protected]
EDITOR=nano brew edit wxmac # Edit the file according to wxmac.patch
brew install wxmac --build-from-source

asdf plugin add erlang
asdf plugin add elixir
@heri16
heri16 / playground.go
Last active September 9, 2021 08:51
Nasdaq OUCH_4.2 golang
package main
import (
"bytes"
"encoding"
"encoding/binary"
"io"
"fmt"
"stockbit.com/proto/ouch42"
@heri16
heri16 / .README.md
Last active August 30, 2021 07:49
Build & Install eixx C++ library

macOS / darwin

Install Dependencies

# Build-time Deps
brew install cmake
# brew install gcc@10
pip3 install gil
@heri16
heri16 / slice.go
Created July 26, 2021 10:50
Golang - convert slice such as []string to []interface{}
module slice
func InterfaceSlice(slice interface{}) []interface{} {
switch slice := slice.(type) {
case []string:
new := make([]interface{}, len(slice))
for i, v := range slice {
new[i] = v
}
return new
@heri16
heri16 / yup.ts
Last active June 29, 2021 05:39
Yup validate input for too many decimals to prevent ethers.js BigNumber / BigInt underflow
let decimals = 4;
const regexpDecimals = new RegExp(`^\\d*\\.{0,1}\\d{0,${decimals}}$`);
const SignupSchema = Yup.object().shape({
decimal: Yup.number().test(
'is-decimal',
'too many decimals',
value => (value + "").match(regexpDecimals),
),
});