Skip to content

Instantly share code, notes, and snippets.

View chenk008's full-sized avatar

chenk008

  • Alibaba Cloud
  • Hangzhou
  • 08:46 (UTC -12:00)
View GitHub Profile
@chenk008
chenk008 / etcd-list-keys.md
Created June 15, 2023 03:22 — forked from lalyos/etcd-list-keys.md
k8s etcd list keys

You can demostrate how kubernetes stores everything in etcd (v3):

One-liner

You can exec etcdctl rigth in the etc pod:

kubectl exec -it \
  -n kube-system etcd-minikube \
  -- sh -c 'ETCDCTL_CACERT=/var/lib/localkube/certs/etcd/ca.crt \
 ETCDCTL_CERT=/var/lib/localkube/certs/etcd/peer.crt \
@chenk008
chenk008 / Makefile
Created May 25, 2023 06:08 — forked from cjbarker/Makefile
Makefile for cross-compiling Golang. Just update BINARY var in Makefile and create empty vars in main.go for Version and Build
# ########################################################## #
# Makefile for Golang Project
# Includes cross-compiling, installation, cleanup
# ########################################################## #
# Check for required command tools to build or stop immediately
EXECUTABLES = git go find pwd
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH)))
@chenk008
chenk008 / tcp_monitor.c
Created May 29, 2022 14:20 — forked from sunhay/tcp_monitor.c
eBPF socket filter based tcptop
#include <uapi/linux/ptrace.h>
#include <uapi/linux/if_packet.h>
#include <net/sock.h>
#include <bcc/proto.h>
#define IP_TCP 6
#define ETH_HLEN 14
struct Key {
u32 src_ip; // source ip
@chenk008
chenk008 / get_inode.c
Created December 10, 2021 02:39 — forked from larytet/get_inode.c
Get inode and file given FD in the Linux kernel
static void get_inode(u64 fd, struct file **p_file, struct inode **p_inode)
{
struct file *file = NULL;
struct inode *f_inode = NULL;
#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,7,0))
file = fget_raw(fd); // do not forget to fput(file)
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,255))
{
struct files_struct *files = current->files;
if (files) // This is always the case, but I am not taking chances
@chenk008
chenk008 / mtest.c
Created October 27, 2020 06:55 — forked from BrotherJing/mtest.c
a kernel module for process memory management
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/string.h>
#include<linux/vmalloc.h>
#include<linux/mm.h>
#include<linux/init.h>
#include<linux/proc_fs.h>
#include<linux/sched.h>
#include<linux/uaccess.h>
#include<linux/fs.h>
@chenk008
chenk008 / xstat
Created April 17, 2020 07:38 — forked from moiseevigor/xstat
xstat bash function to get file creation time on Linux with EXT4
xstat() {
for target in "${@}"; do
inode=$(ls -di "${target}" | cut -d ' ' -f 1)
fs=$(df "${target}" | tail -1 | awk '{print $1}')
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null |
grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${crtime}" "${target}"
done
}
@chenk008
chenk008 / get_ip_v1.c
Created March 27, 2020 13:34 — forked from listnukira/get_ip_v1.c
use getsockname to get ip and port
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SERVER_ADDR "173.194.72.94"
#define SERVER_PORT 80
int main()
@chenk008
chenk008 / README.md
Created February 8, 2020 03:58 — forked from bobrik/README.md
CFS hiccups
@chenk008
chenk008 / curl.md
Created March 23, 2018 15:02 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.