Skip to content

Instantly share code, notes, and snippets.

View todofixthis's full-sized avatar

Phoenix todofixthis

View GitHub Profile
@todofixthis
todofixthis / example.py
Last active August 22, 2020 01:07
MongoDB transparent escaping/unescaping of illegal keys
# coding=utf-8
from __future__ import absolute_import, print_function, unicode_literals
from pprint import pprint
from bson import ObjectId, SON
from pymongo import MongoClient
from pymongo.collection import Collection
from key_escaper import DeterministicKeyEscaper
@todofixthis
todofixthis / jquery.serialize-json.js
Created October 23, 2016 00:38
Serialize form inputs into JSON, with support for `name[]` syntax.
(function($) {
$.extend($.fn, {
serializeJson: function() {
var payload = {},
regex = /^(\w+)\[(\d*)\]$/;
$.each($(this).serializeArray(), function(i, input) {
var res = input.name.match(regex);
if(res) {
if(! (res[1] in payload)) {
@todofixthis
todofixthis / bootstrap.toggleModal.js
Created October 22, 2016 19:08
Shows/Hides a Bootstrap 3 modal and returns a Promise object.
/** Shows or hides a Bootstrap 3 modal and returns a Promise object.
*
* Bootstrap's modal functions return before the modal is shown/
* hidden, which can cause glitches if subsequent code doesn't
* expect that.
*
* Unfortunately, there is no built-in way to defer an
* operation until after the modal is shown/hidden, so
* this function does a little monkey-patching to make
* it work.
@todofixthis
todofixthis / jquery.i18n.properties.snippet.js
Last active December 22, 2015 01:19
Adds JSONP support to `jquery.i18n.properties`. See http://code.google.com/p/jquery-i18n-properties/#Known_issues for more info.
/* ... snip ... */
/** Load and parse .properties files */
function loadAndParseFile(filename, settings) {
/* If we are making a cross-domain request, switch to JSONP mode. */
var dataType = 'text';
if( /^(https?:)?\/\//.test(filename) ) {
dataType = 'jsonp';
}