Skip to content

Instantly share code, notes, and snippets.

@yig
yig / latexmk-fast
Created January 15, 2016 04:36
Runs latexmk in draft mode (fastest) followed by a batch mode (actually generate the PDF).
#!/bin/bash
## Simple draft mode followed by pdflatex once by using the print hook.
## With no arguments, it will follow a 'latexmkrc' file if there is one.
## You still get the nice error messages at the end:
latexmk -pdf -pdflatex='pdflatex -draftmode %O %S && touch %D' -print=pdf -e '$lpr_pdf=q|pdflatex -interaction=batchmode -synctex=1 %R|' "$@"
@yig
yig / pythonlike.h
Last active April 22, 2021 20:45
C++ header-only convenience functions that behave like python standard library functions.
#ifndef __pythonlike_h__
#define __pythonlike_h__
/*
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
Adapted from my old "stl.h"
On GitHub as a gist: https://gist.github.com/yig/32fe51874f3911d1c612
*/
@yig
yig / saveAs( blob, filename )
Last active December 7, 2015 02:52
Simple implementation of saveAs from the withdrawn HTML5 FileSaver API. It's a baby version of eligrey/FileSaver.js.
function saveAs( blob, name ) {
"use strict";
// Inspired by Syntax: http://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser/23451803#23451803
// Initially created to work around a bug in eligray/FileSaver.js
// which prevented saving multiple files
// (Issue 165: https://github.com/eligrey/FileSaver.js/issues/165 ).
// Create a hidden `a` element.
var a = document.createElement("a");
@yig
yig / triangle_area.py
Last active September 22, 2015 06:10
Compare the accuracy of various techniques for computing a triangle's area
from __future__ import print_function, division
from math import sqrt
'''
The Orient2D, Area2D, and ShewchukArea3D functions are
from "Lecture Notes on Geometric Robustness" by Jonathan Richard Shewchuk (2013).
URL: http://www.cs.berkeley.edu/~jrs/meshpapers/robnotes.pdf
'''
@yig
yig / stable_normals.py
Last active September 19, 2015 21:15
Test the numerical stability of different techniques for computing normals.
from __future__ import print_function, division
from math import *
from numpy import *
from pprint import pprint
def get_rotation_matrix( axis, radians ):
'''
Given the axis, angle rotation defined by 'axis' and 'radians', returns a
@yig
yig / img2img.py
Created August 31, 2015 20:11
Simple command line script to convert a file from any image format to another. Based on Python Imaging Library. Not based on ImageMagick.
#!/usr/bin/env python2.7
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
'''
import os, sys
@yig
yig / remove_duplicate_media.py
Created May 14, 2015 01:01
Searches for duplicate files (based on md5) and offers to remove them. For JPEG's, runs md5 on the raw image data.
import sys
from glob import glob
import os
import subprocess
kHarmful = False
argv = list( sys.argv )
try:
@yig
yig / deduplicate.py
Created May 14, 2015 00:49
Replaces duplicate files (based on md5) with hard links. Use only if you understand the ramifications of this. Runs in dry-run mode by default.
#!/usr/bin/env python
import os, hashlib
kDryRun = True
## From: http://stackoverflow.com/questions/1131220/get-md5-hash-of-a-files-without-open-it-in-python
def md5_for_file(f, block_size=2**20):
md5 = hashlib.md5()
while True:
@yig
yig / Replace.py
Created May 14, 2015 00:46
A command line tool for find/replace in filenames (and even paths).
#!/usr/bin/env python -OO
import sys
import os
harmful = False
overwrite = False
full_path = False
def usage():
@yig
yig / Latex space saving tricks
Last active October 15, 2025 13:42
Latex space saving tricks
%% Make everything look better.
%% http://tex.stackexchange.com/questions/553/what-packages-do-people-load-by-default-in-latex
%% http://www.howtotex.com/packages/9-essential-latex-packages-everyone-should-use/
\usepackage{microtype}
%% Shrink space around figures.
%% This beats manually adding negative \vspace commands everywhere.
%\setlength{\textfloatsep}{0pt}
%\setlength{\textfloatsep}{20pt plus 2pt minus 4pt}
%\setlength{\textfloatsep}{10pt plus 2pt minus 4pt}