Skip to content

Instantly share code, notes, and snippets.

View knight42's full-sized avatar
❤️
Loving @FogDong

Zack Zeng knight42

❤️
Loving @FogDong
View GitHub Profile
// ==UserScript==
// @name Open in godoc
// @namespace https://github.com/knight42
// @version 0.1
// @description Open godoc from GitHub
// @author knight42
// @include https://github.com/*/*
// @exclude https://github.com/*/*/blob/*
// @exclude https://github.com/settings/*
// @exclude https://github.com/orgs/*
@knight42
knight42 / clean-k8s-yaml.py
Last active October 10, 2018 09:11
remove unused fields in yaml of k8s object
#!/usr/bin/env python -O
# -*- coding: utf-8 -*-
import yaml
import sys
def delete_key(d, *keys):
for key in keys:
if d.get(key) is not None:
@knight42
knight42 / aws_ip_ranges.py
Created August 30, 2018 10:29
get aws ip ranges in cn-north-1 region
#!/usr/bin/env python -O
# -*- coding: utf-8 -*-
#from __future__ import print_function, unicode_literals, with_statement, division, absolute_import
# import os
# import random
# import requests
import sys
import requests
@knight42
knight42 / main.go
Created August 13, 2018 17:59 — forked from walm/main.go
Simple Golang DNS Server
package main
import (
"fmt"
"log"
"strconv"
"github.com/miekg/dns"
)
@knight42
knight42 / mozlz4a.py
Created January 26, 2018 09:41 — forked from Tblue/mozlz4a.py
MozLz4a compression/decompression utility
#!/usr/bin/env python
#
# Decompressor/compressor for files in Mozilla's "mozLz4" format. Firefox uses this file format to
# compress e. g. bookmark backups (*.jsonlz4).
#
# This file format is in fact just plain LZ4 data with a custom header (magic number [8 bytes] and
# uncompressed file size [4 bytes, little endian]).
#
# This Python 3 script requires the LZ4 bindings for Python, see: https://pypi.python.org/pypi/lz4
#
#!/bin/bash
SWAGGER_DOCS_PORT=${SWAGGER_DOCS_PORT:-8080}
d=$(mktemp -d)
cd $d || exit 1
wget -q https://raw.githubusercontent.com/moby/moby/master/api/swagger.yaml
docker run --rm -tid -v "$PWD/swagger.yaml":/usr/share/nginx/html/swagger.yaml \
-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
-p $SWAGGER_DOCS_PORT:80 \
bfirsh/redoc:1.6.2
@knight42
knight42 / git-clone-single-branch.sh
Created December 19, 2017 11:23
Git clone a single branch
# Excerpt from https://stackoverflow.com/a/14930421/4725840
git clone -b mybranch --single-branch git://sub.domain.com/repo.git
@knight42
knight42 / beautiful_idiomatic_python.md
Created June 7, 2017 08:55 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@knight42
knight42 / xls2csv.py
Created March 23, 2017 09:36
Convert xls to csv
#!/usr/bin/python -O
# -*- coding: utf-8 -*-
########################
# Require python-xlrd
########################
from __future__ import print_function, unicode_literals, with_statement, division
import xlrd
import csv
from os import sys