Skip to content

Instantly share code, notes, and snippets.

Avatar

Yap Yapcheekian

  • Taiwan
View GitHub Profile
@Yapcheekian
Yapcheekian / concurrent.txt
Last active Dec 31, 2021
Process vs coroutines vs thread
View concurrent.txt
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 / gem.md
Created Aug 31, 2021
Fix when gem install mysql2 in rails failed
View gem.md
gem install mysql2 -v 0.5.3 -- \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.26/bin/mysql_config \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include \
--platform=ruby
@Yapcheekian
Yapcheekian / slices.go
Created Aug 9, 2021
Notes on go slices
View slices.go
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 Aug 5, 2021
capture pod packet
View e_net.sh
#!/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 Jul 28, 2021
Docker security hardening
View notes.md
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 Jul 28, 2021
selection sort, bubble sort, insertion sort, merge sort, quick sort
View sorting_algorithm.go
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 / notes.md
Last active Jul 24, 2021
Notes on linux, container and kubernetes networking commands and concepts
View notes.md

Scenario 1: only 2 container (red and blue) created

ip link add veth-red type veth peer name veth-blue

ip link set veth-red netns red

ip link set veth-blue netns blue

ip -n red addr add 192.168.15.1 dev veth-red

@Yapcheekian
Yapcheekian / guide.md
Created Jul 22, 2021
Integrate elastic cloud with okta
View guide.md

Okta

  1. Create an application in okta
  2. Choose SAML2.0
  3. Give a random app name
  4. Single sign on URL: KIBANA_ENDPOINT_URL/api/security/saml/callback
  5. Audience URI (SP Entity ID): KIBANA_ENDPOINT_URL/

elasticsearch.yml

xpack:
@Yapcheekian
Yapcheekian / template.json
Created Jul 16, 2021
Create elasticsearch index template
View template.json
PUT /_template/fluentbit
{
"fluenbit" : {
"order" : 0,
"index_patterns" : [
"fluentbit-*"
],
"settings" : {
"index" : {
"number_of_shards" : "10"