Skip to content

Instantly share code, notes, and snippets.

View clarkli86's full-sized avatar

Clark Li clarkli86

  • Adelaide, Australia
View GitHub Profile
@clarkli86
clarkli86 / prefix_hex_string.py
Created May 3, 2016 03:06
One liner to add 0x to hex string
# Convert abcd into 0xab, 0xcd
reduce(lambda x, y : x + y, map(lambda x : '0x' + x + ', ', map(''.join, zip(*[iter(str)] * 2))))
@clarkli86
clarkli86 / starter_video.cpp
Created April 28, 2016 14:35
De-fisheye in OpenCV starter video example
/*
* starter_video.cpp
*
* Created on: Nov 23, 2010
* Author: Ethan Rublee
*
* Modified on: April 17, 2013
* Author: Kevin Hughes
*
* A starter sample for using OpenCV VideoCapture with capture devices, video files or image sequences
@clarkli86
clarkli86 / ldd_awk.sh
Created March 16, 2016 02:10
Copy all shared libraries for a binary to directory
ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
@clarkli86
clarkli86 / rename.sh
Created March 5, 2016 04:37
Regular expression on file names
rename 's/(.*\.wav)2016.*/$1/g' *.wav
@clarkli86
clarkli86 / resample_wav.sh
Created March 3, 2016 12:49
Resample wav file
track2track --sample-rate 16000 --channels 1 --bits-per-sample 16 down_0.aac
@clarkli86
clarkli86 / itertools
Created February 23, 2016 12:54
Merge np.ndarray with the same number of rows
a = np.ndarray((4, 1))
b = np.ndarray((4, 2))
c = [np.array(list(itertools.chain.from_iterable(it))) for it in zip(a, b)]
@clarkli86
clarkli86 / configure_googletest
Created January 28, 2016 14:23
Configure googletest for baremetal (No OS) targets
autoreconf -fvi
./configure --disable-shared --without-pthreads --disable-libtool-lock --prefix=/home/clark/googletest --exec-prefix=/home/clark/googletest --host=arm-none-eabi LDFLAGS="-mcpu=cortex-m4 -mthumb -mfloat-abi=soft -mthumb-interwork --specs=nosys.specs " CFLAGS="-mcpu=cortex-m4 -mthumb -mfloat-abi=soft -mthumb-interwork -Iinc -DGTEST_HAS_POSIX_RE=0 -DGTEST_HAS_PTHREAD=0 -DGTEST_HAS_DEATH_TEST=0 -DGTEST_HAS_STREAM_REDIRECTION=0 -DGTEST_OS_NONE -std=c99 -Os" CXXFLAGS="-mcpu=cortex-m4 -mthumb -mfloat-abi=soft -mthumb-interwork -Iinc -DGTEST_HAS_POSIX_RE=0 -DGTEST_HAS_PTHREAD=0 -DGTEST_HAS_DEATH_TEST=0 -DGTEST_HAS_STREAM_REDIRECTION=0 -DGTEST_OS_NONE -std=gnu++11 -Os -D_POSIX_PATH_MAX=255"
make & make install-libLTLIBRARIES
@clarkli86
clarkli86 / typelist
Last active October 13, 2015 11:35
A sample typelist implementation
template<typename... Args>
struct TypeList;
/// partial specialisation
template<typename FirstType, typename... Args>
struct TypeList<FirstType, Args...> : private TypeList<Args...> {
using type = FirstType;
template<typename ClientType>
struct InList {
@clarkli86
clarkli86 / vim_advanced_commands
Last active November 27, 2017 14:15
Advanced VIM commands
. to repeat last command
gv to reselect the visual area
>> to indent current line
> to indent selected text
>% to indent the block
>} to indent from the cursor to the next blank line
<aB to un-indent the current C-like {...} "block" structure
>i{ increase indent for inner block
>a{ increase the whole block
@clarkli86
clarkli86 / change_git_author_email_in_previous_commits
Created August 26, 2015 14:49
One liner to change email in git commits
git filter-branch -f --env-filter "
GIT_AUTHOR_EMAIL='clark.li86@gmail.com'
" HEAD