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
function processSiteRequest( data ) { | |
var sites = data.response.sites; | |
// loop through each site given back for the paginated result set | |
$.each( sites || [], function(index, site) { | |
debugPrint("Site: " + site.name); | |
$.each( site.content_categories || [], function( index, category ) { | |
// build up category to publisher map | |
debugPrint(" Category: " + category.name); | |
if ( category.id in category_publisher_map ) { |
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
# pip install django-orm-extensions | |
from django.contrib.gis.db.models import GeoManager | |
from django.contrib.gis.db.models.query import GeoQuerySet | |
from django.contrib.gis.db.models.sql.where import GeoWhereNode | |
from django.contrib.gis.db.models.sql import GeoQuery | |
from django_hstore.query import HStoreQuerySet, HStoreWhereNode | |
from django_hstore.managers import HStoreManager | |
class GeoHStoreWhereNode(GeoWhereNode, HStoreWhereNode): |
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
def email_user(user, email, template): | |
""" | |
""" | |
if 'domain' not in email: | |
email['domain'] = SITE_DOMAIN | |
c = Context({'user': user, 'email' : email}) | |
html_content = template.render(c) | |
text_content = strip_tags(html_content) | |
print 'Sending Email to {0}'.format(user) |
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
<script> | |
// Charles Lawrence - Feb 16, 2012. Free to use and modify. Please attribute back to @geuis if you find this useful | |
// Twitter Bootstrap Typeahead doesn't support remote data querying. This is an expected feature in the future. In the meantime, others have submitted patches to the core bootstrap component that allow it. | |
// The following will allow remote autocompletes *without* modifying any officially released core code. | |
// If others find ways to improve this, please share. | |
var autocomplete = $('#searchinput').typeahead() | |
.on('keyup', function(ev){ | |
ev.stopPropagation(); |
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
Deployment notes for Ubuntu Instance | |
Nginx, uwsgi, postgres, django, virtualenv stack | |
* ssh root | |
root access (need pem) | |
ssh -i whatever.pem ubuntu@ec2-*-*-*-*.compute-1.amazonaws.com | |
* secure box | |
- cut off all ports but 22 and 80 using AWS Management Console | |
- edit /etc/ssh/sshd_config ensure PasswordAuthentication no |
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
#!/usr/env python2 | |
from random import choice | |
pop = ['a', 'b', 'c',] | |
simulations = 0 | |
""" | |
while simulations < 3: | |
simulations += 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
from django.db import models | |
# http://www.djangosnippets.org/snippets/562/#c673 | |
class QuerySetManager(models.Manager): | |
# http://docs.djangoproject.com/en/dev/topics/db/managers/#using-managers-for-related-object-access | |
# Not working cause of: | |
# http://code.djangoproject.com/ticket/9643 |
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 haystack.inputs import Raw | |
>>> from haystack.query import SearchQuerySet, SQ | |
>>> sqs = SearchQuerySet().filter(content='python') | |
>>> sqs2 = SearchQuerySet().filter(SQ(content='python') | (SQ(content='python') & SQ(content=Raw('pycon^10')))) | |
>>> | |
>>> sqs.count() | |
16 | |
>>> sqs2.count() | |
16 | |
>>> |
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
cd ~ | |
sudo apt-get install unzip | |
sudo apt-get install python-software-properties -y | |
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" | |
sudo apt-get update | |
sudo apt-get install sun-java6-jre sun-java6-plugin -y | |
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.6.tar.gz -O elasticsearch.tar.gz | |
tar -xf elasticsearch.tar.gz | |
rm elasticsearch.tar.gz |
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
@property | |
def document(self): | |
user_id = self.id | |
user_document = UserDocument.objects.get(user_fk=user_id) | |
return user_document | |
User.add_to_class("document", document) |