Skip to content

Instantly share code, notes, and snippets.

View vtta's full-sized avatar
🎯
Focusing

Junliang Hu vtta

🎯
Focusing
  • The Chinese University of Hong Kong
  • Hong Kong
  • 08:29 (UTC +08:00)
View GitHub Profile
@vtta
vtta / watermarker.sh
Last active March 24, 2019 05:22
A bash script to watermark all the photos in a folder. ImageMagick is required.
#!/bin/bash
SRC_DIR="${1}"
MARK="${2}"
if [[ "$#" -lt "2" ]] ; then
echo "A small script for adding watermark to images."
echo "Usage: $0 INPUT_IMAGE_FOLDER WATER_MARK_FILE"
exit 1
fi
@vtta
vtta / x265-encode.sh
Last active August 9, 2024 13:45
A script to encode video using ffmpeg and x265 encoder
#!/bin/bash
# need to install ffmpeg with x265 enabled, on macOS:
# sudo port install ffmpeg +nonfree
# or
# brew install ffmpeg --HEAD --with-fdk-aac --with-sdl2 --with-freetype \
# --with-libass --with-libbluray --with-libvorbis --with-libvpx \
# --with-opus --with-webp --with-x265
encode() {
ffmpeg -i "$1" \
@vtta
vtta / ovirt-centos7-template.sh
Last active April 7, 2019 07:52
A script to convert a CentOS Minimal to an oVirt template
#!/bin/bash
# A script to convert a CentOS Minimal to an oVirt template
yum install https://resources.ovirt.org/pub/yum-repo/ovirt-release43.rpm
yum install -y wget git vim ovirt-guest-agent-common cloud-init
yum clean all
systemctl enable ovirt-guest-agent
# systemctl enable cloud-init
echo > /etc/machine-id
rm -f /etc/ssh/ssh_host_*
rm -rf /root/.ssh/*
@vtta
vtta / kMeans.m
Created April 11, 2019 08:24
simple k-means algorithm implemented in GNU Octave
function y = kMeans(m, k, i)
% m: input matrix
% row: each column is a sample
% column: sample number
% k: k clusters
% y: vector consist of the cluster number of each sample
[sampleNum, featureNum] = size(m);
centers = m(1:k, :);
y = zeros(sampleNum,1);
@vtta
vtta / iris.m
Created April 11, 2019 08:26
GNU Octave script to test my k-means algorithm using the iris data set
% usage:
% octave-cli iris.m
fid = fopen('iris.data');
irisTextData = textscan(fid,'%f %f %f %f %s', 200, 'Delimiter',',');
fclose (fid);
irisMatrix = cell2mat(irisTextData(:,1:4));
k = 3;
clusterID = kMeans(irisMatrix, k);
@vtta
vtta / KLTransform.m
Last active May 1, 2019 18:18
simple K-L transform algorithm implemented in Octave
function Y=KLTransform(X, d)
[sampleNum, featureNum] = size(X);
m = mean(X);
for i = 1:sampleNum
X(i,:) = X(i,:) - m;
end
C = cov(X);
[V, D] = eig(C);
S = [diag(D), V];
@vtta
vtta / glcm.m
Created April 14, 2019 10:14
Gray Level Co-occurrence Matrix in Octave
function Y=glcm(X, dx, dy, grayScale)
% (dx, dy):
% ( 1, 0) 0°
% ( 0, 1) 45°
% ( 1, 1) 90°
% (-1, 1) 135°
[m, n] = size(X);
maxGrayScale = max(X) + 1;
X = floor(X.*grayScale./maxGrayScale);
@vtta
vtta / perceptron.m
Last active May 1, 2019 18:17
A simple non-linear perceptron classifier
LEARNING_RATE = 0.1;
MAX_ITERATIONS = 1e3;
MIN_ERROR = 1e-3;
%load input and target
perceptron_data;
[numInst, numDims] = size(input);
numClasses = size(target,2);
weights = randn(numClasses, 3*numDims);
isDone = false;
@vtta
vtta / nqueens-genetic-algorithm.cpp
Created May 1, 2019 18:17
N-Queens problem implemented using genetic algorithm. Support up to 255 queens. Algorithm will converge in a few minutes at most.
#include <bits/stdc++.h>
using namespace std;
bool CONVERGED = false;
int const MUTATION_STEP = 1e2;
int const ROULETTE_SIZE = 1e3;
int const MAX_INTERATION = 1e5;
void init(vector<string>& status)
@vtta
vtta / pip-uninstall-recursively.sh
Created August 8, 2019 15:32
pip uninstall recursively
#!/bin/sh
# for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done
for dep in $(pip show "$1" | grep Requires | sed 's/Requires: //g; s/,//g') ; do
pip uninstall -y $dep
done
pip uninstall -y "$1"