Skip to content

Instantly share code, notes, and snippets.

@evz
evz / oauth_decorator.py
Created May 10, 2012 17:12
Terrace under the hood, part 3
import vimeo
from django.conf import settings
from django.http import HttpResponseRedirect
...
def require_vimeo_auth(view):
def protected_view(request, *args, **kwargs):
request.session['next'] = request.path
if 'vimeo_access_token' in request.session:
vimeo_access_token = request.session['vimeo_access_token']
@evz
evz / audio_search.py
Created May 10, 2012 17:22
Terrace under the hood, part 4
results = AudioFile.objects.filter(Q(recorded__lte=upload_to),Q(recorded__gte=upload_from)).filter(Q(title__icontains=keyword)|Q(description__icontains=keyword)|Q(tags__tag_name__in=tags))
results = set(results) # Make sure there are no duplicates
@evz
evz / client-side-datatable.js
Created May 10, 2012 17:31
Terrace under the hood, part 5
init_posts= function(){
// Setup the table that the data goes in to
var wp_posts = '<table id=\"info\" class=\"shadowize\">';
wp_posts += '<thead><tr>';
wp_posts += '<th>Post ID</th>';
wp_posts += '<th>Title</th>';
wp_posts += '<th>Author</th>';
wp_posts += '<th>Created</th>';
wp_posts += '<th>Post Status</th>';
wp_posts += '<th>View</th>';
@evz
evz / gallery-code.html
Created May 10, 2012 17:38
Terrace under the hood, part 6
@evz
evz / models.py
Created May 14, 2012 14:32
SRP Maps: Under the Hood
class SRPLocality(models.Model):
locality = models.CharField(primary_key=True, max_length=255)
cluster = models.CharField(max_length=100, null=True)
region = models.CharField(max_length=25, null=True)
nsa = models.CharField(max_length=15, null=True)
date_modified = models.DateTimeField(null=True)
stats = DictField(null=True)
file_id = ListField(max_length=25)
loaded = models.BooleanField()
objects = MongoDBManager()
@evz
evz / README.md
Created October 7, 2012 21:43
S3 Publisher for Hyde (static site generator written in Python)

How to use

  • Add the s3.py file to your project. As an example, put it inside a folder called publishers.
  • The folder where s3.py resides must be a Python package, so add an empty __init__.py file to that folder also.
  • Add the following configuration to your site.yaml and modify it as needed:
publisher:
    s3:
 type: publishers.s3.S3 # here, publishers is the folder where the s3.py file was placed
@evz
evz / s3_update.py
Last active December 12, 2015 10:19
Loop over and apply a content-disposition header to PDFs in an S3 bucket
from boto.s3.connection import S3Connection
from boto.s3.key import Key
def doit(bucket_name, file_type):
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
bucket = conn.get_bucket(bucket_name)
for k in bucket.list():
if k.name.lower().endswith('.%s' % file_type):
print ('Updating: %s' % k.name)
k = k.copy(k.bucket.name, k.name, {'Content-Disposition':'attachment', 'Content-Type': 'application/pdf'}, preserve_acl=True)
@evz
evz / recode
Last active May 11, 2020 11:17
Re encode all files in a directory tree. (requires recode)
# Find encoding
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} file -bi {}
# Re-encode
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} recode ISO-8859-1..UTF-8 {}
@evz
evz / 2007-10-24.json
Last active December 17, 2015 05:09
Chicago Crime vs. Weather: Under the hood.
{
"weather": {
"FAHR_MIN": 42.980000000000004,
"CELSIUS_MIN": 6.1,
"CELSIUS_MAX": 12.8,
"FAHR_MAX": 55.040000000000006
},
"meta": {
"total": {
"key": "total",
@evz
evz / json_query.py
Last active December 17, 2015 22:59
A class based method of accessing and running basic queries against JSON files stored on a filesystem
import os
import json
from datetime import datetime
# first a super stupid exception to use
class QueryError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)