arthur.wiebe Where a keyboard takes the form of an idea

4Apr/120

How to Handle Incoming Attachments on Google App Engine

I just finished writing an app on Google App Engine in Python that receives incoming email that may or may not have an attachment and came across a little quirk that I want to share.

According to the App Engine documentation, when receiving email, the attachments attribute will have a value of tuples for each attachment, or it may be empty.
So according to that documentation I iterated the attachments attribute for all incoming emails. Turns out, when using the SDK development server for testing, I was getting this error:

AttributeError: 'InboundEmailMessage' object has no attribute 'attachments'

My code was very simple, "for filename, filecontents in message.attachments:"

Well here is some code that works:

            # handle attachments
            if hasattr(message, 'attachments'):
                for filename, filecontents in message.attachments:
                    a = model.Attachment()
                    a.filename = filename
                    a.contents = filecontents.decode()
                    a.put()

And that solved my problem. I had to use the hasattr method to check to see if the attachments attribute existed.

The second problem is the documentation does not tell you to use the decode function. If you try to save the attachment into a blob in the datastore, it will tell you it is expecting a str object and error out if you do not use the .decode() method. So make sure you remember to use it as well as you're dealing with binary data here.

Enjoy your coding!

29Feb/120

How to Install mod_browserid on Ubuntu Server

I've been looking for a good authentication module for Apache where I would not need to manage a local database of users, and yet it would be able to allow only a specified list of users. I wanted a Google Apps authentication module, but the next best thing I found was mod_browserid which uses a newer service called BrowserID.

There is no package available for Ubuntu server, so here are some instructions to get started with the neat little module for Apache.

First, download a copy of yajl v2 at  http://lloyd.github.com/yajl/
I downloaded version 2.0.1

Next install some required packages:

apt-get install ruby-dev ruby cmake

Now from inside the yajl source directory, run these commands:

./configure
make
make install

Next let's install some packages needed for mod_browserid.

apt-get install libcurl3-dev apache2-prefork-dev

Now inside the mod_browserid folder edit Makefile
Change the second line so that it looks like this:

MY_APXS=/usr/bin/apxs2

Now run make and install:

make
make install

And that's it! You should now be able to follow the documentation available at https://github.com/mozilla/mod_browserid

Filed under: Technical No Comments
30Jan/120

ClearOS Webconfig SSL Error

I had a Clearbox 300 motherboard replaced via an RMA, and when it came back I had a problem. When attempting to access webconfig from my laptop it would come up with an SSL error and there was no way to get around it.

Thanks to some searching I found this solution that worked:

# SSH into the ClearOS system and run this command:
rm /usr/webconfig/conf/server.*

That will delete the certificate and private key. Then restart webconfig using this command:

/etc/init.d/webconfig restart

Restarting webconfig will automatically regenerate the cert and private key.

Note that using webconfig from the console to delete and recreate the certificate, does not work. The reason is the private key is likely bad.

Hope this helps someone out there one day.

29Dec/111

Tip: Error Connecting to MySQL Socket on Localhost

I am doing development on my Mac (running Mac OS X 10.7 (Lion)) and I've installed MySQL 64-bit from mysql.com.

So I'm writing an application, and get to the point of testing my first MySQL query from the app. And guess what! If fails with this message:

PHP Warning:  PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...library/Zend/Db/Adapter/Pdo/Abstract.php on line 129

So I'm racking my brain, as the MySQL server is running just fine. I can connect to it by executing "/usr/local/mysql/bin/mysql -u root" from a Terminal.

The solution!

You are probably connecting to the MySQL service using "localhost". Change that to "127.0.0.1". Basically what's happened is if you use localhost PDO will want to connect via socket. If you use an IP address PDO will use the TCP/IP layer to connect to MySQL.

Otherwise you can change the path to the socket, but I find it much easier to use TCP/IP, especially for development. Not to mention our production servers use TCP for the MySQL connections as well.

Hope this tip helps someone coming across the same thing. It probably happens often for people doing development on a Mac.

29Nov/110

Macbook Pro – No Low Battery Warning

I have a Macbook Pro 15" which is the late 2008 model. It's been having an issue for some time now, at least a few weeks. And this issue seems to be new as a result of my upgrade to Mac OS X Lion (OS X 10.7). I'm not sure if it's related to the 10.7.1 or 10.7.2 updates or not.

Either way the issue is when the battery is low, instead of prompting saying your battery is low, please plug it in, there is no warning at all. It just goes right into sleep mode. Fortunately the amazing thing is nothing is lost, everything is saved. Even if you're copying files to a USB drive, as soon as you plug it in to power, and wake it from sleep mode the data starts copying again.

Anyway, the solution! The solution is in this screenshot.

The simple solution is to open System Preferences (which can be done from the Apple menu on the top left) then open Energy Saver. And then click on Restore Defaults. As soon as I restored defaults when the battery got low, I once again received the warning, which I'm sure will save a lot of frustration going forward!

Hope this helps someone out there!

1Feb/111

LTSP 5.2 and Ubuntu 10.04 – Sound without a Sound Card

