This file contains 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
def attrs_verbose(self): | |
model = self.__class__ | |
# using this form: Record._meta.get_field('created_by').verbose_name | |
items = [] | |
for k, v in self.__dict__.items(): | |
try: | |
x = model._meta.get_field(k).verbose_name | |
except: | |
x = k | |
items += [(x, v)] |
This file contains 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
# FIRST: | |
from django import template | |
from poms.pomsapp import models | |
register = template.Library() | |
# for People template | |
@register.inclusion_tag('admin/snippets/personfactoid_info.html') |
This file contains 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
role, created = UserToUserRole.objects.get_or_create( | |
from_user=current_user, to_user=user, role='follow') |
This file contains 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 mysite.models import Publication, Article | |
# Create a couple of Publications. | |
>>> p1 = Publication(id=None, title='The Python Journal') | |
>>> p1.save() | |
>>> p2 = Publication(id=None, title='Science News') | |
>>> p2.save() | |
>>> p3 = Publication(id=None, title='Science Weekly') | |
>>> p3.save() |
This file contains 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
>>> ringo = Person.objects.create(name="Ringo Starr") | |
>>> paul = Person.objects.create(name="Paul McCartney") | |
>>> beatles = Group.objects.create(name="The Beatles") | |
>>> m1 = Membership(person=ringo, group=beatles, | |
... date_joined=date(1962, 8, 16), | |
... invite_reason= "Needed a new drummer.") | |
>>> m1.save() | |
>>> beatles.members.all() | |
[<Person: Ringo Starr>] | |
>>> ringo.group_set.all() |
This file contains 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
# still to be implemented |
This file contains 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
//Loops | |
//For loop | |
   for (int y = 0; y < 3; y ) { | |
   NSLog(@\"y = %i\", y); | |
} | |
//Do loop | |
x = 0; | |
do{ |
This file contains 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
import re | |
myString = "This is my tweet check it out http://tinyurl.com/blah" | |
print re.search("(?P<url>https?://[^\s]+)", myString).group("url") |
This file contains 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
#!/usr/local/bin/python | |
import sys | |
import time | |
havevalue = 0 | |
while havevalue < 1: | |
try: | |
table = input("What table to you want? ") |
This file contains 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
// This will forcefully reload the current page. No jQuery needed here. | |
location.reload(true); | |
// If your content might be cached by proxy servers and your URL has no query string, try this: | |
location.replace( | |
location.href.replace(/\?.*$/, '') + '?' + Math.random()); |