Skip to content

Instantly share code, notes, and snippets.

# vim: set ft=python :
from __future__ import print_function
import json
import sys
import datetime
from redis import StrictRedis as Redis
"""Create a map and render it as a pgm image.
(see http://netpbm.sourceforge.net/doc/pgm.html)
"""
import sys
import math
import json
from functools import lru_cache
from noise import snoise2
@aleksandarristic
aleksandarristic / cached_property_descriptor.py
Created September 6, 2013 10:13
A CachedProperty descriptor; It receives an expensive getter function (& optional arguments for it). The __get__ runs the getter function with the object instance as the first argument (& optional arguments provided in __init__) and caches the result. The __set__ just changes the cache to the 'value', __delete__ removes the cache.
class CachedProperty(object):
"""
A cached property; A bit specific, as
it runs the getter as an instance method
& forwards the instance & init args to it.
Uses python descriptors protocol
"""
def __init__(self, getter, *args):
self.getter = getter
self.args = args or None
@chanux
chanux / fixsrt.py
Created March 15, 2012 07:11
A simple python tool to fix time of srt files
#!/usr/bin/env python
from sys import argv, exit
from os import path
import datetime
if len(argv) == 5:
(script, inputf, outputf, sign, msec) = argv
else:
print "fixsrt <input.srt> <output.srt> <+/-> <milli seconds>"
exit(1)