Skip to content

Instantly share code, notes, and snippets.

@yig
yig / flatten.js
Created January 17, 2020 14:57 — forked from timo22345/flatten.js
Flatten.js, general SVG flattener. Flattens transformations of SVG shapes and paths. All shapes and path commands are supported.
<!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 February 20, 2021 22:17
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.
@yig
yig / update_mactex.md
Created August 9, 2018 21:23
Instructions for updating MacTeX's BasicTeX every year

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 December 1, 2023 19:39
matrix derivatives via frobenius norm
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 December 4, 2019 05:19
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.
#=
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 January 13, 2018 02:46
How to handle control-C when piping output to tee from Python.
# 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 August 10, 2017 20:08
Convert a libigl DMAT to a Matlab .mat file.
#!/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 *
@yig
yig / get_icloud_note
Created January 28, 2017 01:12
Command line program to get the contents of a Notes.app note
#!/bin/bash
# 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/76e87324ca1e9c754e8f28a8ef294dd0
usage()
{
echo 1>&2 "Usage:" "$0" '<Notes.app note name>'
exit -1
@yig
yig / trim-together.py
Last active May 22, 2017 01:18
Applies imagemagick's -trim to a set of images, but applies the same crop to all of them together (making sure to cut nothing untrimmable off from any)
#!/usr/bin/env python
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
Description: Applies imagemagick's -trim to a set of images, but applies the same crop to all of them together (making sure to cut nothing untrimmable off from any).
URL: https://gist.github.com/yig/7770ec597c595ae4bf1d0de4ca5a65cf
'''
from __future__ import print_function, division
@yig
yig / PNG colorspace experiments
Created October 31, 2016 15:58
What happens when you create a PNG with and without sRGB or linear RGB colorspace headers?
## Make a 5 pixel gradient PNG with no header: 0, 64, 128, 191, 255.
## Save the values with PIL (Python Image Library). PIL does not store a header.
python make_png.py
'''
from numpy import *
from PIL import Image
N = 5
arr = zeros( (1,N,3) )
arr[:] = linspace(0,1,N)[newaxis,:,newaxis]