Skip to content

Instantly share code, notes, and snippets.

View luiarthur's full-sized avatar

Arthur Lui luiarthur

View GitHub Profile
@luiarthur
luiarthur / GP_turing_example.ipynb
Last active July 16, 2020 01:42
Example of how to fit a full GP model in Turing.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@luiarthur
luiarthur / hello-server.R
Created September 16, 2020 18:07
Hello in R -- Server demo
for (i in 1:100) {
Sys.sleep(1)
current_time = format(Sys.time(),usetz = TRUE)
cat(current_time, "|", "Iteration", i, "|", "Hello!", "\n")
}
@luiarthur
luiarthur / install-pyplot.jl
Last active January 13, 2021 23:16
Install own Julia's own Python for PyPlot
# Activate environment
import Pkg; Pkg.activate(".")
# If you are installing PyCall and PyPlot for the first time, just do
ENV["PYTHON"]=""
# before running
Pkg.add("PyPlot")
# If desired, install `PyCall` as well
@luiarthur
luiarthur / git-prompt.sh
Created December 3, 2021 18:49
Simple Git Prompt
# Author: Arthur Lui
# Last modified 31 August, 2019.
# Parse a git repo name, if possible.
parse_git_reponame() {
basename `git rev-parse --show-toplevel 2> /dev/null` 2> /dev/null
}
# Parse the current branch of a git repo, if possible.
parse_git_branch() {
@luiarthur
luiarthur / jupyter-lab-run-all-below.json
Last active January 13, 2022 20:20
Map `Ctrl+Shift+Enter` to run all cells below in jupyter lab by adding the following to Jupyter lab Settings -> Keyboard Shortcuts -> User Preferences
{
"shortcuts": [
{
"command": "notebook:run-all-below",
"keys": [
"Ctrl Shift Enter"
],
"selector": ".jp-Notebook:focus"
},
{
@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
@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 / 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 / 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 / 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