Skip to content

Instantly share code, notes, and snippets.

View allyjweir's full-sized avatar

Ally Weir allyjweir

  • GitHub Staff
  • Glasgow, Scotland
View GitHub Profile
@allyjweir
allyjweir / GUM
Created October 24, 2014 14:15
GUM Website Development
Glasgow University Magazine is Scotland's oldest student publication and is the culturally aware voice of the University of Glasgow and the West End. Our sections are Features / Politics / Culture / Style / Business & Economics / Science & Technology.
Website Development: We plan to develop a new website to launch with the first issue of Glasgow University Magazine in early December. We are looking for a creative person who has experience of website design and can work effectively independently. We have clear plans for the structure of the website but will welcome your suggestions.
Glasgow University Magazine has a circulation of 2000 and a readership of approximately 6000. It is read throughout the university and the West End of Glasgow. We have 1500 likes on Facebook and more than 1200 followers on Twitter.
All GUM positions are voluntary however we are happy to promote your work in print, on our website and on our social media platforms.
If you are interested in this opportunity, please contact ed

Keybase proof

I hereby claim:

  • I am allyjweir on github.
  • I am allyjweir (https://keybase.io/allyjweir) on keybase.
  • I have a public key whose fingerprint is 8430 6C1A 9C2A 1237 4874 8727 8EBD F026 7B20 D5B6

To claim this, I am signing this object:

#In forms.py
class WebForm(forms.Form):
url = forms.URLField(label='Link')
class Meta:
model = Datapoint
fields = ('uploaded_by', 'name', 'file', 'url', 'description', 'author', 'source', 'publish_date',)
#My current attempt in views.py
@allyjweir
allyjweir / gist:06605e49ae0cb3019920
Created January 28, 2015 10:14
autocomplete.py
import simplejson as json
from django.http import HttpResponse
from haystack.query import SearchQuerySet
def autocomplete(request):
sqs = SearchQuerySet().autocomplete(content_auto=request.GET.get('query', ''))[:5]
suggestions = [result.title for result in sqs]
# Make sure you return a JSON object, not a bare list.
# Otherwise, you could be vulnerable to an XSS attack.
the_data = json.dumps({
@allyjweir
allyjweir / gist:26ed8951e4fb3186daa2
Created January 28, 2015 11:06
Haystack autocomplete problems
#The Model
class Datapoint(models.Model):
# Relationships
owner = models.ForeignKey('users.User', related_name='%(class)s_uploader_relation')
project = models.ForeignKey('project.Project', related_name='%(class)s_project_relation')
collections = models.ManyToManyField('collection.Collection', related_name='%(class)s_collection_relation',
blank=True)
# File management
name = models.CharField(max_length=512)
@allyjweir
allyjweir / gist:a224fc08c1772633c4b1
Created February 1, 2015 10:55
Django Rest Framework and Annotator JS JSON requirements
#The serializer
class AnnotationSerializer(serializers.ModelSerializer):
tags = TagListSerializer(required=False)
class Meta:
model = Annotation
fields = ('pk', 'owner', 'datapoint', 'annotator_schema_version', 'text', 'quote', 'uri', 'range_start',
'range_end', 'range_startOffset', 'range_endOffset', 'tags')
from django.forms import widgets
from datapoint.models import Datapoint, Annotation
from rest_framework import serializers
from rest_framework.exceptions import ParseError
from tags.serializers import TagSerializer
from tags.models import Tag
from users.serializers import UserSerializer
import simplejson as json
class Annotation(models.Model):
datapoint = models.ForeignKey('datapoint.Datapoint', related_name='%(class)s_parent_datapoint_relation')
owner = models.ForeignKey('users.User', related_name='%(class)s_creator_relation')
tags = models.ManyToManyField('tags.Tag', related_name="%(class)s_tags_relation", blank=True)
# Key fields from the Annotator JSON Format: http://docs.annotatorjs.org/en/latest/annotation-format.html
annotator_schema_version = models.CharField(max_length=8, blank=True)
text = models.TextField(blank=True)
quote = models.TextField()
{
"total": 2,
"rows": [
{
"id": "2",
"annotator_schema_version": "",
"created": "2015-02-10 12:35:20.562241+00:00",
"updated": "2015-02-10 12:35:20.562248+00:00",
"text": "west, east, north",
"quote": "he song \"Black Skinhead\" by Kanye West. When it came out last year we praised the way it dealt with race and class in America in a way that was both deeply abs",
defmodule Factorial do
def of(0), do: 1
def of(n), do: n * of(n-1)
end