Friday, October 30, 2009

Moving...

So Blogger is a utilitarian platform at best. I started posting here mostly because it's free, but I knew it wouldn't suffice as something professional-looking.

I'm going to start teaching Python at ITT tech in December, and I've been looking for an optimal way to host more content and sharpen my Python skills at the same time. Enter Google App Engine: It's pay per usage, so I can host the application(s) indefinitely and not pay until I get a significant number of hits. And by significant, I mean like 5 million or so. So until I'm that popular, I can host rich web applications and content for free. Good deal for something that I'm looking to generate any income.

I found Bloog, a "RESTful blog app for GAE." Plus it's on GitHub and it's simple enough that I can easily modify it -- the perfect environment to start playing with Python again.

So eventually I'll move to my new Blog on GAE once I get it up an running. It should look super awesome (well, at least better than this) and let me customize to my heart's content.

Wednesday, October 28, 2009

Darken Google and other UserContent CSS tricks

So Stylish is a popular FireFox extension that allows you to change the way certain websites look.  Being a minimalist, I'm generally happy with the way websites are presented by default (once ads are removed, of course) and don't want to install another FireFox extension.

There are, however, a couple rare sites that I do have the desire to change.  The main culprit being Google.  More specifically, Google is too white (no that's not racist.)  Luckily, I can darken Google (that is, _real_ Google, not the Google Dark site.  Mostly because if I want to use Google's new search sandbox, Caffeine, the customized Google frontends can't do that.

Getting to the point, I can modify the CSS for any site I want using FireFox's UserContent.css file.  Here's a CSS snippet to darken Google's search results pages:

@-moz-document url-prefix(http://www.google.com/search),
  url-prefix(http://www2.sandbox.google.com) {

 body, #gsr {
  background-color: #111 !important;
  color: #ccc !important;
 }

 #ssb, #tbd, #bsf, #mbEnd, #tads {
  background-color: #222 !important
 }

 #mbEnd { border-left-color: transparent !important }

 a, .link { color: #7bC !important }
}


Here's a screenshot of the result:

And here's another handy trick: You can also remove those huge iframe ads from Google Reader in the same way:
@-moz-document url-prefix(https://www.google.com/reader/),
   url-prefix(http://www.google.com/reader/) {

  #viewer-container iframe {
   display: none !important
  }
}

You can find more information on customizing FireFox here and here.

Monday, October 19, 2009

The new XML: High Performance Serializers

While JSON has been regarded for some time as a good alternative to XML, binary data serializers such as Thrift and Protocol Buffers have more recently been gaining traction for their performance and compact output. Just the other day I came across Avro (now part of the Hadoop project) which puts itself as a direct competitor to Thrift and ProtoBufs.  Avro looks neat, but there are a few other data marshallers worth looking at too.

Thursday, October 8, 2009

Upload to S3 with Groovy

So, uploading to S3 is not always as simple as it should be. Here's a completely self-contained Groovy script that can upload files to your S3 bucket, plus provide a signed link to access the uploaded file.

The script uses Groovy Grab macro to download the JetS3t library which does the heavy lifting.

#!/opt/groovy/bin/groovy
/* Script to manipulate S3 objects.  
 * @author Tom Nichols
 * @see http://blog.thomnichols.org
 * @see http://jets3t.s3.amazonaws.com/api/org/jets3t/service/impl/rest/httpclient/RestS3Service.html
 */

import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials
import org.jets3t.service.model.*

bucketName =       'CHANGEME'
accessKey =        'CHANGEME'
secretKey =        'CHANGEME'
folder =           'CHANGEME' // optional folder name before the file

@Grab(group='net.java.dev.jets3t',module='jets3t',version='[0.6.1,)')
public putS3() {}

def login = new AWSCredentials( accessKey, secretKey )
def expiry = new GregorianCalendar( 2011,0,1 ).time
def s3 = new RestS3Service( login ) 
def bucket = new S3Bucket( bucketName )

args.each { fileName ->
  def key = "$folder/$fileName"
//  s3.deleteObject bucketName, key 
  def s3obj = new S3Object( bucket, new File( fileName ) )
  s3obj.key = key 
  println "\nUploading $fileName to $bucketName/$key"
  s3obj = s3.putObject( bucket, s3obj )
  
  def link = s3.createSignedGetUrl( bucketName, key, login, expiry, false )
  println "$fileName : $link"
} 
Just change the bucket name, key and folder at the top of the script, or optionally you could pull them in via system properties or environment variables. Enjoy.