Skip to content

Instantly share code, notes, and snippets.

Erlang honors cgroup CPU quota from Erlang 23. But when less than 1 CPU is used, schedulers_online will be cores number(see below k8s 0-5).

docker

$ docker run --rm -it --cpu-period 100000 --cpu-quota 100000 erlang:23 bash
root@3f793576001a:/# erl
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:4:1] [ds:4:1:10] [async-threads:1] [hipe]
@tony612
tony612 / arcanist_cheatsheet.md
Last active July 7, 2023 05:29 — forked from sekimura/gist:6367366
arcanist cheatsheet
  • create tasks T{NNNN} asign them
  • create a branch with name like "T{NNNN}-boo-hoo"
  • git checkout -b T1234-boo-foo
  • commit changes on that branch until it gets ready to be reviewed
  • git commit -am 'first'
  • git commit -am 'now it works'
  • check if it's lint free (NOTE: it runs lint against only modified files)
  • arc lint
  • push a review request to the server. This will create a diff with id D{NNNN}
  • arc diff
@tony612
tony612 / gencert.go
Last active June 14, 2023 04:48
generate x509 cert and key
package main
import (
"bytes"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
@tony612
tony612 / multi.go
Last active June 30, 2022 12:38
grpc one connection vs multiple connections (one: 13.8s, multi: 17s)
package main
import (
"log"
"os"
"sync"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
package main
// Run this in root of https://github.com/vscode-kubernetes-tools/vscode-kubernetes-tools
// `snippets` dir is used.
// Somehow vscode can't show snippets by default.
import (
"encoding/json"
"fmt"
"io/fs"
@tony612
tony612 / client.go
Created February 24, 2022 09:43 — forked from xjdrew/client.go
golang tls client and server, require and verify certificate in double direction
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io"
"io/ioutil"
"log"
"os"
export USERNAME=myadmin
export GROUPNAME=myadmin
export CERTIFICATE_NAME=myadmin
openssl genrsa -out ${USERNAME}.key 2048
openssl req -new -key ${USERNAME}.key -out ${USERNAME}.csr -subj "/CN=${USERNAME}/O=${GROUPNAME}"
cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1beta1
kind: CertificateSigningRequest
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
int main(void) {
size_t pagesize = getpagesize();
printf("System page size: %zu bytes\n", pagesize);
@tony612
tony612 / read_until_eof.py
Created February 17, 2020 09:33
Python read from stdin
def read_until_eof():
buffer = ''
batch_size = 1024
while True:
ready, _, _ = select.select([sys.stdin], [], [], 0.0)
if sys.stdin not in ready:
continue
# Don't know why, but sys.stdin.read() and sys.stdin.readline()
# will cause EPIPE when writting to stdout
defmodule BinaryParseSlow do
def parse(bin) do
parse(bin, 0)
end
def parse(bin, acc) do
case do_parse(bin) do
{:nofin, x, rest} ->
parse(rest, acc + x)
{:fin, x} ->