Skip to content

Instantly share code, notes, and snippets.

View tarkatronic's full-sized avatar

Joey Wilhelm tarkatronic

View GitHub Profile
def search_list(term, words, deep):
result = []
idx = 0
while idx < len(words):
try:
idx = words.index(term, idx)
result.append(idx)
idx += 1 # Start from the next element
if not deep:
break
@tarkatronic
tarkatronic / redis_session_backend.py
Created August 14, 2012 16:23 — forked from mikeyk/redis_session_backend.py
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@tarkatronic
tarkatronic / admin.py
Created March 13, 2012 18:08
Django row-level permissions
"""This is just an example of how to provide permissions on a per-object basis in the admin"""
from django.contrib import admin
from django.contrib.auth.models import Permission
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from account.models import ObjectGroupPermission, ObjectUserPermission
from myapp.models import MyModel
@tarkatronic
tarkatronic / transfer_slicehost.py
Created July 21, 2011 22:23
Transferring DNS records from Slicehost to 6sync via API calls
from pyactiveresource.activeresource import ActiveResource
from biscuit.api import APIHandler
ip_translations = {'aaa.bbb.ccc.ddd': 'xxx.yyy.zzz.qqq',
'eee.fff.ggg.hhh': 'ppp.qqq.rrr.sss'}
slice_api_key = 'xxxxx_YOUR_SLICEHOST_API_KEY_HERE_xxxxx'
slice_api_url = 'https://%[email protected]/' % slice_api_key
@tarkatronic
tarkatronic / slicehost_zone_batch_update.py
Created August 25, 2010 21:17
Shift A records to a new IP for any number of domains at a time using Slicehost's API. Requires http://code.google.com/p/pyactiveresource/
from pyactiveresource.activeresource import ActiveResource
from pyactiveresource.connection import UnauthorizedAccess
#### CONFIGURATION ####
from_ip = 'xxx.xxx.xxx.xxx'
to_ip = 'xxx.xxx.xxx.xxx'
update_domains = ('domain1.com.','domain2.net.','otherdomain.org.')
api_key = 'xxxxx_YOUR_API_KEY_HERE_xxxxx'
api_url = 'https://%[email protected]/' % api_key
@tarkatronic
tarkatronic / analytics.html
Created December 9, 2009 16:59
A mashup of the analytics demo and linechart plugin for gRaphael
<html>
<head>
<script type="text/javascript" src="raphael-1.2.5.js"></script>
<script type="text/javascript" src="raphael.path.methods.js"></script>
<script type="text/javascript" src="raphael.primitives.js"></script>
<script type="text/javascript" src="g.raphael-0.4.js"></script>
<script type="text/javascript" src="g.analytics.js"></script>
<script type="text/javascript">
$(function () {
$("#data").css({