This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. |
OlderNewer