Blog

Archive for the ‘Web’ Category

ActionScript 3 Maze Generator

Sunday, September 13th, 2009

This is something that’s been sitting on my hard drive for a very long time now, an AS3 implementation of the Depth First Search algorithm, used here to generate mazes. This was originally created as a personal project, but it also ended up being applicable to a class. On both counts, the final product turned out to be pretty cool.

mikemaze_screenshot

In addition to generating mazes, it also allows you to spawn mice to mindlessly scamper through the maze. Although the same algorithm to generate the maze could be used to solve it, this would’ve been pretty boring to look at. The mice, when faced with a decision, simply randomly pick a direction to go. This simple solving algorithm also allows you to spawn a few hundred mice without any real speed loss, which makes it slightly more exciting to watch.

The only real problem with this implementation as it stands is that the mazes it makes aren’t very tough. The incorrect paths usually hit a dead end pretty quickly, making it a lot easier to backtrack and continue.

The download containing everything is attached below, released under a 2 clause BSD license.

Download SWF and source

JSONTamer: XUL-based JSON visualizer

Monday, July 27th, 2009

JSONTamer is a simple Firefox extension that adds a new sidebar, and a new menu item under Tools. It allows the user to paste in any valid JSON string, as defined by JSON.org. When a string is entered, and the user hits Display, a tree is generated, showing the resulting object.

jsontamer_screenshot_thumb

Current planned features include a version that can be used with the most excellent Komodo IDE, and a set of tools to allow creation of objects from scratch and manipulating existing objects.

A git repository will be available in the near future. For now, JSONTamer is only tested with Firefox 3.0 and above, though may work on older versions.

Download JSONTamer 0.1

Invoking the Firebug debugger from a script

Tuesday, June 9th, 2009

If you’re tired of digging through the Firebug scripts tab to find and insert breakpoints, I was told today about a little-known trick in Firebug that allows you to add breakpoints directly in the source JS file itself.

By issuing the ‘debugger’ statement anywhere in your code, Firebug will halt execution of the script at that location, popping up it’s debugger and highlighting the line where it was used. Example:

    <body>
        Debugging:
            <script type="text/javascript">
            for (var i=0; i<100; i++) {
                if (i === 50) {
                    debugger;
                }
                document.write(i+"<br>");
            }
            </script>
        Page end!
    </body>

Unfortunately, this feature seems to be specific to Firebug only, although the Chrome Javascript Debugger (CTRL + SHIFT + L) allows you to use the “break” command with an optional conditional. There does not seem to be any similar functionality in IE8, Opera, and Safari, although I would be glad to hear if it did.

QUAKE LIVE Twitter IRC Bot

Friday, March 13th, 2009

On #quakelive on QuakeNet, there is a bot named QLTwitter that spits out text everytime the QUAKE LIVE Twitter account is updated. I’ve gotten a few requests for the code, so figure I’d publicly release it.

It has a couple of dependencies, all of which are available in Debian packages. Specifically, it requires POE, its IRC client module, and JSON modules. It is basic, but it works, and can easily be changed to broadcast tweets from any other account.

use warnings;
use strict;

use POE;
use POE::Component::IRC;
use JSON;
use LWP::Simple;
use Time::HiRes qw(time);

my ($irc) = POE::Component::IRC->spawn();
my $currStatus = '';
my $updateDelay = 120;
sub CHANNEL { "#quakelive" }

POE::Session->create(
    inline_states => {
       _start     => \&bot_start,
       irc_001    => \&on_connect,
       tick       => \&checkTweet
    },
);

sub bot_start {
    $irc->call(register => "all");
    $irc->call(connect =>
          { Nick => 'QLTwitter',
            Username => 'QLTwitter',
            Ircname  => 'QLTwitterBot by sponge',
            Server   => 'us.quakenet.org',
            Port     => '6667',
          }
    );
}

sub on_connect {
	$irc->call(privmsg => 'Q@CServe.quakenet.org', 'AUTH sponge ------');
	$irc->call(join => CHANNEL);
	$irc->call(privmsg => CHANNEL, 'QLTwitterBot is LARGE and IN CHARGE!');
	$_[KERNEL]->delay( tick => $updateDelay);
	checkTweet();
}

sub checkTweet {
	eval {
		my $json = get 'http://twitter.com/statuses/user_timeline/quakelive.json';
		my @statuses = from_json($json);
		my $curr = $statuses[0][0]->{'text'};
		if ($currStatus ne $curr) {
			$irc->call(privmsg => CHANNEL, "New QUAKE LIVE Twitter update: $curr");
			$currStatus = $curr;
		}
	};
	eval { $_[KERNEL]->delay( tick => $updateDelay); }
}

$poe_kernel->run();
exit 0;

New design online!

Thursday, January 29th, 2009

Finished up the couple of remaining bits, and my new design is now officially up! The blog at the moment is still unskinned, but I’ll probably be fixing that in the near future. The new site should hopefully be compatible, or at least working, in most major browsers, so any feedback on broken things would be greatly appreciated.

iPhone Web Applications

Wednesday, December 10th, 2008

RIT offer a class “Web Application Development for iPhone” and looking to fill my schedule, I’ve been taking it this quarter. Despite my skepticism at the hardware and Apple’s treatment of the platform in general, there is a lot of cool stuff there.

First, arguably the biggest feature, is Dashcode. Although it suffers from poor support and being Mac OS X only (attempts to run it in a virtual machine thus far have failed) the idea and execution is great. It is essentially a visual application builder, not unlike the old FrontPage, and the form builders in Visual Studio, etc. It does a reasonably well job of hiding the web part in web design, coming with pre-built components that match the iPhone look. Output will obviously only work on the iPhone/iPod Touch; not even Safari can run output.

Being able to target only one browser allows you to use much of the cutting edge features. CSS3, HTML5, and the more advanced JS features are all available, along with GPU-accelerated transitions. It is very much a look into the future of what all browsers will eventually support, except with a viable platform available today for immediate development.

Although the mobile web has a lot of hype and buzzwords associated with it, there is some substance to be found. It is pretty exciting to see what the next-generation of browsers will bring as a new standard. With technologies like Adobe Alchemy bringing C++ to Flash, there are certainly exciting times ahead for web applications.

Wheel of Friends

Tuesday, September 9th, 2008

This is something I produced last year, as a part of the Open Publishing Lab so unfortunately the source isn’t available as of yet, but it’s still worth nothing.

The below is a visualization of the results of a social networking game we ran at a festival last May. Hit the link for all the details, but the gist of the game is people trade barcode stickers with people who share at least one interest out of a pool of 8 or so. Those people who connect are scanned in via a normal scanner, an application rips the barcodes and stuffs them into a database. Once those links in the database are made, it’s a bit hard to visualize it all. This is where my part came in: visualising all the people via a wheel.

The wheel was created in PHP, using a little trig, and a lot of tweaking. The output can accomdate a virtually unlimited amount of people and links. Plus, it’s pretty to look at. The wheel has gotten a lot of mileage (no pun intended) on a lot of the promotional material for the OPL.

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);
}
}