Skip to content

Instantly share code, notes, and snippets.

View gavincangan's full-sized avatar

Barnabas Gavin Cangan gavincangan

View GitHub Profile
@gavincangan
gavincangan / printers.py
Created August 21, 2019 00:57
Pretty printers for Eigen::Matrix
# -*- coding: utf-8 -*-
# Source: https://bitbucket.org/eigen/eigen/raw/default/debug/gdb/printers.py
# https://stackoverflow.com/a/25088214/3138875
# This file is part of Eigen, a lightweight C++ template library
# for linear algebra.
#
# Copyright (C) 2009 Benjamin Schindler <bschindler@inf.ethz.ch>
#

Hokie Notes

ARC - Request interactive jobs

Newriver

interact -q p100_normal_q -l procs=2,gpus=1 -l walltime=20:00:00

Huckleberry / Cascades (slurm)

from matplotlib.backends.backend_pdf import PdfPages
def multipage(filename, figs=None, dpi=200):
pp = PdfPages(filename)
if figs is None:
figs = [plt.figure(n) for n in plt.get_fignums()]
for fig in figs:
try:
fig.savefig(pp, format='pdf')
except:
@gavincangan
gavincangan / spline_interpolation.py
Created June 1, 2019 03:17 — forked from komasaru/spline_interpolation.py
Python script to calc 3D-Spline-Interpolation.
#! /usr/local/bin/python3.6
"""
3-D spline interpolation
(with graph drawing by matplotlib)
"""
import matplotlib.pyplot as plt
import sys
import traceback
class SplineInterpolation:
@gavincangan
gavincangan / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created May 31, 2019 01:52 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@gavincangan
gavincangan / bezier_curves.py
Created May 24, 2019 17:57 — forked from astrojuanlu/bezier_curves.py
Interactive Bézier curves with Python using just matplotlib.
import matplotlib
matplotlib.use('webagg')
import numpy as np
from scipy.special import binom
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
@gavincangan
gavincangan / map_capsLock_to_LShift.sh
Last active March 15, 2019 12:53
Map Caps Lock to LShift
# https://askubuntu.com/questions/574208/deactivate-caps-lock-in-14-04
# Add this to startup
xmodmap -e "keycode 66 = Shift_L NoSymbol Shift_L"
@gavincangan
gavincangan / tmux_color_palette.sh
Created March 15, 2019 12:30
Print tmux color palette
# How does the tmux color palette work?
# https://superuser.com/a/285400/916053
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"
done
# Then use colourxxx with tmux.
# Mind the 'u' in colour!
@gavincangan
gavincangan / check_cov_psd.m
Created March 5, 2019 19:45
Check whether a kernel results in a positive semi-definite covariance matrix using rejection sampling
% https://stats.stackexchange.com/a/394487/204863
clear; close all;
num_points = 100;
xrange = [-100, 100];
x = xrange(1) + 2 * xrange(2) * rand(num_points, 1);
yrange = [0, 20];
y = yrange(1) + 2 * yrange(2) * rand(num_points, 1);
@gavincangan
gavincangan / glob_cpp.cpp
Created February 27, 2019 18:23
Glob C++
/*
* Source: https://stackoverflow.com/questions/8401777/simple-glob-in-c-on-unix-system
*/
#include <glob.h> // glob(), globfree()
#include <string.h> // memset()
#include <vector>
#include <stdexcept>
#include <string>
#include <sstream>