Tunneling over SSH

As a rule, whenever I’m online I’m logged into my server back in the States. I’m also usually wireless, which we all know is beyond insecure – I’ve found it especially useful to tunnel firefox over SSH. I try my best to tunnel stuff over SSH back, and if you want to also, this is how. I’m on Linux, so this is pretty darn easy. ssh [email protected] -D 1080 If the SSH daemon runs on a different port, you’d do something like this:
Read more

Alexa Site Thumbnail And Django

So, you’ve seen how to look up thumbnails via python, but wonder how to integrate this with Django? I created a sample app to demonstrate. One thing to note about this app is it is slightly more complex than just using the previously mentioned ThumbnailUtility. For starters, the thumbnail is downloaded from Alexa onto the server. Another part is first searching if the thumbnail exists already, and if it does, serving that instead of querying Alexa. Let’s just start with some code.
Read more

Alexa Site Thumbnail with Python

For one of my sites I needed to get thumbnails, yet Alexa Site Thumbnail didn’t have any code snippets for Python. Well, no they/you do. import base64 import datetime import hmac import sha import sys import re import urllib import xml.dom.minidom AWS_ACCESS_KEY_ID = 'your-access-key-id' AWS_SECRET_ACCESS_KEY = 'your-super-secret-key' # This one is for an individual thumbnail... def create_thumbnail(site_url, img_size): def generate_timestamp(dtime): return dtime.strftime("%Y-%m-%dT%H:%M:%SZ") def generate_signature(operation, timestamp, secret_access_key): my_sha_hmac = hmac.new(secret_access_key, operation + timestamp, sha) my_b64_hmac_digest = …
Read more

Alexa Site Thumbnail with Python II

This is how I actually use Alexa Site Thumbnail, and since I’min a sharing mood, I’ll extend the code your way. In short, this takes the url and searches in STORELOC first, then any urls not already in STORELOC are retrieved and named via a slug. You need to pass two variables to either of these: blog_site.url and blot_site.slug – since I’m using Django, this is naturally how sites are returned after I filter a queryset. What I do is place the call to Alexa as high up the page as I can, and because I’ve threaded this, the page can continue to load without waiting for Alexa’s response. For instance, let’s say you have some model with cool sites, and you want to return …
Read more

Adding Search to Django

This is fairly well documented in the Django docs, so I’ll be brief. This is the the bit of search code I use in almost all of my Django sites, and it works great: def search(request): from django.db.models import Q q = request.GET.get("q", "") if q and len(q) >= 3: clause = Q(dirtword__icontains=q) \ | Q(description__icontains=q) \ | Q(tags__name__icontains=q) site_search = Dirt.objects.filter(clause).distinct() else: site_search = Dirt.objects.order_by('?')[:100] return list_detail.object_list( request = request, queryset = site_search, template_name = "dirty/search.html", template_object_name = "dirty", paginate_by = 20, extra_context = {"q" : q}, ) …
Read more

Django Syndication with Colddirt

Creating feeds in Django is freaking simple. I’ll start with an example of just updating a feed with the newest objects (for instace, newest blog posts). Similar to the forms.py way of handling our different forms, I’ve created a feeds.py to handle the feeds. from django.contrib.syndication.feeds import Feed from colddirt.dirty.models import Dirt class LatestDirts(Feed): title = "Cold Dirt" link = "/" description = "When you have dirt, you've got dirt. Right..." copyright = 'All Rights Unreserved' def items(self): return Dirt.objects.all()[:50] What this will do is query our Dirt DB and return an obj. The fields here are pretty well documented in the Django docs, …
Read more

Django Syndication with Colddirt II

Since I’ve already covered a really simple syndication example, I’ll move onto something a little more complex. Let’s say you want to offer syndication that is slightly more custom. The Django syndication docs give an example from Adrian’s Chicagocrime.org syndication of beats. I had to ponder a minute to get “custom” syndication to work, so here’s my example from start to finish. First, as usual, feeds.py class PerDirt(Feed): link = "/" copyright = 'Copyright (c) 2007, Blog Mozaic' def get_object(self, bits): from django.shortcuts import get_object_or_404 if len(bits) != 1: raise ObjectDoesNotExist my_dirt = get_object_or_404(Dirt, slug__exact=bits[0]) …
Read more

Django Newforms Usage in Colddirt

I hear many complaints and questions about newforms, but I’ve personally found it rather easy and logical to use. There are numerous ways for you to use do forms in Django, and most likely the best way to see them all is to read the docs. On the Colddirt demo site, this is how I used newforms. I’ll take the index page as an example. I’ve accessed the newforms module like so:
Read more

Simple Ajax with Django

So, the Django developers, in my opinion, are freaking smart. Instead of bundling Django with a particular library, they have added XML and JSON serialization; us humble users can choose whatever AJAX library we want. Prototype 1.5.1 has been pretty fun to work with, so I’ll kick off this demo with a really simple example. How simple? The intended goal is to have the total number of ‘dirts’ update without user intervention. Laaaammmeee. If you are a visual type of person, take a look on the Colddirt huh page. That number automatically increases without user intervention. And this is how. The process (some pseudocode) will go like this:
Read more

Solved: NO PUBKEY

I’ve received this error more than once, so I’m finally writing my notes how I solve it. W: GPG error: http://security.debian.org stable/updates Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY A70DAF536070D3A1 This really is just your standard don’t-have-the-gpg-keys error. So, get’em – take the last eight digits from the long NO_PUBKEY string that is displayed on your computer. If you are using Debian 4.0, the above key is likely correct; if you are using Ubuntu or another version of Debian, it will be wrong. (The last eight digits are used as an identifier at the keyservers). Then:
Read more