jump to navigation

New Camera… Tons of pics May 26, 2007

Posted by sdpurtill in : Life , add a comment

James and I were tired of not having any pictures of all the places and adventures we go on… So we just said screw it and went to Best Buy and bought a camera. It’s the Canon PowerShot SD1000, and it is awesome!

So now we’re taking pictures of everything we do and everywhere we go. And all my pictures go straight to Facebook.

Pictures from the Giants game last night

Have a great weekend!

A Year of Blogging May 14, 2007

Posted by sdpurtill in : Blogging , 1 comment so far

I began my blog on May 12th, 2006, so this post is two days late. Reason being I was up in Tahoe for Nate Pina’s bachelor party (getting married in 6 more days!)

Let’s reminisce on a full year of blogging for a second. Blogging has done a few things for me so far.

1) Help me become a better writer
I can articulate my thoughts much better because I write on a regular basis. The more you write, the easier it is to write, the faster you write, blah blah blah (I’m tired from the bachelor party last night, don’t feel like being articulate tonight).

2) Proved to myself that I can do something for a whole year straight and not give up
I really wanted to see if I could actually stick to something for a year straight, and I was able to. Sure, there were weeks here and there where I didn’t blog, but I never went for more than two weeks (when I was developing for ClassOwl) without a post. But I actually did it! Yay!

3) Helped me stay in touch with my readers
When I say readers, I mean my loyal readers — Bubbie & Grandpa. Aunt Martha deserves a mention here too. But everyone else reads it really sporadically — which I completely am OK with, my voice carries no weight… yet.

4) Helped me stay in touch with my family
Sometimes it is sooo hard for me to get up and walk outside of my bedroom to say hi to the earthlings I call my siblings. And also those… creatures… that happen to come around the house every now and then, my parents. Ok this one is totally a joke.

5) Helped me overcome writer’s block for school papers
Sometimes when I’m doing homework, I really can’t think of what to write. 99% of the time this is due to the fact that the essays that they make you write in high school are absolutely PATHETIC. I would never encounter writer’s block if I was writing a paper on something interesting. Maybe comparing JavaScript with ActionScript, or even a research paper on why Python developers are exponentially smarter than Java developers. Something like that would cure me, but no, we have to write papers on our “civic responsibility”. Heh heh heh, don’t want to rant anymore.

6) I can BS everything so much better
Every paper I write for school now I can completely BS with paragraphs that go on and on about nothing, yet my teachers always write comments on my papers on how they “enjoy” my writing. Too bad I was minimizing the OpenOffice Writer window every 30 seconds and writing code for ClassOwl ;)

To sum it all up: yes, it’s been worth it. Blogging is here to stay for me.

And so is the FREE FLOW OF INFORMATION!

