A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.
python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
| # Copyright 2018 Simon Davy | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| # copies of the Software, and to permit persons to whom the Software is | |
| # furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in |
| from ctypes import CDLL, c_void_p, byref | |
| from ctypes.util import find_library | |
| # The following code fails on ubuntu 18.04, but succeeds on 14.04 | |
| lib = CDLL(find_library('guestlib')) | |
| handle = c_void_p() | |
| ret = lib.VMGuestLib_OpenHandle(byref(handle)) | |
| if ret != 0: | |
| raise RuntimeError("failed to get handle") |
A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.
python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
| # aproducer.py | |
| # | |
| # Async Producer-consumer problem. | |
| # Challenge: How to implement the same functionality, but no threads. | |
| import time | |
| from collections import deque | |
| import heapq | |
| class Scheduler: |
| openssl genpkey -out chandan.key -algorithm Ed25519 | |
| cat chandan.key | |
| openssl req -new -key chandan.key -out chandan.csr -subj "/CN=chandan/O=edit" | |
| creq=$(cat chandan.csr | base64 | tr -d "\n") | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: certificates.k8s.io/v1 | |
| kind: CertificateSigningRequest | |
| metadata: | |
| name: chandan |
| #!/usr/bin/python3 | |
| #https://github.com/Jin-Yang/examples/blob/master/linux/memory/pagemap/pagemap.py | |
| import sys | |
| import os | |
| import binascii | |
| import struct | |
| def read_entry(path, offset, size=8): |
| ps -eo pss|awk '{sum+=$1}END{print sum/1024**1}' &&\ | |
| ps -eo pid,rss|awk '!/PID/{if($2!=0){print $1}}'|xargs -I{} bash -c "pmap -X -p {}|awk 'END{print \$3}'"|awk '{sum+=$1}END{print sum/1024**1}' &&\ | |
| free -m | |
| #20480K kernel code, 4270K rwdata, 13536K rodata, 4816K init, 17368K bss, 550384K reserved, 0K cma-reserved | |
| #cat /var/log/dmesg|grep "Memory:"|sed 's/.*kernel: Memory:.*(\(.*\))$/\1/' |tr ',' '\n'|sed 's/K .*$//g'|awk '{sum+=$0}END{print sum/1024}' | |
| #slabtop -o|awk '/Total Size/{print $(NF-1)}' |
| cat /dev/kmsg |awk '/invoked oom-killer/, /oom-kill:constraint/ {print}' | |
| cat /proc/meminfo | |
| cat /proc/stat | |
| cat /proc/*/stat | |
| cat /proc/vmstat | |
| cat /proc/loadavg | |
| cat /proc/net/netstat | |
| cat /proc/mounts | |
| cat /proc/diskstats | |
| cat /proc/vmallocinfo |
Currently in no particular order. Most of these are kind of ancient.
Where's all the modern documentation? So much of what I've turned up searching is other folks complaining about having few options beyond reading source code.
The OREILLY books, while dated, seem to be some of the best available. Note that these can be read with a 7-day trial. Do this! At least get through the introduction section and first chapter of each to see if it's what you're after.