Skip to content

Instantly share code, notes, and snippets.

@gameame
gameame / kippt_to_unmark.py
Created September 15, 2015 12:43
Converts Kippt json export to Unmark json format
"""
This script converts Kippt json export to unmark json format.
Lists in Kippt will be converted to tags.
Bonus: lines in notes staring with 'Tags: ' will be imported as tags.
Required packages: pytz, tzlocal, python-dateutil
Usage:
python kippt_to_unmark.py export_data.json > export.json
@gameame
gameame / gist:1376105
Created November 18, 2011 10:24
Enforce unique upload file names in Django
def unique_filename(path):
"""
Enforce unique upload file names.
Usage:
class MyModel(models.Model):
file = ImageField(upload_to=unique_filename("path/to/upload/dir"))
"""
import os, base64, datetime
@gameame
gameame / gist:1219599
Created September 15, 2011 15:41
Che t'avrà fatto mai la richiesta precedente?
if previous_request:
previous_request.delete()
del(previous_request)
previous_request = None
@gameame
gameame / each
Created February 21, 2011 14:49
Execute a command on each line in input using the line as parameter
#!/usr/bin/env python
# Example usage:
# ls|each cd PARAM\;pwd
import sys, subprocess
command = " ".join(sys.argv[1:])
command = command.replace("PARAM", "%(p)s")
i = 0
for parameter in sys.stdin.readlines():
@gameame
gameame / gist:713998
Created November 24, 2010 17:05
Using with statement in python 2.5
from __future__ import with_statement
@gameame
gameame / group_iterate.py
Created February 2, 2009 11:00
Iterates over the elements of list grouping elements by the specified amount.
def group_iterate(list = [], group_by = 1):
"""
Iterates over the elements of list grouping elements by the specified amount.
Example usage:
>>> for a in group_iterate(range(12), 3):
... print a
...
(0, 1, 2)
(3, 4, 5)
def test_shuffle(n, shuffle):
"""
Test a shuffle function.
"""
res = dict()
for i in xrange(n):
list = ['A', 'B', 'C']
shuffle(list)
res[''.join(list)] = res.get(''.join(list), 0) + 1
print res