Skip to content

Instantly share code, notes, and snippets.

View zzh8829's full-sized avatar
😚
hi

Zihao Zhang zzh8829

😚
hi
View GitHub Profile
@zzh8829
zzh8829 / bebo_log.json
Created December 11, 2018 02:33
Bebo lnav
{
"bebo_log": {
"title": "Bebo Log",
"regex": {
"basic": {
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{6}\\+00:00) (?<hostname>[a-z0-9\\-\\.]+) (?<procname>.+): (?<level>debug|info|warning|error|DEBUG|INFO|WARNING|ERROR) \\[(?<source_file>.+?)\\] (?<body>.*)$"
}
},
"level": {
"debug": "debug|DEBUG",
@zzh8829
zzh8829 / nginx-ingress.yaml
Created March 20, 2017 03:46
kubernetes nginx ingress
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: default-http-backend
labels:
k8s-app: default-http-backend
namespace: kube-system
spec:
replicas: 1
template:
@zzh8829
zzh8829 / kuboo.sh
Last active March 9, 2019 14:29
Mini Kubernete cluster setup with kubeadm on any ubuntu machine
###
# master setup on fresh ubuntu machine
###
sudo su
# real memory is too expensive
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
@zzh8829
zzh8829 / 0001-Lower-Limits.patch
Created March 15, 2017 23:16
kubeadm lower resource limit
From 62b5e2f5fcf407783245ce7f03dc33f70d0f3200 Mon Sep 17 00:00:00 2001
From: Zihao Zhang <zzh8829@gmail.com>
Date: Wed, 15 Mar 2017 15:26:30 -0700
Subject: [PATCH] Lower Limits
---
cmd/kubeadm/app/master/manifests.go | 2 +-
cmd/kubeadm/app/phases/addons/manifests.go | 6 ++----
2 files changed, 3 insertions(+), 5 deletions(-)
@zzh8829
zzh8829 / ztop.sh
Created February 8, 2017 23:25
List cpu usage grouped by user
own=$(id -nu)
tmp=$(mktemp)
#for user in $(getent passwd | awk -F ":" '{print $1}' | sort -u)
for user in $(who | awk '{print $1}' | sort -u)
do
# print other user's CPU usage in parallel but skip own one because
# spawning many processes will increase our CPU usage significantly
if [ "$user" = "$own" ]; then continue; fi
(top -b -n 1 -u "$user" | awk -v user="$user" 'NR>7 { sum += $9; } END { print user, sum; }') >> $tmp &
done
@zzh8829
zzh8829 / Poker.py
Last active August 28, 2016 23:41
Poker profit prediction
import numpy as np
import matplotlib.pyplot as plt
import csv
import re
def graph_profit(profit):
x = np.arange(len(profit))
y = np.cumsum(profit)
p1 = np.poly1d(np.polyfit(x, y, 3))
p2 = np.poly1d(np.polyfit(x, y, 4))
@zzh8829
zzh8829 / keybase.md
Created August 6, 2016 04:10
keybase.md

Keybase proof

I hereby claim:

  • I am zzh8829 on github.
  • I am zihao (https://keybase.io/zihao) on keybase.
  • I have a public key whose fingerprint is A5D4 F88A 78A0 074E 855C 58E7 12B0 1A6A AC10 DF01

To claim this, I am signing this object:

@zzh8829
zzh8829 / earthporn.py
Created June 29, 2014 01:57
Reddit EarthPorn automatic downloader
import feedparser
import re
from bs4 import BeautifulSoup
import pprint
import os
import urllib.request
import imghdr
import sys
from time import localtime, strftime
from PIL import Image
@zzh8829
zzh8829 / Delegate.hpp
Created January 18, 2014 02:47
C++ Lightning Fast Function Wrapper
template<typename T>
class Delegate{};
template<typename Return, typename ... Args>
class Delegate<Return(Args ...)>
{
private:
class AnyClass;
using AnyMemberFunc = Return(AnyClass::*)(Args...);
using AnyStaticFunc = Return(*)(Args...);
@zzh8829
zzh8829 / MinecraftLogin.java
Created August 30, 2013 16:56
[1.6] Connect to legit Minecraft server with forge/mcp Minecraft inside eclipse
package net.minecraft.client;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;