Skip to content

Instantly share code, notes, and snippets.

@yig
yig / index.html.py
Last active Oct 15, 2020
Make a simple, static index.html for a directory listing the files and their sizes.
View index.html.py
#!/usr/bin/env python3
# Author: Yotam Gingold <yotam@yotamgingold.com>
# License: Public Domain (CC0)
# URL: https://gist.github.com/yig/e59eaa22f5042320ecf18a87da4e44ae
from pathlib import Path
def make_index_html( path ):
path = Path(path)
@yig
yig / zoom-defang.sh
Last active May 14, 2020
Defang the macOS Zoom Installer. Extracts a .app that can be dragged to /Applications.
View zoom-defang.sh
#!/bin/sh
## Author: Yotam Gingold
## License: CC0 (public domain) https://creativecommons.org/share-your-work/public-domain/cc0/
## URL: https://gist.github.com/yig/af5bbb054bb9c4de39abc9156e6863e1/edit
## Download the latest Zoom installer.
echo "==> Downloading the latest Zoom installer."
cd ~/Downloads
curl -LO 'https://zoom.us/client/latest/Zoom.pkg'
@yig
yig / mortgage.py
Created Apr 2, 2020
Two useful functions for calculating lifetime mortgage payments
View mortgage.py
## Author: Yotam Gingold <yotam@yotamgingold.com>
## License: Public domain, CC0: https://creativecommons.org/share-your-work/public-domain/cc0/
## URL: https://gist.github.com/yig/6eb1c3170e6e2e05df810fca8e47f3ca
"""
You can calculate your monthly payment for a loan for X years with interest rate Y%. For example:
> monthly_payment_for_termination_in_X_years( years = 30, principal = 300_000, interest_rate_per_year = 3.75/100 )
$1389.35
@yig
yig / flatten.js
Created Jan 17, 2020 — forked from timo22345/flatten.js
Flatten.js, general SVG flattener. Flattens transformations of SVG shapes and paths. All shapes and path commands are supported.
View flatten.js
<!doctype html>
<html>
<title>Flatten.js, General SVG Flattener</title>
<head>
<script>
/*
Random path and shape generator, flattener test base: https://jsfiddle.net/fjm9423q/embedded/result/
Basic usage example: https://jsfiddle.net/nrjvmqur/embedded/result/
@yig
yig / gallery_simple.py
Last active Dec 20, 2018
Creates nearly the simplest possible static HTML image gallery for a set of images. Just the images with CSS max-width, max-height, padding, and optionally a title. Optional thumbnails.
View gallery_simple.py
@yig
yig / update_mactex.md
Created Aug 9, 2018
Instructions for updating MacTeX's BasicTeX every year
View update_mactex.md

Once you get the dreaded error message that tlmgr won't install any new packages, it's time to upgrade to the latest texlive.

  1. Save list of currently installed packages:

     tlmgr list --only-installed > previously_installed_texlive_packages.txt
    
  2. Download and install the latest BasicTex.pkg: http://www.tug.org/mactex/

  3. Save list of default packages:

@yig
yig / matrix derivatives.txt
Last active Nov 19, 2019
matrix derivatives via frobenius norm
View matrix derivatives.txt
matrix derivatives via Frobenius norm
# Automatic matrix derivatives: http://www.matrixcalculus.org/
# A good primer on basic matrix calculus: https://atmos.washington.edu/~dennis/MatrixCalculus.pdf
# The Matrix Reference Manual: http://www.ee.ic.ac.uk/hp/staff/dmb/matrix/intro.html#Intro
# Trying to understand the derivative of the inverse: https://math.stackexchange.com/questions/1471825/derivative-of-the-inverse-of-a-matrix
# Derivative of the pseudoinverse:
https://math.stackexchange.com/questions/2179160/derivative-of-pseudoinverse-with-respect-to-original-matrix
https://mathoverflow.net/questions/25778/analytical-formula-for-numerical-derivative-of-the-matrix-pseudo-inverse
@yig
yig / httpserver.jl
Last active Dec 4, 2019
A simple static file server written in Julia. Listens on localhost port 8000. Doesn't serve files outside current working directory (unless symlinked). Doesn't print directory listings.
View httpserver.jl
#=
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
Description: A simple static file server written in Julia. Listens on localhost port 8000. Doesn't serve files outside current working directory (unless symlinked). Doesn't print directory listings. Runs on Julia 1.3.
URL: https://gist.github.com/yig/f65e86b7730019d4060449f24342fcb4
=#
using HTTP
using Base.Filesystem
@yig
yig / controlc_pipeline.py
Last active Jan 13, 2018
How to handle control-C when piping output to tee from Python.
View controlc_pipeline.py
# Run with
## python -u controlc_pipeline.py | tee foo.out
# Then press control-C.
## You never see the output without an IOError handler,
## because an IOError is generated (stdout went away) before a KeyboardInterrupt.
## You could catch the IOError and redirect stdout manually. UPDATE: That doesn't seem to work.
## Or you could tell `tee` to ignore SIGINT and exit this program gracefully:
# python -u controlc_pipeline.py | tee -i foo.out
from __future__ import print_function, division
@yig
yig / DMAT2MATLAB.py
Created Aug 10, 2017
Convert a libigl DMAT to a Matlab .mat file.
View DMAT2MATLAB.py
#!/usr/bin/python
# Convert a libigl DMAT to a Matlab .mat file.
# Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
# License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
# On GitHub as a gist: https://gist.github.com/yig/0fb7fe73b2ce914c4b1d6de3b4e4ba01
from __future__ import print_function, division
from numpy import *
You can’t perform that action at this time.