Skip to content

Instantly share code, notes, and snippets.

d = {192: u'A', 193: u'A', 194: u'A', 195: u'A', 196: u'A', 197: u'A',
199: u'C', 200: u'E', 201: u'E', 202: u'E', 203: u'E', 204: u'I',
205: u'I', 206: u'I', 207: u'I', 209: u'N', 210: u'O', 211: u'O',
212: u'O', 213: u'O', 214: u'O', 216: u'O', 217: u'U', 218: u'U',
219: u'U', 220: u'U', 221: u'Y', 224: u'a', 225: u'a', 226: u'a',
227: u'a', 228: u'a', 229: u'a', 231: u'c', 232: u'e', 233: u'e',
234: u'e', 235: u'e', 236: u'i', 237: u'i', 238: u'i', 239: u'i',
241: u'n', 242: u'o', 243: u'o', 244: u'o', 245: u'o', 246: u'o',
248: u'o', 249: u'u', 250: u'u', 251: u'u', 252: u'u', 253: u'y',
255: u'y'}
@SaneMethod
SaneMethod / ajaxCacheTransport.js
Last active December 18, 2015 23:29
Ajax transport example for json, for ajax caching.
/**
* This function performs the fetch from cache portion of the functionality needed to cache ajax
* calls and still fulfill the jqXHR Deferred Promise interface.
* See also $.ajaxPrefilter
* @method $.ajaxTransport
* @params options {Object} Options for the ajax call, modified with ajax standard settings
*/
$.ajaxTransport("json", function(options){
if (options.localCache)
{
@superdaigo
superdaigo / tasks.py
Created April 22, 2016 04:46
Celery rate_limit test script
"""
# Test celery's rate_limit
Tested version of python
$ python --version
Python 2.7.11
## Requirements
$ pip install celery==3.1.23
$ pip install SQLAlchemy==1.0.12
import base64
import hashlib
import hmac
import simplejson as json
def base64_url_decode(inp):
padding_factor = (4 - len(inp) % 4) % 4
inp += "="*padding_factor
return base64.b64decode(unicode(inp).translate(dict(zip(map(ord, u'-_'), u'+/'))))
@nealtodd
nealtodd / gist:a8f87b0d95e73eb482c5
Created June 10, 2015 11:10
Django management command to detect missing migration files.
import sys
from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import ProjectState
from django.db.utils import OperationalError
@SaneMethod
SaneMethod / ajaxCachePrefilter.js
Last active May 3, 2019 13:01
Ajax prefilter for caching, based on paul irish's work at https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises when paired with an appropriate ajaxTransport.
/**
* Prefilter for caching ajax calls - adapted from
* https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises.
* See also $.ajaxTransport.
* New parameters available on the ajax call:
* localCache : true, // required if we want to use the cache functionality
* cacheTTL : 1, // in hours. Optional
* cacheKey : 'post', // optional
* isCacheValid : function // optional - return true for valid, false for invalid
* @method $.ajaxPrefilter
@GitRay
GitRay / serialize.py
Last active May 24, 2019 06:53 — forked from mrocklin/serialize.py
Serialization benchmark
# This has been edited to work with python3. Some of the tested combinations will not work in python2.
import pandas as pd
df = pd.DataFrame({'text': [str(i % 1000) for i in range(1000000)],
'numbers': range(1000000)})
import pickle
# Python 3 has no cPickle
#import cPickle
import json
from functools import partial
@bofm
bofm / escape_xml.py
Last active July 30, 2019 22:22
Escape invalid XML characters in Python 3
#!/usr/bin/env python3
import sys
import re
# https://trac-hacks.org/ticket/11050#comment:13
_illegal_unichrs = ((0x00, 0x08), (0x0B, 0x1F), (0x7F, 0x84), (0x86, 0x9F),
(0xD800, 0xDFFF), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF),
(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF),
(0x3FFFE, 0x3FFFF), (0x4FFFE, 0x4FFFF),
@jacoor
jacoor / AdditionalDataListApiView.py
Created March 5, 2014 15:37
additional data for listApiView for django.rest.framework
class TransactionsList(ListAPIView):
"""
List all transactions for currently logged in user, paginated by 25
page -- page number
ordering -- yoddle_amount, created, yoddle_description, reverse order ie. -yoddle_amount
"""
model = Transaction
@thomwolf
thomwolf / attention_layer_pytorch.py
Last active January 25, 2021 00:51
A pyTorch attention layer for torchMoji model
class Attention(Module):
"""
Computes a weighted average of channels across timesteps (1 parameter pr. channel).
"""
def __init__(self, attention_size, return_attention=False):
""" Initialize the attention layer
# Arguments:
attention_size: Size of the attention vector.
return_attention: If true, output will include the weight for each input token
used for the prediction