Skip to content

Instantly share code, notes, and snippets.

View joestump's full-sized avatar

Joe Stump joestump

View GitHub Profile
<?php
$strings = array(
'adsfa sdf adf asdf asdf adfasdfa sdf asdf',
'i like to buy ^abc, ^aa, ^aaaa, ^d.',
'^^Here is my twitter comment.',
'Here is my tweet. ^^I like turtles.'
);
foreach ($strings as $str) {
class URLSequence(models.Model):
id = models.ItemName()
urls = models.NumberField(required=True, default=0)
class Meta:
connection = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET)
domain = 'shortener_url'
@staticmethod
def id():
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import AppCache
from django.conf import settings
import simpledb
class Command(BaseCommand):
help = ("Sync all of the SimpleDB domains.")
def handle(self, *args, **options):
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import AppCache
from django.conf import settings
import simpledb
class Command(BaseCommand):
help = ("Sync all of the SimpleDB domains.")
def handle(self, *args, **options):
>>> for u in URL.objects.filter(views=0):
... print u.url
...
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/jstump/dev/stu.mp/stump/packages/simpledb/simpledb.py", line 768, in __iter__
return iter(self._get_results())
File "/home/jstump/dev/stu.mp/stump/packages/simpledb/models.py", line 134, in _get_results
self.domain.select(self.to_expression())]
File "/home/jstump/dev/stu.mp/stump/packages/simpledb/simpledb.py", line 850, in to_expression
class URL(models.Model):
id = models.ItemName()
url = models.Field(required=True)
views = models.NumberField(required=True, default=0)
class Meta:
connection = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET)
domain = 'shortener_url'
def save(self):
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
class XMLTree(object):
nodes = {}
def __init__(self, node):
self.node = node
class Model(object):
keyspace = None
column_family = None
key = None
data = {}
required = []
modified = False
def __init__(self, **kwargs):
if self.key in kwargs and len(kwargs) == 1:
# Create a new PYTHONPATH using all of the packages
# that have been checked out into $HOME/dev
_NEW_PATH=""
for i in `ls $HOME/dev`
do
_NEW_PATH="$_NEW_PATH:$HOME/dev/$i"
done
export PYTHONPATH="${_NEW_PATH:1}:$PYTHONPATH"
"""
Below is an example of some signals I use in Django to update denormalized counts and to Tweet out
automatically when certain records are created.
"""
def channel_post_save(sender, instance, created, **kwargs):
"""
Increment the number of channels in the category. A corollary `channel_post_delete` would be
created as well to reverse this change out. I attach my signals in my models.py and save
them in signals.py.