Skip to content

Instantly share code, notes, and snippets.

@hzqjyyx
hzqjyyx / spin_install.sh
Last active September 9, 2019 04:19
install spin and iSpin in Windows
# install cygwin64 of x86 version.
# once you installed the application, close it.
# run PowerShell as Admin, and input follows:
.\setup-x86.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel
# the command installs gcc compiler which is necessary
# download spin and ispin files from [here](http://spinroot.com/spin/Src/index.html)
# extract
# open cygwin
@hzqjyyx
hzqjyyx / Mininet.sh
Last active September 13, 2018 02:09
Install and use mininet
# sudo apt install pip
sudo apt-get update
sudo apt-get install -y git vim-nox python-setuptools python-all-dev flex bison traceroute
sudo apt install python3-pip
git clone git://github.com/mininet/mininet
cd mininet
git tag # list available versions
git checkout 2.3.0d3 # or whatever version you wish to install
cd ..
@hzqjyyx
hzqjyyx / OneProducerConsumer.java
Created September 2, 2018 23:12
Producer and Consumer problems implemented by Java
import java.util.concurrent.*;
public class Restaurant {
Meal meal;
ExecutorService exec = Executors.newCachedThreadPool();
WaitPerson waitPerson = new WaitPerson(this);
Chef chef = new Chef(this);
public Restaurant() {
exec.execute(chef);
sudo apt-get update
sudo apt update
sudo apt upgrade
sudo apt-get install -y mysql-server
sudo apt-get install -y java
# Test MySQL service
systemctl status mysql.service
# Install Python2 and Python3-pip
sudo apt install -y python2.7 python-pip
@hzqjyyx
hzqjyyx / Print2DMatrix.java
Created June 21, 2018 01:50
Print 2D matrix
public void printMatrix(int[][] matrix) {
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
System.out.printf("%4d", matrix[row][col]);
}
System.out.println();
}
}
@hzqjyyx
hzqjyyx / BST.java
Last active December 1, 2018 16:41
public class BST {
private TreeNode root;
private TreeNode findRecursive(TreeNode node, int t) {
if (node == null) return null;
if (node.val == t) return node;
else if (node.val > t) return findRecursive(node.left, t);
else return findRecursive(node.right, t);
}
public class ArrayList<T> implements ILIst<T> {
private T[] arrays;
private int size;
private static final int INIT_CAPABILITY = 16;
public static final float RESIZE_FACTOR = 0.75f;
public ArrayList() {
this.arrays = (T[]) new Object[INIT_CAPABILITY];
this.size = 0;
}
var e = document.createElement('script');
e.setAttribute('src', 'https://nytimes.github.io/svg-crowbar/svg-crowbar.js');
e.setAttribute('class', 'svg-crowbar');
document.body.appendChild(e);
@hzqjyyx
hzqjyyx / AllowUWPUseSS.bat
Created June 10, 2018 07:54
Allow ALL windows uwp apps use proxy
@echo OFF
echo 清楚所有程序 && CheckNetIsolation.exe LoopbackExempt -c 1>nul
cd %USERPROFILE%\AppData\Local\Packages
echo 开始添加程序
for /d %%i in (*) do echo 添加程序%%i && CheckNetIsolation.exe LoopbackExempt -a -n = %%i 1>nul
pause
@hzqjyyx
hzqjyyx / qqq.java
Last active December 19, 2017 23:23
Union Find
public class QuickUnionUF{
private int[] id;
public QuickUnionUF(int N) {
id = new int[N];
for (int i=0;i<N;i++) {
id[i] = i;
}
}
// depth of tree