Skip to content

Instantly share code, notes, and snippets.

View mekarpeles's full-sized avatar
📚
Universal Access to All Knowledge

Mek mekarpeles

📚
Universal Access to All Knowledge
View GitHub Profile
@mekarpeles
mekarpeles / gist:3408081
Created August 20, 2012 21:30
Python 2.7 Performance Comparison: list concatenation (+) vs list.extend()
mek@bigbertha:~/7-Projects$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> def test():
... """Comapring concat. + vs list.extend"""
... x = range(10000000)
... y = range(10000000)
... x0 = time.clock()
@mekarpeles
mekarpeles / lazydb-mutlikey-example.py
Created September 24, 2012 00:33
Example of lazydb multiple keys
mek@apollo:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lazydb.lazydb import Db
>>> db = Db('test')
>>> db.put('a', '1')
'1'
>>> db.put('b', '1')
'1'
@mekarpeles
mekarpeles / github-api-example.py
Created November 2, 2012 00:02
A demonstration of using the Github API to access public user data
#-*- coding: utf-8 -*-
import requests
def user(username):
"""
>>> print(user('mekarpeles'))
{u'public_repos': 23, u'public_gists': 2, u'name': u'Michael E. Karpeles', u'created_at': u'2011-08-13T20:01:14Z', u'url': u'https://api.github.com/users/mekarpeles'\
, u'company': u'Hyperink', u'html_url': u'https://github.com/mekarpeles', u'id': 978325, u'blog': None, u'hireable': True, u'avatar_url': u'https://secure.gravatar.com/a\
vatar/7ca82283af0b65b163dde4f5f5e3fb41?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png', u'
@mekarpeles
mekarpeles / auth.py
Created November 16, 2012 09:23
Sessions and authentication module for Waltz
#-*- coding: utf-8 -*-
"""
auth.py
~~~~~~~
Sessions and authentication
"""
def initialize_session(web, app, storage_method, **kwargs):
web.config.session_parameters['ignore_expiry'] = False
@mekarpeles
mekarpeles / main.py
Last active December 11, 2015 10:08
An basic example implementing an application in Waltz
#!/usr/bin/env Python
import waltz
from waltz import track, db, render, session
urls = ('/session', 'Session',
'/analytics', 'Analytics',
'/', 'Index')
sessions = {'cart': waltz.Cart()}
@mekarpeles
mekarpeles / decorate.py
Last active December 11, 2015 17:19 — forked from anonymous/decorate.py
Added debug kwarg
def exponential_backoff(exception, err=None, tries=5, debug=False):
"""Exponentially backoff on a certain Exception exception.
params:
tries - num of expn backed off attempts before quitting
err - custom error msg to display in addition to 'e'
debug - default False, boolean deciding whether to raise
error msg e along with Exception instance
note:
* debug flag used to avoid raising security sensitive exception err msgs
@mekarpeles
mekarpeles / __init__.py
Created January 26, 2013 09:05
Auxiliary json file open and loading function -- /usr/lib/python2.7/json/__init__.py
def slurps(f, perms='r'):
"""Auxiliary json file open and loading function"""
try:
with open(f, perms) as fp:
return loads(fp.read())
except:
raise
@mekarpeles
mekarpeles / install.sh
Created February 8, 2013 02:23
The new and improved waltz v.0.1.64
#!/bin/bash
sudo pip install --upgrade waltz
@mekarpeles
mekarpeles / main.py
Last active December 14, 2015 09:09
Waltz render example
from waltz import render, setup
import derp
urls = ('/?', 'Index')
env = {"derp": derp}
app = setup.dancefloor(urls, globals(), env=env)
class Index:
@mekarpeles
mekarpeles / main.py
Last active December 14, 2015 10:59
Demonstration of RSS generation
#!/usr/bin/python
#-*- coding: utf-8 -*-
import waltz
from waltz import track, render
from datetime import datetime
urls = ('/analytics/?', 'waltz.modules.Analytics',
'/rss/?', 'Rss',
'/?', 'Index')