Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / latexmk-ding
Created January 15, 2016 04:43
Runs latexmk in continuous mode. Runs quickly (draft mode followed by batch mode). Plays a ding sound when finished. Also copies the PDF aside, so that PDF viewers don't get confused by the partially-written PDF files.
#!/bin/bash
## I used cfxr to create a coin sound. afplay is an OS X command line sound playback tool.
DING='afplay -v .01 /mixed\ media/music/cfxr\ coin.wav'
## Silence the ding.
# DING=''
## Simple continuous ding with draft mode followed by a batch mode run which actually generates the PDF.
## Copies the PDF with the suffix -copy.pdf, so that live-updating PDF viewers don't choke trying to load the PDF while it is still being written.
### We can't distinguish between the first time latexmk launches the viewer regardless of changes and later launches of the viewer with changes.
@yig
yig / HandbrakeCLI-recursive
Last active September 13, 2019 21:26
Give HandbrakeCLI a path to a file or a directory and it will generate better-compressed "{.}-handbrake.mp4" files next to each video.
#!/bin/bash
## Depends on Handbrake command line tool, which you can download as a binary: https://handbrake.fr/downloads2.php
## This script calls it recursively on all videos found. As a one off, the command is:
# HandBrakeCLI -i path/to/input -o path/to/output.mp4' -O --preset 'Normal' --crop 0:0:0:0
usage()
{
echo 1>&2 "Usage:" "$0" 'path/to/video/dir1 [path/to/video/dir2 ...]'
exit -1
@yig
yig / wrapfigure_without_whitespace.tex
Created May 17, 2016 04:39
Eliminate white space around wrapfigure environments in LaTeX.
%% The typical answer for how to eliminate white space in wrapfigure doesn't work for me (I'm using a SIGGRAPH style sheet):
%% http://tex.stackexchange.com/questions/111393/too-much-space-around-wrap-figure
%% Instead, let's just offset the image.
%% The horizontal white space is \columnsep and the vertical white space is \intextsep.
%% Subtract them from the column width and offset the image accordingly.
%% How to move an image:
%% http://tex.stackexchange.com/questions/107340/how-to-shift-graphics-adjust-placement-of-figure-with-includegraphics
\begin{wrapfigure}[11]{R}{1in - .75\columnsep}
%\centering
\vspace{-\intextsep}
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
'''
from __future__ import print_function, division
from numpy import *
from skimage import color
@yig
yig / obj-thumbnails
Last active May 2, 2018 19:48
Create PNG thumbnails for OBJ files on OS X using built-in QuickLook (and ImageMagick `mogrify` to trim them afterwards)
#!/bin/bash
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
Description: Create PNG thumbnails for OBJ files on OS X using built-in QuickLook (and ImageMagick `mogrify` to trim them afterwards).
'''
for obj_file in "$@"; do
## qlmanage comes with OS X
@yig
yig / save_screenshot.js
Created August 19, 2016 03:20
How to save the contents of <canvas> tags to disk as PNG's with filenames
// Depends on:
// Blob: http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js
// canvas.toBlobHD: http://purl.eligrey.com/github/canvas-toBlob.js/blob/master/canvas-toBlob.js
function saveScreenshot( filename )
{
/// Open in a new window.
// var kMIMEType = "image/png";
// var dataURL = renderer.domElement.toDataURL( kMIMEType );
// window.open( dataURL );
@yig
yig / pillow_format_test.py
Last active August 21, 2016 04:48
A test to determine which high bit-depth image formats are supported by Pillow / PIL / Python Imaging Library.
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
'''
from __future__ import print_function, division
from numpy import *
from PIL import Image