Skip to content

Instantly share code, notes, and snippets.

View luiarthur's full-sized avatar

Arthur Lui luiarthur

View GitHub Profile
@luiarthur
luiarthur / figlet-fonts.txt
Last active March 24, 2022 17:45
Figlet fonts
1943____
### ## #### ### # #
## ## #### ### # #
## ## #### ### # #
## ## ## #### #### ### # #
## ## ## ## #### ### # #
## ## ### #### #### ### # #
### ## ## ## #### ### # #
## ## #### ### # #
@luiarthur
luiarthur / vim-tmux-install.sh
Last active February 16, 2023 03:05
vim+tmux
# Install plug.vim in ~/.vim/autoload
mkdir -p ~/.vim/autoload
wget https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -O ~/.vim/autoload/plug.vim
# Add plugins to ~/.vim/vimrc
echo -e "
call plug#begin()
Plug 'luiarthur/tmux.vim'
Plug 'luiarthur/red.vim'
call plug#end()
@luiarthur
luiarthur / ssh-gsoc.sh
Created March 22, 2022 17:46
start a stopped AWS EC2 instances
#!/bin/bash
# GSOC instance.
aws_instance_id=i-01234567d # dummy id.
# Start a stopped aws ec2 instance.
alias start_aws_instance="aws ec2 start-instances --instance-ids $gsoc_id"
# Stop a running aws ec2 instance.
alias stpo_aws_instance="aws ec2 stop-instances --instance-ids $gsoc_id"
@luiarthur
luiarthur / advi-python.ipynb
Last active February 16, 2023 03:07
ADVI demo in 100 lines of Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@luiarthur
luiarthur / reverse_forward_ad.py
Last active March 10, 2022 20:07
Pedagogical implementations of Reverse / Forward Automatic Differentiation (AD)
# See: https://rufflewind.com/2016-12-30/reverse-mode-automatic-differentiation
import numpy as np
# NOTE: Reverse AD is generally favored in statistics / ML because we usually
# optimize a likelihood / negative cost function, which is a scalar, in which
# case reverse AD requires only one evaluation of the objective, which could
# be expensive. Forward AD, while simpler to implement, requires as many
# evaluations of the objective as the number of parameters. So, it tends to be
# slower than Reverse AD when the number of parameters is > 10 or the objective
# is costly to compute..
@luiarthur
luiarthur / parallel-groups.sh
Created March 7, 2022 23:36
Run something in parallel, in groups.
# Number of cores to use.
NCORES=3
# Use parenthesis to suppress superfluous output.
(
for x in `seq 8`
do
((i%NCORES)) && ((i++==0)) && wait;
echo $x && sleep 2 & # comomand to execute.
done
@luiarthur
luiarthur / ProgressBar.py
Last active March 8, 2022 00:35
Basic Progress Bar for Python
"""
Basic progress bar.
"""
from datetime import timedelta, datetime
import time
def pbrange(*args, **kwargs):
return pbar(range(*args), **kwargs)
@luiarthur
luiarthur / gaussian_kernel.py
Created February 24, 2022 20:31
Gaussian Kernels in Python
import numpy as np
def gaussian_kernel(X, knots, sd):
"""
X: points to evaluate kernel (n x q)
knots: kernel locations (m x q)
sd: kernel width
"""
diff = X[..., None] - knots.T[None, ...] # n x q x m
ss = np.sum(diff ** 2, axis=1) # n x m
@luiarthur
luiarthur / gh-to-nbviewer.md
Created February 23, 2022 23:13
View GitHub Jupyter notebook on nbviewer
  1. Create a bookmark in your browser
  2. Copy and paste the code below into the url field.
  3. When viewing a jupyter notebook on GitHub, click on the bookmark to view the notebook in nbviewer.
javascript: (() => {
  const url = window.location.href;
  const nbviewer_url = "https://nbviewer.org/github/";
  const new_url = nbviewer_url + url.split("https://github.com/")[1];
 window.open(new_url);
@luiarthur
luiarthur / covariance_to_correlation.py
Created January 21, 2022 20:50 — forked from wiso/covariance_to_correlation.py
Compute correlation matrix from covariance matrix using numpy
import numpy as np
def correlation_from_covariance(covariance):
v = np.sqrt(np.diag(covariance))
outer_v = np.outer(v, v)
correlation = covariance / outer_v
correlation[covariance == 0] = 0
return correlation