Skip to content

Instantly share code, notes, and snippets.

View eykd's full-sized avatar

David Eyk eykd

View GitHub Profile
@eykd
eykd / compare_sorted_unsorted_iteration.py
Last active December 22, 2015 09:39
A more robust approach to testing the findings at http://rickystewart.wordpress.com/2013/09/03/why-sorting-an-array-makes-a-python-loop-faster/ that factors out all the "buts" that immediately came to mind.
import timeit
sorted_setup = """
a = range(1000000)
"""
unsorted_setup = """
from random import shuffle
{}
shuffle(a)
@eykd
eykd / esv-api-example-http.txt
Created September 4, 2013 15:30
Interacting with reading plans on the ESV v2 API (using HTTPie from the command line).
$ http --verbose --form GET http://www.esvapi.org/v2/rest/readingPlanInfo key==IP reading-plan==bcp
GET /v2/rest/readingPlanInfo?key=IP&reading-plan=bcp HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Content-Length: 0
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: www.esvapi.org
User-Agent: HTTPie/0.4.1
@eykd
eykd / output
Created July 31, 2013 21:59
Python Serialization: Comparing the performance of msgpack, cPickle, and marshal.
In [33]: msgpack_lt, pickle_lt, marshal_lt
Out[33]: (0.004015207290649414, 0.039834022521972656, 0.007205963134765625)
In [34]: msgpack_dt, pickle_dt, marshal_dt
Out[34]: (0.015387773513793945, 0.04079103469848633, 0.006851911544799805)
In [35]: len(s_msgpack), len(s_pickle), len(s_marshal)
Out[35]: (16, 48, 41)
@eykd
eykd / backbone-jquery-lock.js
Created May 1, 2013 17:09
A lock implementation using a Backbone Model and jQuery Deferred. Only one caller can "own" the lock at a time. The lock maintains an internal queue of Deferreds that it resolves, in order, as it is released.
var Lock = Backbone.Model.extend({
initialize: function () {
this._queue = [];
this.set('_locked', false);
this.on('change:_locked', this._on_change_lock, this);
},
_on_change_lock: function (m, locked) {
if (!locked && this._queue.length) {
var d = this._queue.shift();
@eykd
eykd / apiclient.js
Created September 26, 2012 16:27
API Client code for getting Backbone to talk with Tastypie. Over-engineering at it's finest!
/*global Backbone:false, $:false, _:false, extend:false */
// Copyright (c) 2012, David Eyk for Good News Publishers
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
@eykd
eykd / hubot-markov.coffee
Created May 15, 2012 19:17
Markov plugin for Hubot
base_url = 'http://nymkit.com/generators/chatterbots/gort/'
module.exports = (robot) ->
robot.catchAll (msg) ->
if msg.message.text.match(/\bgort\b/i) or msg.message.text.match(/\n/)
# When addressed, I'll pull something out of my... sock
# drawer. Or, if it's a multi-line message, I'll add my
# two cents.
json_params =
name: 'gort'
@eykd
eykd / .gitignore
Created January 19, 2012 04:37
Full stack BDD testing with Behave+Mechanize+Django
*.pyc
bin/
include/
lib/
@eykd
eykd / traceback.py
Created September 9, 2011 22:48
Demonstrating bad password check for django_des_crypt password hashes in passlib
In [4]: u.password
Out[4]: u'crypt$MNVY.9ajgdvDQ$MNVY.9ajgdvDQ'
In [5]: u.check_password('foo')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
.../lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.pyc in <module>()
----> 1 u.check_password('foo')
.../src/passlib/passlib/ext/django/utils.pyc in check_password(user, raw_password)
@eykd
eykd / django_oauth_plus_tests.py
Created July 27, 2011 21:59
Failing unittests in django_oauth_plus_tests
import time
import re
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from oauth_provider.models import Resource, Consumer
from oauth_provider.models import Token
@eykd
eykd / nginx_error_rate.py
Created July 26, 2011 15:44
Munin plugin for displaying error rates from Nginx
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""nginx_error_rate -- Munin plugin to report the error rate in an access log.
The access log defaults to `/var/log/nginx/access.log`. This may be
customized with the following stanza in your munin plugin conf:
[nginx_error_rate]
env.access_log /path/to/access.log
"""