Skip to content

Instantly share code, notes, and snippets.

@qiuwch
qiuwch / iminfo.sh
Last active March 31, 2017 02:46
Batch resize images #tags: tips
identify *.png
@qiuwch
qiuwch / GoProRename.py
Created May 12, 2015 03:05
Batch rename and convert time lapse of GoPro.
import glob
# Update this script to make it clear enough to merge two folders
# This is done manually right now
pattern = '108GOPRO/G012*.JPG'
srcdir = pattern.split('/')[0]
prefix = pattern.split('/')[1].split('*')[0]
tgtdir = srcdir + '/' + prefix
frames = glob.glob(pattern)
print 'Srcdir:', ddir, 'Prefix:', prefix, 'Tgtdir:', tgtdir
@qiuwch
qiuwch / todo.py
Created May 12, 2015 02:34
Utility python script.
#!/usr/bin/env python
import argcomplete, argparse, requests, pprint
import types
import os, sys, pprint
# http://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory
cwd = os.getcwd()
print cwd
sys.path.append(cwd)
import todo
@qiuwch
qiuwch / figureTips.m
Last active August 29, 2015 14:20
Set the figure size of MATLAB
set(gcf, 'PaperPosition', [0 0 20 10]);
% PaperPosition is used for exporting figure
% PaperUnits: default inches for U.S., cm for Asia and Euro. normalized is the best choice
set(gcf, 'Position', [0 0 20 10]);
% Position is used for GUI position
% Default unit is pixels
% Units: Default pixel
xTickLabel = arrayfun(@(x) num2str(x), betas, 'UniformOutput', false);
@qiuwch
qiuwch / simpleMatrix.h
Created May 10, 2015 03:40
A simple matrix implementation, useful for course project
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <complex> // std::complex, std::abs
#define CHECK_ACC
#define EPS 10e-3 // a very small value
// Float matrix
template<typename T>
@qiuwch
qiuwch / randperm.c
Last active March 31, 2017 02:46
Sample a value from a distribution #tags: algorithm
double random_num = (double)rand() / RAND_MAX;
for (k = 0; k <= MAX_INTENSITY; k++)
{
if (random_num < probs[k])
{
synthesized[i*im_width+j] = k; // update synthesized image
break;
}
else
random_num = random_num - probs[k];
@qiuwch
qiuwch / randPerm.c
Last active November 28, 2023 12:21
Random permutation in C, equivalent to randperm in MATLAB, #tags: algorithm
int perm[SZ];
for (int i = 0; i < SZ; i++) perm[i] = i;
// Random permutation the order
for (int i = 0; i < SZ; i++) {
int j, t;
j = rand() % (SZ-i) + i;
t = perm[j]; perm[j] = perm[i]; perm[i] = t; // Swap i and j
}