Skip to content

Instantly share code, notes, and snippets.

View ekzhang's full-sized avatar

Eric Zhang ekzhang

View GitHub Profile
@ekzhang
ekzhang / crontab
Last active February 4, 2024 11:37
Minecraft server tmux/cron scripts
0 8 * * * $HOME/scripts/restart.sh
15 8 * * * $HOME/scripts/fullrender.sh
@ekzhang
ekzhang / install_dotfiles.sh
Last active April 12, 2020 21:24
Install dotfiles for vim, bash, and tmux
#!/bin/bash
# Check for dependencies
if [ -z $(which git) ]; then
>&2 echo "Could not find Git."
exit 1
fi
if [ -z $(which wget) ]; then
>&2 echo "Could not find wget."
exit 1
@ekzhang
ekzhang / fd1.cpp
Created March 9, 2020 04:40
File descriptor copying tests with fork() and dup2()
#include <cstdio>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
using namespace std;
int main() {
int fd = open("fd.txt", O_CREAT | O_WRONLY | O_TRUNC, 644);
@ekzhang
ekzhang / bipartite_match.cpp
Created February 14, 2020 03:46
Harvard-MIT matching algorithm for Datamatch
#include <bits/stdc++.h>
using namespace std;
#define MAX_STUDENTS 10000
/* Minimum-Cost, Maximum-Flow solver using Successive Shortest Paths with Dijkstra and SPFA-SLF.
* Requirements:
* - Duplicate or antiparallel edges with different costs are allowed.
* - No negative cycles.
* Time Complexity: O(Ef lg V) average-case, O(VE + Ef lg V) worst-case with negative costs.
@ekzhang
ekzhang / ekzhang.sty
Last active May 8, 2024 20:40
LaTeX template and useful macros
\ProvidesPackage{ekzhang}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{asymptote}
\usepackage{cancel}
\usepackage{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{enumerate}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
@ekzhang
ekzhang / .vimrc
Last active August 4, 2021 00:48
" Begin vim-plug
set nocompatible
call plug#begin('~/.vim/plugged')
Plug 'VundleVim/Vundle.vim' " Vundle
Plug 'rstacruz/sparkup', {'rtp': 'vim/'} " Emmet-like HTML expansion
Plug 'w0ng/vim-hybrid' " Hybrid theme
Plug 'sheerun/vim-polyglot' " Enhanced language support
Plug 'scrooloose/nerdtree' " Tree explorer
Plug 'vim-scripts/delimitMate.vim' " Auto-close parens/quotes
Plug 'tpope/vim-sleuth' " Auto-detect indentation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ekzhang
ekzhang / splash.md
Last active October 5, 2019 19:06
Class pitches for MIT ESP Splash 2019

Putting Big Things in Tiny Boxes: An Introduction to Compression (1h50m, ★★★)

You take a photo on your iPhone X's 12MP camera; that's 12 million pixels! This is roughly 36 MB of data -- but it only takes about 1 MB of space on your computer. How were you able to store the entire image in 1/36 of its actual size?

The magic: compression algorithms!

We will be discussing various techniques for the compression of data, starting from the basics (RLE) and ranging to lossless methods such as entropy encoding, LZW compression, and the Burrows-Wheeler Transform.

The last part of the class will be an exploration of compression methods for images, taking a look at some ad hoc approaches that we might try (8-bit graphics!). We'll then conclude with an in-depth examination of how modern lossy algorithms, like JPEG, are able to achieve ~20x compression ratios with no perceptible change in quality.

@ekzhang
ekzhang / cinterop_sha512.c
Created September 26, 2019 21:27
SHA-512 in LLVM IR
// Interop for sha512.ll
// Reference: http://www.iwar.org.uk/comsec/resources/cipher/sha256-384-512.pdf
// Author: Eric Zhang
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-std=c++14", "-O2", "-Wall"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cpp",
"variants":
[
{
"name": "Run",