Skip to content

Instantly share code, notes, and snippets.

@yig
yig / cffi_asarray.py
Last active March 2, 2018 03:04
An `asarray` function that wraps a cffi pointer in a numpy.array.
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain [CC0](http://creativecommons.org/publicdomain/zero/1.0/)
Description: An `asarray` function that wraps a cffi pointer in a numpy.array.
URL: https://gist.github.com/yig/77667e676163bbfc6c44af02657618a6
'''
from __future__ import print_function, division
import numpy
@yig
yig / gallery_simplest.py
Last active October 20, 2022 02:02
Creates the simplest possible static HTML image gallery for a set of images. Just the images with CSS max-width, max-height, and padding. Thumbnails optional.
@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
@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 / 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
'''
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 / 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}
@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 / 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 / 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|' "$@"