Skip to content

Instantly share code, notes, and snippets.

@yig
yig / JavaScript reference.md
Last active April 21, 2024 23:36
An overview of JavaScript best practices. Geared towards someone with a C/C++/Java/Python background.

JavaScript reference for non-JavaScript programmers

Author: Yotam Gingold
License: Public Domain (CC0)

This document is intended as a reference or introduction to JavaScript for someone familiar with a language like C/C++/Java or Python. It follows best practices and gathers the scattered wisdom from matny stackoverflow questions and in-depth JavaScript essays. It relies on no external libraries.

#!/bin/sh
#
# Startup script for btsync
# Copy to /usr/local/etc/rc.d/S99btsync.sh and chown to root:root
#
# Stop myself if running
btsyncdir="/var/services/homes/yotam/btsync/"
btsync="${btsyncdir}/btsync"
pidfile="${btsyncdir}/.sync/sync.pid"
#
'''
Author: Yotam Gingold <yotam (strudel) yotamgingold.com>
License: Public Domain. (I, Yotam Gingold, the author, dedicate any copyright to the Public Domain.)
http://creativecommons.org/publicdomain/zero/1.0/
'''
from math import sqrt
from numpy import asfarray
def sgn( x ):
@yig
yig / Latex space saving tricks
Last active October 11, 2024 03:23
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}
@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 / 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 / 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 / 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 / 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 / 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
'''