Skip to content

Instantly share code, notes, and snippets.

View install_ensurepip.py
import os
import sys
import io
import tarfile
import urllib.request
ARCHIVE_URL = 'http://d.pr/f/YqS5+'
View antialias-test.py
# Tests for antialiasing a high-frequency image in various ways
# Nathan Reed, July 2014
# Written for Python 3.4; requires numpy and Pillow to be installed
import concurrent.futures
import math
import multiprocessing
import numpy as np
import optparse
import random
View music_formula_collection.txt
Collection of oneliner music formulas. Version 2011-10-18
I've tried to collect all the formulas in the related threads etc.
(excluding those that clearly sound like random first experiments or total
crap; when several variants are available, i've chosen the shortest one)
If you think I've missed something that should be here, please let me know.
====== 1ST ITERATION ======
@mvasilkov
mvasilkov / load.js
Created Aug 28, 2014
Image loader for canvas, suitable for JS13K
View load.js
function load(images, done) {
var toLoad = images.length
var res = Array(toLoad)
var loaded = 0
images.forEach(function (url, i) {
var image = new Image
image.onload = function () {
res[i] = this
if (++loaded == toLoad)
@mvasilkov
mvasilkov / _sin.sjs
Created Aug 19, 2014
Math.sin macro
View _sin.sjs
macro _sin {
case { _($x:lit) } =>
{
var res = Math.sin(unwrapSyntax(#{ $x }))
return [makeValue(res, #{ $x })]
}
case { _($x) } =>
{
return #{ Math.sin($x) }
View jsjs.js
function foo() {
this.a = function () { return 96 }
this.b = function () { return this.a() * 10101 }
}
function bar() {}
bar.prototype = new foo
b = new bar
b.a() // 96
View map.txt
# _ = empty
# X = solid ground
# S = sand
_________________
_____SSSSSS______
___SSSXXXXSSS____
____SSSXXXXSSS___
______SSSSSS_____
@mvasilkov
mvasilkov / remove_lines
Created Nov 18, 2013
Remove empty lines at the end of file.
View remove_lines
#!/bin/bash
last_non_blank_ln=$(grep -En ^. $1 |tail -n 1 |sed 's/:.*//')
head -n $((last_non_blank_ln + 1)) $1 > _xxx
mv _xxx $1
View gist:7487460
(box2d-html5) -> git commit
[master e170981] There are two sides to every issue: one side is right and the other is wrong, but the middle is always evil.
120 files changed, 125 insertions(+), 125 deletions(-)
rename contrib/{Enhancements/Controllers/b2BuoyancyController.js => enhancements/controllers/buoyancycontroller.js} (100%)
rename contrib/{Enhancements/Controllers/b2ConstantAccelController.js => enhancements/controllers/constantaccelcontroller.js} (100%)
rename contrib/{Enhancements/Controllers/b2ConstantForceController.js => enhancements/controllers/constantforcecontroller.js} (100%)
rename contrib/{Enhancements/Controllers/b2Controller.js => enhancements/controllers/controller.js} (100%)
rename contrib/{Enhancements/Controllers/b2GravityController.js => enhancements/controllers/gravitycontroller.js} (100%)
rename contrib/{Enhancements/Controllers/b2TensorDampingController.js => enhancements/controllers/tensordampingcontroller.js} (100%)
rewrite contrib/paths.json (99%)
@mvasilkov
mvasilkov / replace.py
Created Nov 6, 2013
Helper tool for Box2D-HTML5 conversion. Fucking kill Google, one Closure Library at a time.
View replace.py
import re
import sys
def replacer_pro(match):
print match.group(1)
parts = match.group(1).split('.')
init_code = ''
cur = ''
for part in parts:
if cur: