Skip to content

Instantly share code, notes, and snippets.

@karlrohe
karlrohe / PCA_on_handwritten_2s.R
Created January 7, 2022 22:48
PCA on mnist handwritten 2's
# PCA on n=6990 images of handwritten 2's, each with d = 784 pixels.
# install.packages("remotes")
# remotes::install_github("jlmelville/snedata")
# thank you jlmelville for making this data so easy to access!
library(snedata)
library(magrittr)
library(Matrix)
library(rARPACK)
@standaloneSA
standaloneSA / nvidia.md
Last active April 29, 2024 17:11 — forked from meikuam/nvidia.md
Nvidia GPUs sorted by CUDA cores
@nikibobi
nikibobi / colab-latex.py
Created November 3, 2018 14:06
Add LaTeX support to a Colab notebook for SymPy
import sympy
def custom_latex_printer(exp, **options):
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
javascript(url=url)
return sympy.printing.latex(exp, **options)
sympy.init_printing(use_latex="mathjax", latex_printer=custom_latex_printer)
@alexg9010
alexg9010 / how_to_debug_rcpp.Rmd
Created October 23, 2017 09:36
How to debug Rcpp code in a package
---
title: "How to debug Rcpp code in a package"
output: html_document
author: Alexander Gosdschan
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@karpathy
karpathy / min-char-rnn.py
Last active May 11, 2024 20:19
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@stoneage7
stoneage7 / VDI-shrink-trim.md
Last active February 20, 2024 21:00
Automatically shrinking VDI images under VirtualBox

Motivation

The purpose of this gist is to set up a virtual machine in such a way that the on-disk image in the host machine automatically grows and shrinks as needed by the guest machine. This utilizes the (still undocumented) "--discard" and "--nonrotational" parameters in "VBoxManage storageattach" which make the attached image appear as an SSD to the guest. Guest OS will then issue TRIM commands to the virtual controller where such an image is attached. VirtualBox is then able to capture the commands and punch holes in the attached VDIs.

Although there is some initial setup needed, I think the time saved with babysitting the VDIs is worth it. Usually you would need to zero out the free space with zerofree or sdelete and then run "VBoxManage --compact" on your images. With this setup you can allocate a large dynamic VDI (1TB or so) and it will keep itself at minimum size for easy syncing, backup, etc. You can also set it up in a template machine if you use one for clones etc.

Requirements

  • Linux
@cdiener
cdiener / overload.R
Last active July 7, 2022 19:37
R operator overloading
a = "bla"
b = "so on"
class(a) = append("my_class", class(a))
'+.my_class' = function(x,y) paste(x,y,sep=" and ")
print(a+b)
@pkgw
pkgw / uval.py
Created April 4, 2013 02:38
"The worst possible way to propagate uncertainties."
"""
The worst possible way to propagate uncertainties.
"""
import numpy as np
from scipy.stats import scoreatpercentile as sap
n = 1024
uplaces = 1 # the argument is that you generally only know your uncerts to 1 place
udtype = np.double