Skip to content

Instantly share code, notes, and snippets.

View charlee's full-sized avatar

Charlee Li charlee

View GitHub Profile
@charlee
charlee / timethis.py
Created January 8, 2013 21:40
generic decorator with functools.wraps
import functools
def timethis(func):
"""A profiling function used to record the time consumed on a function call."""
@functools.wraps(func)
def _(self, *a, **kw):
start = time()
ret = func(self, *a, **kw)
@charlee
charlee / ffmpeg.sh
Last active January 19, 2022 15:05
ffmpeg tips
# losslessly concat mp4 files
ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
# concat files with the same format
# 1. create a file list
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
@charlee
charlee / js-cheatsheets.js
Last active December 12, 2015 04:08
Programming Cheatsheets
// element dimension
var w = $(this).width();
var h = $(this).height();
// current window(viewport) dimension
var w = $(window).width();
var h = $(window).height();
// document dimension
var w = $(document).width();
@charlee
charlee / email-validator.js
Created March 9, 2013 06:27
E-mail address validator
var emailValidator = function(s) {
s = $.trim(s);
var name, addr, p = s.indexOf('<');
if (p >= 0 && s.charAt(s.length - 1) == '>') {
name = $.trim(s.substring(0, p));
addr = s.substring(p+1, s.length - 1);
} else {
addr = s;
@charlee
charlee / default.custom.yaml
Last active January 19, 2021 00:51
鼠须管颜文字配置文件
patch:
schema_list:
- schema: luna_pinyin_simp
- schema: emoji
@charlee
charlee / pre-push
Created February 5, 2015 15:28
auto submit to multiple remote
#!/usr/bin/env python
import sys
from subprocess import call
remote = sys.argv[1]
if remote == 'origin':
for line in sys.stdin.readlines():
local_ref, local_sha, remote_ref, remote_sha = line.split(' ')
branch = remote_ref.split('/', 2)[2]
@charlee
charlee / mobile-icon-cutter.py
Created April 10, 2016 16:45
Mobile Icon Cutter
#!/usr/bin/env python
import os
import sys
import errno
from PIL import Image
try:
filename = sys.argv[1]
im = Image.open(filename)
#deprecated
def grep_php_const(lines, name):
regexp = "^define\(\s*'%s',\s*'(.*)'\s*\);\s*$" % name
for line in lines:
m = re.match(regexp, line)
if m:
return m.group(1)
@charlee
charlee / fping
Created July 19, 2017 00:56
scan tools
# scan a network
fping -a -r 0 -g 192.168.1.0/24
@charlee
charlee / read_from_tfrecords.py
Created October 24, 2017 05:16
Read example from TFRecord
def read_and_decode(filename_queue):
"""Read from tfrecords file and decode and normalize the image data."""
reader = tf.TFRecordReader()
_, serialized_exmaple = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_exmaple,
features={
'image': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64),