Skip to content

Instantly share code, notes, and snippets.

@adoc
adoc / mapquest_geocode.py
Created November 15, 2014 20:54
mapquest_geocode.py: Geocoding example using mapquest API. (geopy)
from geopy.geocoders import MapQuest, OpenMapQuest, Nominatim
omapquest_api_key = "APIKEYHERE"
gm = MapQuest(api_key=omapquest_api_key, timeout=60)
gom = OpenMapQuest(api_key=omapquest_api_key, timeout=60)
gn = Nominatim(timeout=60)
loc = "611 West Holt Blvd., ontario, ca, 91762"
@adoc
adoc / pkcs7.py
Last active July 25, 2021 09:46
#pkcs7.py3: Implementation of PKCS #7 padding. Based on: http://japrogbits.blogspot.com/2011/02/using-encrypted-data-between-python-and.html
"""
Python implementation of PKCS #7 padding.
RFC 2315: PKCS#7 page 21
Some content-encryption algorithms assume the
input length is a multiple of k octets, where k > 1, and
let the application define a method for handling inputs
whose lengths are not a multiple of k octets. For such
algorithms, the method shall be to pad the input at the
trailing end with k - (l mod k) octets all having value k -
@adoc
adoc / migrate.py
Created March 18, 2015 09:42
SQLAlchemy Migration Tool
#!/usr/bin/env python
"""
# Original Author: Tyler Lesmann
# Original Source: http://www.tylerlesmann.com/2009/apr/27/copying-databases-across-platforms-sqlalchemy/
# TODO: Look at https://gist.github.com/thoas/1589496 if any
# "sequencing" issues come in to play.
@adoc
adoc / fblogin_test.py
Created March 2, 2015 09:03
py: Simple facebook login
import os
import base64
import flask
import urllib.parse
import requests
app = flask.Flask(__name__)
APP_ID = "ID"
APP_SECRET = "SECRET"
@adoc
adoc / rng.js
Created January 25, 2014 05:20
rng.js: Random number generator
//http://www-cs-students.stanford.edu/~tjw/jsbn/prng.js
// prng4.js - uses Arcfour as a PRNG
function Arcfour() {
this.i = 0;
this.j = 0;
this.S = new Array();
}
// Initialize arcfour context from key, an array of ints, each from [0..255]
@adoc
adoc / rndaz09
Last active February 3, 2016 20:04
rndaz09 N: Cat N urandom characters and return limited [a-z0-9]
#!/bin/bash
# /usr/local/sbin/rndaz09 N: Cat N urandom characters and return limited [a-z0-9]
# link: https://gist.github.com/adoc/275cba7ef1639cc648bb
# resource: http://stackoverflow.com/a/2793856
cat /dev/urandom | tr -cd 'a-z0-9' | head -c $1
@adoc
adoc / hashdeept
Last active February 3, 2016 20:03
hashdeept $@: Hashdeep and trim "##" and "%%%%" lines
#!/bin/bash
# /usr/local/sbin/hashdeept $@: Hashdeep and trim "##" and "%%%%" lines
# author: https://github.com/adoc
# link: https://gist.github.com/adoc/8c117fb895c6dfdc962d
# resources:
# http://unix.stackexchange.com/a/174720
# deps:
# hashdeep (http://md5deep.sourceforge.net/)
# todo:
# check incoming ards for -l and -j??
@adoc
adoc / backbone_auth.js
Last active January 4, 2016 11:09
backbone_auth.js: Provides bi-directional HMAC hooked in to Model and Collection.
/*
backbone_auth.js
Provides bi-directional HMAC hooked in to Model and Collection.
Author: github.com/adoc
Location: https://gist.github.com/adoc/8613376
*/
define(['underscore', 'backbone', 'config', 'events', 'auth_client', 'persist'],
@adoc
adoc / gist:8613254
Created January 25, 2014 08:00
temp: api call outside of backbone
// api calls outside of backbone.
var apiCall = function(uri, data, success, method) {
data = data || {};
method = method || 'GET';
$.ajax({
method: method,
url: opts.apiRoot + uri,
data: method == 'POST' ? JSON.stringify(data) : data,
dataType: 'json',
@adoc
adoc / gist:8613268
Created January 25, 2014 08:01
temp: tightenauth
// Update the time provider and ip address.
// Called on every page, cause.
var tightenAuth22 = function() {
apiCall('/ping', {}, function(data) {
authApi.timeProvider.reset(data._time);
authApi.clientIp = data._addr;
authApi.tight = true;
if (opts.success) {
opts.success();