Skip to content

Instantly share code, notes, and snippets.

View myfavouritekk's full-sized avatar

Kai KANG myfavouritekk

View GitHub Profile
@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.
%
@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 / 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 / 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 / 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 / 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 / batchCombine.m
Last active February 21, 2017 00:31
Matlab: Process multiple files and combine the results into a cell array.
function [combination] = batchCombine(funhandle, indir, varargin)
%BATCHCOMBINE Process multiple files and combine the results into a cell array
% BATCHCOMBINE(FUNC, INDIR) processes every file or directory in
% INDIR using processing funtion FUNC.
%
% FUNC is a function handle that takes source filename as input variables.
% For example, if FUNC = @foo, then BATCHCOMBINE calls foo(infile) to
% every infile in INDIR.
%
% BATCHCOMBINE(..., 'para1', value1, 'para2', value2, ...) takes extra
@myfavouritekk
myfavouritekk / tarzip.sh
Last active August 29, 2015 14:04
Linux/Unix: Compress and copy
# Use tar to direct output to standard output "-" and use gzip to compress
tar -cf - <source_file> | gzip -1 > <destination_file>
# Same effect, be sure to put <destination_file> directly behind -f option
tar -czf <destination_file> <source_file>
# Untar
tar -xzf <tar_file>
@myfavouritekk
myfavouritekk / change_bash.md
Created August 4, 2014 06:35
Change Bash version on OS X

Change Bash version on OS X

  • Installation

sudo port install bash

  • Add it to your shells: add installed bash to /etc/shells

sudo vim /etc/shells

@myfavouritekk
myfavouritekk / sd.sh
Created August 22, 2014 13:00
OS X: Change directory in Terminal, Sync folder in Finder window.
# change directory and sync Finder window
sd () {
# change terminal directory
cd "$@" || return
# sync Finder window or open new one if not exists
osascript -e "tell application \"Finder\"
if front Finder window exists then
set target of front Finder window to (""\"$PWD\""" as POSIX file)
else
open (""\"$PWD\""" as POSIX file)