Skip to content

Instantly share code, notes, and snippets.

@jizhilong
jizhilong / kill_child_processes.py
Created September 24, 2013 16:37
how to kill a process's child processes in python
#!/usr/bin/env python
import multiprocessing
import time
import subprocess, os, signal, sys
def test(s):
while True:
print s
time.sleep(1.5)
@jizhilong
jizhilong / tree.cpp
Last active December 24, 2015 04:38
the 3 ways of iterating a binary tree.
/*
* =====================================================================================
*
* Filename: tree.cpp
*
* Description: some operations with binary tree
*
* Version: 1.0
* Created: 09/29/2013 01:16:19 AM
* Revision: none
@jizhilong
jizhilong / sorts.cpp
Last active December 24, 2015 06:49
basic sorting algorithms implemented in C.
/*
* =====================================================================================
*
* Filename: sorts.c
*
* Description: basic sorting algorithms
*
* Version: 1.0
* Created: 09/23/2013 03:58:30 PM
* Revision: none
@jizhilong
jizhilong / heap.h
Created October 1, 2013 06:54
a generic heap implemented in c++ template.
#include <vector>
#include <algorithm>
using std::vector;
using std::swap;
template <typename T>
class heap
{
public:
@jizhilong
jizhilong / rbtree.cpp
Created October 4, 2013 02:01
a implementation of red-black tree in cpp
/*
* =====================================================================================
*
* Filename: rbtree.cpp
*
* Description: red-black tree in cpp
*
* Version: 1.0
* Created: 10/03/2013 11:38:50 PM
* Revision: none
@jizhilong
jizhilong / kmp.cpp
Created October 4, 2013 10:36
Knuth-Morris-Pratt Algorithm
/*
* =====================================================================================
*
* Filename: kmp.cpp
*
* Description: Knuth-Morris-Pratt Algorithm
*
* Version: 1.0
* Created: 10/04/2013 06:15:30 PM
* Revision: none
@jizhilong
jizhilong / reverse_words
Created October 27, 2013 12:56
my solution to the classic interview question: "reverse the words in a string , and keep the characters' order within a word unchanged."
/*
* =====================================================================================
*
* Filename: reverse_words.cpp
*
* Description: a program to reverse the words in a sentence.
*
* Version: 1.0
* Created: 10/27/2013 08:21:49 PM
* Revision: none
import os
import glob
import shutil
def rotate_files(filename, limit):
need_rotate = os.path.exists(filename)
if not need_rotate:
return
files = glob.glob('%s.*' % filename)
files.sort(key=lambda f: int(f.rsplit('.', 1)[1]))
@jizhilong
jizhilong / gen_git_crypt_key.py
Created May 11, 2017 06:45
a python script for generating git crypt key file from password.
#!/usr/bin/env python
import os
import struct
import hashlib
import hmac
import sys
import getpass
HMAC_KEY_FOR_AES = '\xa7\x8fd\xaa\xa9\x9cwWnjf\xf6bN\xb0\xb7<a\xdb\xd8\xbf\xc7\x99\xaf\xc1)\x96\xf8\xe4i`\xc3l\x94l7h'
@jizhilong
jizhilong / ewma.py
Created September 20, 2019 04:04
cli tool for counting occurence rate of lines with certain keyword with ewma algorithm.
#!/usr/bin/env python
'''
count occurence rate of lines with certain keyword with ewma algorithm.
'''
import math
import time
import sys