Blog

Archive for July, 2008

Site Updates

Wednesday, July 30th, 2008

After a couple of years of letting my resume fall into disarray, I’ve finally updated it with all the projects I’ve been apart of these past couple of years. I’m getting ready to hopefully graduate college this year, so if anyone actually reading this has any connections that may be looking, please do let me know!

autoftp.py

Saturday, July 26th, 2008

This has been something that’s been sitting on my PC for a while, and has actually been used pretty often unlike every other script I’ve ever published. In its most basic form, it’s a Python script that connects to an FTP address, and compares two directories. It will then upload any new files that are on the client to the FTP server.

The usefulness of the script for me occurs when I run it on my Windows Mobile phone, running PythonCE. The Python script is set up to filter out only .jpg files. This end effect is, when combined with the built-in camera, and a data connection, one can easily upload images from their camera phone to their website.

# Copyright (c) 2008, Mike Rubits
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY Mike Rubits "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Mike Rubits BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os, re
from ftplib import FTP
import time

# CONFIGURATION
if os.name is "ce":
   picPath = "/My Documents/My Pictures/"
else:
   picPath = "."

ftpAddress = "ftp.example.com"
ftpUsername = "Username"
ftpPassword = "Password"
ftpPasv = False
ftpPath = "/httpdocs/photos"

# END CONFIGURATION

def ParseRemoteFiles(line):
   match = re.search("(\w+)\.jpg",line)
   if match is None:
      return None
   else:
      remoteListing.append( match.group() )
      return None

# Find Local Files
remoteListing = list()
localListing = os.listdir(picPath)

#Find Remote Files
ftp = FTP(ftpAddress)
print ftp.login(ftpUsername,ftpPassword)
print ftp.cwd(ftpPath)
ftp.set_pasv(ftpPasv)
print ftp.retrlines('LIST',ParseRemoteFiles)

newFiles = 0
filesToUpload = list()
for localFile in localListing:
   f = localFile in remoteListing
   if f is False:
      newFiles = newFiles + 1
      print "found new image " + localFile
      filesToUpload.append(localFile)

print "found " + str(newFiles) + " new images to upload"

progress = 0
for uploadFile in filesToUpload:
   file = open(picPath + uploadFile,'rb')
   progress = progress + 1
   print "uploading img (" + str(progress) + "/" + str(newFiles) + ")"
   print ftp.storbinary("STOR " + uploadFile, file)

XML Gallery

Thursday, July 24th, 2008

I’ve recently been starting to use Git as an SCM, and despite the fact it’s an utter pain to use (131 uniquely named binaries, but that’s something best left for other places to discuss) I’ve put up one of my recent projects that I spent a little time on: my efforts to create a flat-file based photo gallery.

Sure, it’s probably not as relevant today as it was 5 years ago with services like Flickr and Photobucket used just about everywhere, however there’s still something to be said for self-hosting.

The application itself is pretty simple. Point it at your photo directory, and when visited in the browser, will generate an XML index of the directory. The XSLT transforms it into XHTML, which is viewed by your browser. As far as I know, taking this approach for a photo gallery is pretty unique, and makes templating a snap. It has potential, just needs to be finished.

Right now, it all basically “works” although I don’t have a sample to show. It is really quite hideous at the moment, and is missing a few things. I’m also not entirely happy with the format of the XML. It’s more public for the sake of getting it out there, rather than for public consumption.

Without further ado, you can view the source on the web in Gitweb, hosted by l3ib, a front for one of many IRC channels I frequent (I created the front page, if anyone actually cares). The code itself has no license at the moment, but the final version will likely be BSD licensed if I ever get that far. Enjoy!

SMS Notification for Pidgin

Saturday, July 5th, 2008

After a couple hours of figuring out Perl, Pidgin’s API, and a host of other tiny annoyances, I’ve thrown together a little Perl plugin that should work on Pidgin and Finch. It’s extremely simple: when you receive a message while marked as away, it will send an email via sendmail to a specific address. As almost all cell providers have some sort of SMS to email gateway, this gives you the effect of having all messages, regardless of protocol, forwarded to your phone while you’re away. You can’t respond, however something like WebPidgin could come in handy (although I personally just SSH in and reattach screen)

Code attached below. This version, at least, is licensed under the WTFPL. I may revisit this one day and make it a lot easier to use. (Note: I’m not a Perl coder at all, so this may not be pretty, but then again, what Perl IS pretty?)

use Purple;

%PLUGIN_INFO = (
perl_api_version => 2,
name => "SMS Notify",
version => "0.1",
summary => "Dispatches an email, generally to a phone, when a message is received while away.",
description => "None",
author => "Mike Rubits <sponge\@d8d.org>",
url => "http://d8d.org",
load => "plugin_load",
unload => "plugin_unload",
);

sub plugin_init {
return %PLUGIN_INFO;
}

sub plugin_load {
$plugin = shift;
$data = "";
$conversation_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, \&im_received, $data);
Purple::Debug::info("smsnotify", "SMS Notify Loaded\n");
}

sub plugin_unload {
Purple::Debug::info("smsnotify", "SMS Notify Unloaded\n");
}

sub im_received {
my ($account, $sender, $message, $conv, $flags) = @_;
$message =~ s/<[^<>]+>//g;
my $status = $account->get_active_status();
my $statusName = $status->get_name();
if ($statusName eq "Away") {
my $sendmail = "/usr/sbin/sendmail -t";
my $to = "To: email\@address.com\n";
my $from = "From: pidgin\@address.com\n";
open(SENDMAIL, "|$sendmail") or Purple::Debug::info("smsnotify", "Cannot open sendmail\n");
print SENDMAIL $to;
print SENDMAIL $from;
print "\n\n";
print SENDMAIL $message;
close(SENDMAIL);
}
}

Panoramic Photography

Wednesday, July 2nd, 2008

I’ve finally gotten around and uploaded some of my old panorama shots in the Other section. In addition to a few standard panoramas, I’ve also created a 360 degree Quicktime VR version of one of the photos, and two shots that were rendered via the PC version of Quake Wars, and converted into Flash panoramas. Check them out if you’re into looking at other people’s photographs!