Skip to content

Instantly share code, notes, and snippets.

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

Jian Zeng knight42

❤️
Loving @FogDong
View GitHub Profile
@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
@knight42
knight42 / git-change-author-info.sh
Last active May 31, 2017 14:10
git-change-author-info.sh
#!/bin/sh
# git clone --bare https://github.com/user/repo.git
# cd repo.git
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
@knight42
knight42 / choose.rs
Last active August 23, 2016 07:05
doesn't work :/
use syntax::ast;
use syntax::ptr::P;
use syntax::codemap;
use syntax::parse::token;
use syntax::tokenstream::TokenTree;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder;
use syntax_pos::Span;
use rustc_plugin::Registry;
use syntax::util::small_vector::SmallVector;