Skip to content

Instantly share code, notes, and snippets.

View 0atman's full-sized avatar
🦀
Oxidising

Tristram Oaten 0atman

🦀
Oxidising
View GitHub Profile
@0atman
0atman / models.py
Created February 20, 2013 16:32
Django mixin-model for audit stats
class AuditStatsModelMixin(models.Model):
"audit metadata"
created_on = models.DateTimeField(auto_now_add=True)
created_ip = models.IPAddressField(null=True)
created_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_created_by")
updated_on = models.DateTimeField(auto_now=True)
updated_ip = models.IPAddressField(null=True)
updated_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_updated_by", null=True)
class Meta:
@0atman
0atman / models.py
Created February 25, 2013 15:14
AccessLevel model
class AccessLevel(models.Model):
user = models.ForeignKey(User, related_name='access_levels')
access_level = models.CharField(
max_length=12,
choices=(("open", "open"), ("closed", "closed")),
default="open"
)
starts = models.DateTimeField(auto_now=True)
expires = models.DateTimeField(blank=True, null=True)
content_type = models.ForeignKey(ContentType, related_name='access_levels')
@0atman
0atman / models.py
Created February 26, 2013 15:06
A generic grouping, other models m2m this.
class Group(models.Model):
"""
A generic grouping, other models m2m this.
"""
parent = models.ForeignKey('self', null=True, blank=True, related_name="children")
slug = models.SlugField(max_length=100, help_text="The slug field.", default="")
name = models.CharField(max_length=100)
def __unicode__(self):
return u"%s/%s" % (
#!/usr/bin/env python
"""
Copyright (c) 2009 Blackgate Research.
This work is made available under the terms of the Creative Commons Attribution-ShareAlike 3.0 license,
http://creativecommons.org/licenses/by-sa/3.0/."
"""
import time
import os
import sys
"""
This fabric file makes setting up and deploying a django application much
easier, but it does make a few assumptions. Namely that you're using Git,
Apache and mod_wsgi and your using Debian or Ubuntu. Also you should have
Django installed on your local machine and SSH installed on both the local
machine and any servers you want to deploy to.
_note that I've used the name project_name throughout this example. Replace
this with whatever your project is called._
@0atman
0atman / static-json.py
Created July 3, 2013 15:52
Simple flask-restful GET json stub
from flask import Flask
from flask.ext.restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class SimpleRest(Resource):
def get(self):
return {
@0atman
0atman / stub.py
Last active December 19, 2015 09:29
Stub out tastypie resources with static json
from django.http import HttpResponse
class Stub(object):
"""
Mixin. Use:
class MyResource(Stub, ...) # (Stub must be the first parent class)
Now MyResource will do no processing, auth or model-checking.
It will simply respond with the contents of the json file in the local directory
from hashlib import sha1
import uuid
import hmac
def generate_key(self):
"""
Lifted from:
https://github.com/toastdriven/django-tastypie/blob/master/tastypie/models.py#L46
"""
@0atman
0atman / logerrors.py
Created August 14, 2013 11:35
errors-by-date.py
import os
import datetime
from collections import Counter
import json
import argparse
parser = argparse.ArgumentParser(
description='Count Tomcat errors and group by date.'
)
@0atman
0atman / jenkins.sh
Created September 2, 2013 14:57
A fix for jenkin's inefficient SCM methods
git pull || (cd ../ && rmdir workspace && git checkout repo.git workspace && cd workspace)