Skip to content

Instantly share code, notes, and snippets.

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 ======
import Image, ExifTags
try:
image=Image.open(os.path.join(path, fileName))
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation': break
exif=dict(image._getexif().items())
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
@mvasilkov
mvasilkov / first_uniq.py
Created February 9, 2012 03:25
Return first non-repeating (unique) symbol in the string. With tests and timeit.
#!/usr/bin/env python
import re
from timeit import timeit
import unittest
UNIQ_RE = re.compile(r'(.)(?=.*?\1)')
TESTS = {
'test': 'e',
'plperl': 'e',
@mvasilkov
mvasilkov / restful.py
Created January 27, 2012 12:31
RestfulView from libanimuchan
from django.shortcuts import render
class RestfulView(object):
allowed_methods = ["GET", "POST"]
def __call__(self, request, *args, **kwargs):
if request.method not in self.allowed_methods or not hasattr(self, request.method):
return self.method_not_allowed(request)
return getattr(self, request.method)(request, *args, **kwargs)
# _ = empty
# X = solid ground
# S = sand
_________________
_____SSSSSS______
___SSSXXXXSSS____
____SSSXXXXSSS___
______SSSSSS_____
@mvasilkov
mvasilkov / remove_lines
Created November 18, 2013 05:12
Remove empty lines at the end of file.
#!/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
(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 November 6, 2013 18:29
Helper tool for Box2D-HTML5 conversion. Fucking kill Google, one Closure Library at a time.
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:
/(?:GLAPI\b)(.*?)(?:GL)?APIENTRY(.*?)\((.*?)\)/
@mvasilkov
mvasilkov / pcat
Created November 2, 2013 20:38
pcat: patch cat
#!/bin/bash
sed -E 's/[[:<:]]SetXYZ?[[:>:]]/Set/g' "$@"