Skip to content

Instantly share code, notes, and snippets.

View Yapcheekian's full-sized avatar

Yap Yapcheekian

View GitHub Profile
@Yapcheekian
Yapcheekian / nginx.conf
Created May 27, 2021 08:46
Add resolver in nginx to resolve DNS dynamically
server {
listen 80;
server_name test.com;
location / {
# docker 內的 resolv.conf 指到 127.0.0.11
resolver 127.0.0.11;
# 只加 resolver directive 不夠,還得用上 set
set $url http://example.com;
proxy_pass url;
@Yapcheekian
Yapcheekian / lua.yaml
Created May 28, 2021 11:37
custom lua plugin example to print req header for ingress-nginx
apiVersion: v1
kind: ConfigMap
metadata:
name: lua-plugins
namespace: ingress-nginx
data:
main.lua: |
local ngx = ngx
local _M = {}
@Yapcheekian
Yapcheekian / factor.c
Created May 29, 2021 23:59
Process control in c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const int children = 4;
void factor(int n) {
for (int i = 2; i <= n/2; i++) {
if (n % i == 0) printf("%d", i);
}
@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);
@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 / 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 / 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 / guide.md
Created July 22, 2021 12:29
Integrate elastic cloud with okta

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: