Skip to content

Instantly share code, notes, and snippets.

View Yapcheekian's full-sized avatar

Yap Yapcheekian

View GitHub Profile
@Yapcheekian
Yapcheekian / concurrent.txt
Last active December 31, 2021 10:42
Process vs coroutines vs thread
https://stackoverflow.com/questions/3324643/processes-threads-green-threads-protothreads-fibers-coroutines-whats-the
https://stackoverflow.com/questions/46864623/which-of-coroutines-goroutines-and-kotlin-coroutines-are-faster
@Yapcheekian
Yapcheekian / slices.go
Created August 9, 2021 13:56
Notes on go slices
var arrNum [5]int // this is an array
var sliceNum []int // this is a slice
fmt.Println(arrNum) // [5]int{0,0,0,0,0} array have initial value of zero value
fmt.Println(sliceNum) // []int(nil) slice have initial value of nil value
sliceNum == nil // true
arrNum[0] = 1 // ok
sliceNum[0] = 1 // compile time error because you cannot assign values to nil
@Yapcheekian
Yapcheekian / e_net.sh
Last active August 5, 2021 00:46
capture pod packet
#!/usr/bin/env bash
# https://mp.weixin.qq.com/s?__biz=MzA4MzIwNTc4NQ==&mid=2247484821&idx=1&sn=aaa173a8b913cc759c56efe05d2c15ad&chksm=9ffb4e63a88cc7755ca720b3886946245246d8e57687cf209ad47f61a186cc290c04ef57fc91&scene=21#wechat_redirect
function e_net() {
set -eu
pod=`kubectl get pod ${pod_name} -n ${namespace} -o template --template='{{range .status.containerStatuses}}{{.containerID}}{{end}}' | sed 's/docker:\/\/\(.*\)$/\1/'`
pid=`docker inspect -f {{.State.Pid}} $pod`
echo -e "\033[32m Entering pod netns for ${namespace}/${pod_name} \033[0m\n"
cmd="nsenter -n -t ${pid}"
echo -e "\033[32m Execute the command: ${cmd} \033[0m"
@Yapcheekian
Yapcheekian / notes.md
Last active July 28, 2021 16:43
Docker security hardening
docker run -it --rm -u yap ubuntu /bin/bash # run as non-root user

docker run -it --rm --security-opt=no-new-privileges ubuntu /bin/bash

docker run -it --rm --cap-drop all --cap-add NET_ADMIN ubuntu /bin/bash

docker run -it --rm --read-only --tmpfs /opt ubuntu /bin/bash
@Yapcheekian
Yapcheekian / sorting_algorithm.go
Last active July 28, 2021 01:46
selection sort, bubble sort, insertion sort, merge sort, quick sort
func selectionSort(items []int) {
for x := 0; x < len(items) - 1; x++ {
min := x
for y := x+1; y < len(items); y++ {
if items[y] < items[min] {
min = y
}
}
items[x], items[min] = items[min], items[x]
}
@Yapcheekian
Yapcheekian / template.json
Created July 16, 2021 02:44
Create elasticsearch index template
PUT /_template/fluentbit
{
"fluenbit" : {
"order" : 0,
"index_patterns" : [
"fluentbit-*"
],
"settings" : {
"index" : {
"number_of_shards" : "10"
@Yapcheekian
Yapcheekian / debug.txt
Created June 30, 2021 02:58
Cert manager debug
kubectl get certificaterequest
kubectl describe certificaterequest X
kubectl get order
kubectl describe order X
kubectl get challenge
kubectl describe challenge X
@Yapcheekian
Yapcheekian / aws-ssm-ec2-proxy-command.sh
Last active June 15, 2021 03:54
ssh tunneling with ssm
set -eu
REGION_SEPARATOR='--'
ec2_instance_id="$1"
ssh_user="$2"
ssh_port="$3"
ssh_public_key_path="$4"
ssh_public_key="$(cat "${ssh_public_key_path}")"
ssh_public_key_timeout=60
@Yapcheekian
Yapcheekian / note.md
Last active June 14, 2021 07:39
Binary search 模版

找一個準確值

循環條件: l <= r

縮減搜索空間: l = mid + 1, r = mid - 1

找一個模糊值(比4大的最小數)

循環條件: l < r

縮減搜索空間: l = mid, r = mid - 1 或者 l = mid + 1, r = mid

@Yapcheekian
Yapcheekian / random.c
Created May 30, 2021 00:00
Random number generator in c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, const char * argv[]) {
srandom(getpid());
for (int i = 0; i < 16; i++) {
long int r = random();
printf("%ld\n", r);