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
#!/usr/bin/python3 -O
# -*- coding: utf-8 -*-
import hashlib
import binascii
from passlib.utils import des
def GenerateNTResponse(AuthChal, PeerChal, UserName, Password):
'''
IN 16-octet AuthenticatorChallenge,
@knight42
knight42 / npm_registry.conf
Created March 5, 2016 01:26
npm registry caching proxy using nginx
proxy_cache_path /mnt/array1/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
proxy_temp_path /mnt/array1/nginx/temp;
keepalive_timeout 2;
tcp_nodelay on;
sendfile on;
limit_conn_zone $binary_remote_addr zone=addr:20m;
limit_req_zone $binary_remote_addr zone=req_per_ip:20m rate=80r/s;
limit_req zone=req_per_ip burst=100;
@knight42
knight42 / naive-request.js
Last active December 8, 2016 08:37
naive promisified request
#!/usr/bin/node
"use strict";
const net = require('net');
const url = require('url');
const qs = require('querystring');
function request(opts) {
if(! /^https?:\/\//.test(opts.url)) opts.url = `http://${opts.url}`;

Keybase proof

I hereby claim:

  • I am knight42 on github.
  • I am knight42 (https://keybase.io/knight42) on keybase.
  • I have a public key ASBcXMtM1C4xjqaqqM-hbhT93xhcebCOv2i-FyjK51VDqAo

To claim this, I am signing this object:

@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;
@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 / 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 / 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 / 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