Skip to content

Instantly share code, notes, and snippets.

@saaj
saaj / snippet.js
Last active August 29, 2015 14:06
Simplified LDML to POSIX datetime format converter
/**
* Simplified datetime format string converter from LDML (Locale Data Markup
* Language) aka CLDR (Unicode Common Locale Data Repository) format to POSIX
* aka strftime format.
*
* Main usecase is using complete localization from CLDR with D3, which
* implements POSIX style of date formatting.
*
* References:
* - http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
@saaj
saaj / ranking.py
Created June 9, 2014 11:31
Python SQLite ranking functions for sqlitefts
# -*- coding: utf-8 -*-
'''
Ranking code based on:
https://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py
'''
import struct
import math
@saaj
saaj / sqlite_tokenizer.py.patch
Last active August 29, 2015 14:02
Debugging Python SQLite FTS4 tokenizers with sqlite-fts-python 0.1
--- original/sqlite_tokenizer.py
+++ patched/sqlite_tokenizer.py
@@ -8,6 +8,10 @@
import ctypes
from ctypes import POINTER, CFUNCTYPE
import struct
+
+
+SQLITE_OK = 0
+SQLITE_DONE = 101
@saaj
saaj / gist:7154231
Created October 25, 2013 12:54
Routes 1.13 capturing group fix
--- ~/venv/1/lib/python2.7/site-packages/routes/route.py
+++ ~/venv/2/lib/python2.7/site-packages/routes/route.py
@@ -421,7 +421,7 @@
# our regexp first. It's still possible we could be completely
# blank as we have a default
if self.reqs.has_key(var) and self.defaults.has_key(var):
- reg = '(?:' + partreg + rest + ')?'
+ reg = '(' + partreg + rest + ')?'
# Or we have a regexp match with no default, so now being