I just added a book to my book list that I keep on my blog. I’ve actually been able to read a lot more than I thought I was able to in the last year, and it hasn’t been too hard. Hmm, I guess I’m starting to get older or something :(

I must be out of touch with reality May 8, 2007

Posted by sdpurtill in : High School, Classowl , add a comment

I learned something today: email is the new snail mail for my generation. When I first built ClassOwl, I honestly thought that kids would check their email daily. It’s just… logical to me to check my email every day. Even if I didn’t have a BlackBerry with every email sent to it, I would still check my email 3-4 times a day (I did before I had the phone). But today, when a bunch of invitations were sent out, I got an intense reality check.

Kids don’t check their email.

It is almost absurd to me how a human being could not check their email. I suppose something like MySpace or Facebook messages could be really replacing the “age-old” email, right? I would have to agree that the new Facebook Inbox could possibly replace all past electronic communication (save instant messaging) with your circle of friends. But beyond interacting with your friends, there is no purpose for the Facebook and MySpace messaging architecture. This is where you check your email.

And maybe that’s where my reality check comes in. Teenagers obviously don’t care about much beyond their circle of friends, and this is understandable. It also makes the 30.4% California High School dropout rate much more understandable to me (source). Teenagers spend more time trying to be “accepted” and making a large group of friends than ever before, thanks the Social Networking phenomona.

Understandable, yes. But is this right? Should the only thing teenagers care about in high school be their circle of friends? Maybe kids should start thinking about something more important.

Their future.

Django and S3 - integrating May 7, 2007

Posted by sdpurtill in : Python, Django , 7comments

This was so much easier than I had anticipated. There are three things you need to do to get S3 up and running.

#1) Sign up on Amazon S3 to get the secret keys that you need (there are two of them). Don’t want to spend time talking about this because it’s a Google search away.

#2) Download the S3 library that Amazon gives out. Beautiful code in there.

#3) Set up your models so that you can store keys in them. I store some extra data just to make retrieval faster, content-type and name (original filename) because I plan on making it look like they are downloading it from my site in the future. Here is my exact code that took me about an hour to come up with (super super bare right now, will be writing more later on tonight/in the coming days)

site_s3.py:

import S3
import time
import sys
from django.conf import settings
AWS_ACCESS_KEY_ID = 'YOUR-KEY-HERE'
AWS_SECRET_ACCESS_KEY = 'YOUR-KEY-HERE'
# I declare this in my settings file so I can have a local bucket for testing and one for the server
BUCKET_NAME = settings.BUCKET_NAME
conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
generator = S3.QueryStringAuthGenerator(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
def save_s3_data(key, data, content_type):
  conn.put(
    BUCKET_NAME,
    key,
    S3.S3Object(data),
    { 'x-amz-acl': 'public-read' , 'Content-Type': content_type }
  )
  return key
def delete_s3_data(key):
  return conn.delete(BUCKET_NAME, key)
def get_s3_url(key):
  return generator.make_bare_url(BUCKET_NAME, key)

MODEL:

from mysite.amazon import site_s3
class MediaFile(models.Model):
  name = models.CharField(maxlength=200, blank=False)
  key = models.CharField(maxlength=100, blank=False)
  content_type = models.CharField(maxlength=100, blank=False)
  upload_date = models.DateTimeField(auto_now_add=True)
  active = models.BooleanField(default=True)
  def _get_file_url(self):
    return site_s3.get_s3_url(self.key)
  url = property(_get_file_url)

VIEW:

# this is extremely simple for example, I've cut out all validation (I do it in my view, too much for this post though)
copied_data = request.POST.copy()
if 'upload' in request.FILES:
  copied_data.update(request.FILES)
if 'upload' in copied_data:
  content_type = copied_data['upload'].get('content-type')
  file = copied_data['upload']['content']
  key = '%s-%s' % (request.user.id, ''.join(copied_data['upload']['filename'].split(' ')))
  copied_data['key'] = key
# save it to S3
  site_s3.save_s3_data(key, file, content_type)
if data['key']:
  d = MediaFile()
  d.name = data['upload']['filename']
  d.content_type = data['upload'].get('content-type')
  d.key = data['key']
  d.save()

and finally…

TEMPLATE:

{% if assignment.attachment %} <a href="{{ assignment.attachment.url }}">Grab It</a> {% endif %}

Whew! So let’s review that third step real quick.

In the file site_s3.py, I defined three methods. The first one saves the data to the S3 servers, and I invoke it in my view when uploading a document and makes it publicly viewable. The second one deletes an object if you tell it the key. I haven’t used this yet, don’t know why I included it haha, but it works. The third one retrieves a bare URL so that users can easily download the file.

In my model, I define a class MediaFile, so I can use a ForeignKey from any other model to this one so it can just store and retrieve all the URLs that I could ever want.

In my view, basically what I do is check if I have the file named ‘upload’ in the request, and if it exists, copy it into the request.POST data, which is copied_data. I also put the key in copied_data so I can retrieve it anywhere using copied_data[’key’]. This is probably stupid, but whatever, I’m just getting this going right now. I then save all the data to the database and right there is where I’d link ‘m’ to some other model as a ForeignKey. In this instance, I saved it to the FK of the model Assignment.

In my template, I just did a quick check to see if the attachment (MediaFile FK) existed, and if it did, render a link for someone to download the file. The variable {{ assignment.attachment.url }} gets the URL because url is a property in the MediaFile model.

And it all works PERFECTLY.

Thank God for Amazon. I love you guys ;).

Django - Find list of emails from a comma separated string May 6, 2007

Posted by sdpurtill in : Python, Django , add a comment

I need to start posting more code. Here’s something I just did real quick.


from django.utils.html import simple_email_re
if request.POST['invite_list']:
  post_list = request.POST['invite_list']
  email_list = post_list.split(',')
  list = []
  for e in email_list:
    email = e.strip()
    if simple_email_re.match(email):
      list.append(simple_email_re.match(email).group(0))
  return list

Where post_list is something like “foo@foobar.com, somebody@whatever.com, jimmy@django.com” etc.

This will clean out that list just in case your user put in bad emails.

Okthanksbye

Thank You Amazon May 4, 2007

Posted by sdpurtill in : Classowl , 2comments

I just wanted to write a little bit about the most amazing web service of all time. It enables startups scale from nothing to millions of users without ever having to worry about one of the biggest startup problems in the past - SERVERS. Yes, I am talking about the Amazon Simple Storage Service. With Amazon’s S3 service, web applications can store an almost infinite amount of data that users upload.

Amazon, thank you. Jeff Bezos, you are truly a life/startup saver.