Skip to content

Instantly share code, notes, and snippets.

View myfavouritekk's full-sized avatar

Kai KANG myfavouritekk

View GitHub Profile
@myfavouritekk
myfavouritekk / dropbox_git.sh
Last active August 29, 2015 13:57
Shell: Using Dropbox folder as git remote repository.
# Initalize git repository
git init
git add .
git commit -m "first commit"
# Initialize git repository on Dropbox folder as remote branch
cd ~/Dropbox/git
git init --bare project.git
# Add remote to local git repository
@myfavouritekk
myfavouritekk / vararginChecking.m
Created February 25, 2014 13:39
Matlab: Variable-length input argument (varargin) list checking.
%% checking minimum arguments requried
minargs = 3;
maxargs = inf;
n_exargs = length(varargin);
try
narginchk(minargs, maxargs);
catch err
if strcmp(err.identifier,'MATLAB:narginchk:notEnoughInputs')
error('batchconvert:notEnoughInputs',...
@myfavouritekk
myfavouritekk / batchProcess.m
Last active February 18, 2017 19:23
Matlab: Process multiple files with given processing function
function [] = batchProcess(funhandle, indir, varargin)
%BATCHPROCESS Process multiple files with given processing function
% BATCHPROCESS(FUNC, INDIR) processes every file or directory in
% INDIR using processing funtion FUNC.
%
% FUNC is a function handle that takes source filename and target
% directory as input variables. For example, if FUNC = @foo, then
% BATCHPROCESS calls foo(infile) to every infile in INDIR.
%
% BATCHPROCESS(..., 'para1', value1, 'para2', value2, ...) takes extra
@myfavouritekk
myfavouritekk / ssh_copy.sh
Last active August 29, 2015 13:56
Copy public-key to remote-machine for public-key authentication.
# Copy public-key to remote-machine for public-key authentication
ssh-copy-id someuser@remote-machine
# To specify port number
ssh-copy-id "someuser@remote-machine -p port_number"
@myfavouritekk
myfavouritekk / gist:8878496
Created February 8, 2014 08:23
Unix/Linux: Display Username and UID
cut -d ':' -f 1,3 /etc/passwd | sort -t ':' -k2n - | tr ':' '\t'
@myfavouritekk
myfavouritekk / batchConvert.m
Last active February 21, 2017 00:31
Matlab: Function for converting multiple files with given conversion function
function [] = batchConvert(funhandle, indir, outdir, varargin)
%BATCHCONVERT Convert multiple files with given conversion function
% BATCHCONVERT(FUNC, INDIR, OUTDIR) converts every file or directory in
% INDIR using conversion funtion FUNC and save the converted files to
% OUTDIR with the same names as in INDIR.
%
% FUNC is a function handle that takes source filename and target
% directory as input variables. For example, if FUNC = @foo, then
% BATCHCONVERT calls foo(infile, outfile) to every infile in INDIR.
%