Skip to content

Instantly share code, notes, and snippets.

@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 / sendmail.py
Created February 14, 2015 09:52
sendmail.py3 - Small sendmail lib for Python 3
import logging
log = logging.getLogger(__name__)
import codecs
from subprocess import Popen, PIPE
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
from email.mime.text import MIMEText
var formError = function (options) {
/*
options expected:
input_el - $selector for input field
error_el - $selector for error div
hide_error_duration - Duration in ms to hide the error.
hide_error_animation_duration - Jesus...
*/
var options = _.extend({}, options);
@adoc
adoc / gist:fa817fd9a232859b82cd
Created February 5, 2015 10:14
Fancy Scroller Start.
// TODO: Encaps this and fancyScroll in function.
var currentObj = null;
var fancyScrolling = false;
function fancyScroll(ev, down) {
var scrollToOffset = 60,
scrollDuration = 500;
// Do nothing if we're already animating.
if (!$('body').is(':animated')) {
@adoc
adoc / gist:ff558ea45aee0e9e5178
Created January 9, 2015 01:56
Census data to zipcode center.
import itertools as IT
def area_of_polygon(x, y):
"""Calculates the signed area of an arbitrary polygon given its verticies
http://stackoverflow.com/a/4682656/190597 (Joe Kington)
http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm#2D%20Polygons
"""
area = 0.0
for i in range(-1, len(x) - 1):
area += x[i] * (y[i + 1] - y[i - 1])
@adoc
adoc / forme_sec_ex.py
Created November 15, 2014 20:56
forme.validators.sec usage example
import time
import forme.validators.sec
import formencode
v = forme.validators.sec.HmacValidator(b'12345')
val = v.from_python(b'abcdef')
v.to_python(val)
@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 / freeze.py
Created November 11, 2014 03:36
py: Freeze a nested dict, tuple and/or list. Used to check whether a given state has changed.
def freeze(obj):
"""
"""
def _freeze(obj):
def do_list():
for i in obj:
yield _freeze(i)
def do_dict():
for k, v in obj.items():
@adoc
adoc / SocketioModel.js
Created October 31, 2014 00:16
SocketioModel.js: Example of a backbone.js model enabled with socketio rather than "ajax". Very basic and not supporting the full backbone API.
var SocketioModel = Backbone.Model.extend({
//
constructor: function (attributes, options) {
options || (options = {});
if (options.socket) this.socket = options.socket;
if (options.controller) this.controller = options.controller;
if (options.model_id) this.id = options.model_id;
Backbone.Model.apply(this, arguments);
},
@adoc
adoc / socketRequest.js
Last active August 29, 2015 14:08
socketRequest: Mimics a very simple Request/Response dynamic through a socket.
/* Mimics a very simple Request/Response dynamic through a
socket.
see `bicycle_path.views.EnabledNamespace` for an example of
the server-side component.
*/
function socketRequest(socket, method, data, options) {
data || (data = {});
options || (options = {});
options.timeout || (options.timeout = 10000);