Skip to content

Instantly share code, notes, and snippets.

@walsvid
walsvid / pip_upgrade_all.py
Created November 3, 2016 13:05
pip upgrade all packages.
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
@walsvid
walsvid / timer.py
Last active November 22, 2016 06:40
Simple Timer context manager. It will take care of starting the timer when your code block begins execution and stopping the timer when your code block ends.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from time import clock
class Timer(object):
def __init__(self, verbose=False):
self.verbose = verbose
def __enter__(self):
@walsvid
walsvid / chinese.cpp
Created November 22, 2016 06:38
Read file which has Chinese characters.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
wifstream in;
string filename;
@walsvid
walsvid / Markov.py
Created January 2, 2017 13:02
马尔科夫链生成乱数假文
import random
class Markov(object):
def __init__(self, open_file):
self.cache = {}
self.open_file = open_file
self.words = self.file_to_words()
self.word_size = len(self.words)
self.database()
@walsvid
walsvid / color_printf_c.c
Created January 2, 2017 13:04
printf 颜色控制
#include <stdio.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
@walsvid
walsvid / lazyJsonParse.py
Created January 2, 2017 13:09
copy from stackoverflow, lazy json parse.
def lazyJsonParse(j):
j = re.sub(r"{\s*'?(\w)", r'{"\1', j)
j = re.sub(r",\s*'?(\w)", r',"\1', j)
j = re.sub(r"(\w)'?\s*:", r'\1":', j)
j = re.sub(r":\s*'(\w+)'\s*([,}])", r':"\1"\2', j)
return json.loads(j)
@walsvid
walsvid / huffman.cpp
Created January 2, 2017 13:12
哈夫曼树
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
class Huffman
{
public:
int deep; //深度
@walsvid
walsvid / ReservoirSampling.py
Created January 2, 2017 14:52
蓄水池抽样
#!/usr/bin/python
import sys
import random
if len(sys.argv) == 3:
input = open(sys.argv[2],'r')
elif len(sys.argv) == 2:
input = sys.stdin;
else:
sys.exit("Usage: python samplen.py <lines> <?file>")
@walsvid
walsvid / ffmpeg.md
Created January 7, 2017 13:14 — forked from v5tech/ffmpeg.md
ffmpeg视频合并、格式转换、截图

使用ffmpeg合并MP4文件

ffmpeg -i "Apache Sqoop Tutorial Part 1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i "Apache Sqoop Tutorial Part 2.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "Apache Sqoop Tutorial Part 3.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate3.ts
ffmpeg -i "Apache Sqoop Tutorial Part 4.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate4.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts|intermediate3.ts|intermediate4.ts" -c copy -bsf:a aac_adtstoasc "Apache Sqoop Tutorial.mp4"
@walsvid
walsvid / subsets.py
Created February 4, 2017 12:12 — forked from makto/subsets.py
求某个集合的所有子集
#-*- coding: utf-8 -*-
"""
给定集合 test_case
输出其所有子集
"""
def getsubs(father, size):
"""获取集合 father 的
指定长度 size 的所有子集合"""