A little tip for anyone struggling with the same issue.

I am running LTSP with Ubuntu on VMware ESXi 4.1 and as you may know it does not have the ability to create a sound card device for the virtual machine.
Not sure if that's the only issue, but none of my thin clients were getting audio.

So here's what I had to do and it worked without a hitch:

Install alsaplayer-esd on the LTSP server:

sudo apt-get install alsaplayer-esd

Also make sure in your lts.conf you have Sound set to True.

Hope this helps someone else on the big wide internet!

Tagged as: , , 1 Comment
20Nov/100

Settlements are the Greatest Thing that’s ever Happened to the Middle East

I do want to state a few facts that you're never going to hear on CNN.
What actually happened when the Jewish people started settling the lands of Judea, Samaria and Gaza. The average Arab income tripled--so did their birth rate. The average Arab income in Gaza grew 20 fold. 2,500 factories were built. Seven universities were established. And the life expectancy almost doubled, jumping from 40 to 70.
Are the settlements the problem? The settlements are the greatest thing that's ever happened to the Middle East. -- Jeremy Gimpel

31Mar/100

“Turning Jerusalem into a Jewish City”

  • Jerusalem was first settled in 3500 BCE and known as Rusalimum according to Egyptian writings.
  • In 1003 BCE King David established Jerusalem as the capital of the kingdom of Israel.
  • In 164 BCE the Maccabee's recaptured Jerusalem and restored the temple.
  • Jerusalem is mentioned in 767 versus of the Bible.

........
Muhammad was born in 570 CE. and Islam didn't come until around 620.

...............

2010 CE I  am reading some of the headlines and come across this again for like the 100th time:

Israel's objective is to "turn Jerusalem into a Jewish city," the Hezbollah leader said.

OK, there's three possible responses I could have:

  1. Laugh out loud. In fact laugh so hard I start to cry.
  2. Become angry with the disgusting nature of these lies, and where they come from.
  3. Understand what the bigger picture is, reach a logical understanding, and move on.

I don't fully understand the bigger picture yet. And cannot come to any logical conclusion. Except for the fact that there is a spiritual war going on. I know who will win, but this is just another reminder of the propaganda being spread across the media by Islamic idealist. And the ideal world of Islam consists of many millions of dead Christians and Jews.

What is my message? Find the truth, things are never as they seem.

19Feb/100

SSH Server And “Permission denied (publickey).”

This drove me up a wall, yet it's so simple, and so easy to overlook.

If you ever setup a server with SSH public key authentication, and you get the following error:

Permission denied (publickey).

Make sure you do the following:

  • Make sure the permissions of the .ssh folder are 0700
  • Make sure the permissions of the authorized_keys file are 0600
  • Make sure the user owns the .ssh folder and contents (normally that's the case but just to make sure)

For example from the home folder of the user you are trying to setup, use these commands:

sudo chown -R username:username /home/username/.ssh
sudo chmod 0700 /home/username/.ssh
sudo chmod 0600 /home/username/.ssh/authorized_keys

Especially if you're on Amazon EC2 which uses public key authentication by default, this is very important when setting up new users. And with modern Linux distros like Ubuntu this is very easy.

Happy secure terminalling!

11Feb/102

2010 Winter Games Live Streaming Requires Silverlight

Just when I thought the internet was headed to good pasture, I check out what internet streaming is going on for the 2010 Olympic Winter games here in Vancouver. What shall I find? But low and behold.. And I mean low. They are streaming using Microsoft Silverlight.

Until now I have refused to install it, I'll probably end up installing it just for this and uninstalling it right after. But hey, they are streaming in 720p HD which is not bad. And I believe it's even using H.264 so not a Microsoft specific codec. But still, I just don't like it! This is bad for the open web, and bad for the non-Microsoft web. I know very well what Microsoft's plan was for the internet. Thanks for the likes of Mozilla, Google, and Apple their plans have been thwarted. I just hope it continues.

1Feb/100

The family was telephoned and urged to leave

The destroyed Abu Askar family house was used to store Grad rockets. The family was telephoned and urged to leave before the house was shelled. - The Goldstoning of Israel.

I feel compelled to write this short post, hopefully to help spread the information for anyone who even thinks about believing the goldstone report. Those who wrote the report had made their decision before even beginning the inquiry.

It's anti-Semitic, and intentionally sides with the terrorists.

Going back to the first sentence in the post, what other army in the world, let alone the small pocket of the world called the middle east, would call their target allowing them to escape, before launching the attack? Something Israel has done countless times in an mind boggling effort to save civilian lives.

"The Goldstone Report was born in bias and matured into a full-fledged miscarriage of justice."

Who Else Thinks So?

Those are just a few.

25Jan/100

Did You Know? – Episode #2

I've managed to get a recording together for a second episode of the Did You Know podcast. This time we have Isaak along for the ride, and he brings some more interesting facts about the human body, and more.

On a side note, please forgive the production quality. I was experimenting a bit too much with this episode. First both of us were recording live using the same microphone so editing turned out to be difficult, and then I was working with new software which I still am not used to. Anyway, enjoy!

[Download iTunes File]