Skip to content

Instantly share code, notes, and snippets.

View harry830622's full-sized avatar

Harry Chang harry830622

View GitHub Profile
// Parsing
Node* root = 0;
map<string, Node*> nodes; //container of all nodes, choose map for easy query
vector<Edge*> edges;
vector<Node*> primary_inputs;
vector<Node*> primary_outputs;
string str = "";
while (getline(delay_file, str)) {
stringstream ss(str);
string tmp = "";
StageName = function(game) {};
(function() {
StageName.prototype = {
preload: function() {
},
create: function() {
},
cell*** ptr_two_d_array = new cell**[m];
for (int i = 0; i < m; ++i) {
cell[i] = new cell*[n];
for (int j = 0; j < n; ++j) {
cell[i][j] = new cell(args...);
}
}
@harry830622
harry830622 / pigeonhole.sh
Last active October 27, 2016 10:31
Generate the CNF of pigeonhole problem in DIMACS format. See also http://www.satcompetition.org/2009/format-benchmarks2009.html
#!/usr/bin/env bash
if [ "$1" = "" ]; then
echo "Please specify the number of holes"
echo "Usage: $0 NUMBER_OF_HOLES"
exit
fi
num_holes="$1"
num_pigeons="$(($1 + 1))"
@harry830622
harry830622 / Makefile
Created January 4, 2017 14:27
Makefile template
EXE = mp
CXX = clang++
CXXFLAGS = -std=c++11 -O2 -Wall
CPPS := $(wildcard src/*.cpp)
OBJS := $(addprefix obj/,$(notdir $(CPPS:.cpp=.o)))
.PHONY: all clean
all: obj $(EXE)
@harry830622
harry830622 / install.sh
Last active March 10, 2017 08:57
Arch Linux install script
#!/usr/bin/env bash
timedatectl set-ntp true
gdisk /dev/sda
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;
// Assumption: Initializing a vector with size before assignments runs faster
// then filling it by "push_back"s.
int main() {
#!/usr/bin/env python
# l: final length
# e: epsilon
# d: lambda
# u: mu
# dd: derivative of lambda
from mpmath import *
@harry830622
harry830622 / shuffle.js
Last active March 19, 2022 07:17
js utils
// Fisher-Yates shuffle algorithm
function shuffle(arr) {
const result = [...arr];
for (let i = result.length - 1; i >= 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
@harry830622
harry830622 / iterate_files_in_dir.sh
Last active January 13, 2020 08:39
Iterate over files in a directory
#!/bin/env bash
# For example, iterate over files in the home directory.
dir=~
for f in $dir/*; do
echo $f
done