Skip to content

Instantly share code, notes, and snippets.

View ekzhang's full-sized avatar

Eric Zhang ekzhang

View GitHub Profile
@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
Loading
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",
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ekzhang
ekzhang / gerrymandering.py
Last active October 29, 2018 19:09
Cleaned up solution to Gerrymandering (HackMIT Puzzle Hunt 2018)
import copy
import random
import numpy as np
import pandas as pd
from scipy.stats import norm
pa, pb = pd.read_json('voters.json').voters_by_block
population_a, population_b = np.array(pa), np.array(pb)
population = population_a + population_b
@ekzhang
ekzhang / Gerrymandering.ipynb
Created July 17, 2018 04:24
Gerrymandering solution (HackMIT Puzzle Hunt 2018)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ekzhang
ekzhang / MaxFlow.cpp
Created August 7, 2017 02:06
Maximum-Flow solver using Dinic's Blocking Flow Algorithm.
#include <bits/stdc++.h>
using namespace std;
/* Maximum-Flow solver using Dinic's Blocking Flow Algorithm.
* Time Complexity:
* - O(V^2 E) for general graphs, but in practice ~O(E^1.5)
* - O(V^(1/2) E) for bipartite matching
* - O(min(V^(2/3), E^(1/2)) E) for unit capacity graphs
*/
template<int V, class T=long long>
@ekzhang
ekzhang / MinCostMaxFlow.cpp
Last active August 7, 2017 02:00
Minimum-Cost, Maximum-Flow solver using Successive Shortest Paths with Dijkstra and SPFA-SLF.
#include <bits/stdc++.h>
using namespace std;
/* Minimum-Cost, Maximum-Flow solver using Successive Shortest Paths with Dijkstra and SPFA-SLF.
* Requirements:
* - No duplicate or antiparallel edges with different costs.
* - No negative cycles.
* Time Complexity: O(Ef lg V) average-case, O(VE + Ef lg V) worst-case.
*/
template<int V, class T=long long>