Skip to content

Instantly share code, notes, and snippets.

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'+/'))))
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'}
@hrldcpr
hrldcpr / tree.md
Last active June 8, 2024 18:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@ndarville
ndarville / secret-key-gen.py
Created August 24, 2012 17:01
Generating a properly secure SECRET_KEY in Django
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 22, 2024 23:19
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@ruckus
ruckus / statistics.sql
Created June 5, 2013 23:26
Postgres statistics queries
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
@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)
{
@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
@tbrianjones
tbrianjones / free_email_provider_domains.txt
Last active July 8, 2024 00:56
A list of free email provider domains. Some of these are probably not around anymore. I've combined a dozen lists from around the web. Current "major providers" should all be in here as of the date this is created.
1033edge.com
11mail.com
123.com
123box.net
123india.com
123mail.cl
123qwe.co.uk
126.com
150ml.com
15meg4free.com
@bradmontgomery
bradmontgomery / install-comodo-ssl-cert-for-nginx.rst
Last active June 10, 2024 15:37
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert