Archive for the 'Technology Bits' Category

Algorithmic Mirror

This is a repost from my old blog from a couple years ago…

Algorithmic Mirror is an art piece using computer media. It’s not really useful in any way, but is rather meant to be interesting, thought provoking, and visually stimulating.

The setup consists of some software I wrote using Processing running in fullscreen, and a webcam. When the viewer enters the webcam’s field of view, they will see a mirror image of themselves on the screen. What makes the algorithmic mirror unique is the way in which the image is displayed.

Over a thousand particles are in constant motion on the screen. When a person or object enters the camera’s field of view, the particles arrange themselves in order to show a vague silhouette version of the image. The result is like a sketch in motion.

Algorithmic Mirror was on display at the National Exhibition Centre in Swift Current, SK from February 19 to March 20, 2005.

ScreenshotScreenshot
ScreenshotArt in the Family Exhibition
Art in the Family ExhibitionArt in the Family Exhibition

Download

Requires Mac OS X 10.4 or higher and an iSight camera
AlgorithmicMirror1.1.zip (1.5Mb, Application + Source Code)

No comments

Push email on Symbian S60 smartphones

There is a lot of discussion about using IMAP Idle with the Symbian Series 60 smart phones but nobody seems to have really gotten it working well. I have, and here are my experiences…

My setup

Configuring basic email

Since this phone was purchased unlocked and unbranded, none of Fido’s settings were pre-configured. I called them and they sent me a couple SMSs with all of the settings I would need. For email, I created a new access point at Menu -> Settings -> Phone Settings -> Connection -> Access Points for internet.fido.ca.

I was able to quite easily get basic email sending and receiving by filling out the usual settings such as server, login and password in: Messaging -> Options -> Settings -> Email. It’s painful to type in all those settings using a numeric keypad though.

My mail server requires SSL (actually, TLS) for encrypted connections, and uses a certificate from GoDaddy. The phone complained about it being an untrusted certificate until I installed GoDaddy’s root certificate on the phone. To do this:

  1. Download gd-class2-root.cer
  2. It still isn’t in the right format, so run the following command on it in terminal:
    openssl x509 -in gd-class2-root.cer -out cert.cer -outform DER
  3. Use bluetooth to send cert.cer to the phone. When you open it, it will ask you to install it.

Of course, if your mail server doesn’t use SSL/TLS, then you don’t really need to do this, although you should probably think about switching to SSL/TLS ’cause the Internet is a scary place and someone’s probably spying on you.

Enabling IMAP Idle

The Cyrus server supports Idle by default. To get the phone to take advantage of it, you have to make a couple adjustments:

  • Menu -> Settings -> Phone Settings -> Connection -> Packet Data, set to “When available.”
  • Messaging -> Options -> Settings -> Email -> Mailboxes -> (yours) -> Automatic retrieval:
    • Email notifications: disabled
    • Email retrieval: enabled
    • Retrieval interval: 15 minutes

Is it working?

IMAP Idle keeps a persistent connection alive, so the most convenient way to verify that it’s working is to look at your phone’s network status icons.

gsmstatus.png

If you have the solid arrows, there is a connection and chances are good that IMAP Idle is working. It doesn’t matter what connection type you have, but a UMTS one will likely suck your battery dry pretty quickly.

Of course, the only real way to test is to send yourself an email. Your phone should get it in about 30 seconds or less.

Caveats

The email client software feels a little buggy on the S60 phones. Occasionally it will stop checking automatically. To jump start it again, you need to go into Messaging -> Options -> Settings -> Email -> Mailboxes -> (yours) -> Automatic retrieval, and then exit them all. Somehow just visiting this menu reminds it that it should be checking your email.

Your carrier is probably also dropping connections that are open for more than about 20 minutes with no activity. (At least that’s what mine seems to be doing). Luckily, if you receive enough emails, your connection may stay active enough to keep the connection alive for hours at a time. If it does drop, your phone should re-establish it when it is next scheduled to check email (every 15 minutes).

Overall

It’s not perfect, but it’s definitely a workable solution if you want instant email notification on your mobile without using proprietary setups like ActiveSync or BES.

I’m interested in trying out Zimbra’s S60 client now…

No comments

GLUI 2.3 Framework for Mac OS X

GLUI FrameworkPreviously I published a quick tutorial on how to get GLUI installed on Mac OS X. Enough people were still having problems getting it to play nicely with XCode that I decided to just package it up as a nice little framework.

This is the first time I’ve made a framework for OS X, so tell me if it works or if it makes your computer go boom.

Download

8 comments

GLUI, GLUT, and Mac OS X… Oh my!

I needed GLUI to do an assignment but I found that it wouldn’t compile on Mac OS X. Here’s what I did to make it work. Hopefully someone will find this with google and it will save them some time. I used GLUI 2.35 and Mac OS X 10.4.8.

Update: My original solution didn’t work on my new Intel-based MacBook Pro, so I’ve updated the instructions below so that they should work for either PowerPC or Intel macs.

Update #2: I got so fed up with this crap that I just made a GLUI Framework which works much nicer with XCode. If you still want it as a libglui.a file, then read on…

First, you have XCode installed, right?

Open the Makefile and change the line:

LIBGL   = -lGLU -lGL

to

LIBGL   = -framework OpenGL

and

LIBGLUT   = -L/usr/X11R6/lib -lglut

to

LIBGLUT   = -L/usr/X11R6/lib -framework GLUT

This assumes you have GLUT.framework installed which you probably do. It should be in /System/Library/Frameworks/. If not, you can download it and install it yourself.

Then build like usual…

pb:~/glui-2.35/src lcyca$ make
mkdir -p bin
mkdir -p lib
g++ -I./ -I./include -I/usr/X11R6/include -c glui_string.cpp
g++ -I./ -I./include -I/usr/X11R6/include -c glui.cpp
...
... (lots of output)

Then you can try out the included examples. Since the mac version of GLUT doesn’t use X11, you can run them straight from Terminal.app.

pb:~/glui-2.35/src lcyca$ cd bin
pb:~/glui-2.35/src/bin lcyca$ ./example5

If you want to actually install it, copy lib/libglui.a to /usr/local/lib/ and include/GL/glui.h to /usr/local/include/GL/, because software that requires it is most likely to be looking for it there.

pb:~/glui-2.35/src lcyca$ mkdir /usr/local/lib
pb:~/glui-2.35/src lcyca$ cp lib/libglui.a /usr/local/lib/
pb:~/glui-2.35/src lcyca$ mkdir /usr/local/include
pb:~/glui-2.35/src lcyca$ cp include/GL/glui.h /usr/local/include/
4 comments

Dueling Percussion

Dueling Percussion is another Max/MSP Patch that I created for an electroacoustic music course instructed by Arne Eigenfeldt at SFU. (previously)

The idea is simple. Imagine having two snare drummers facing each other. One plays a bar-long rhythm, then the other responds by playing a similar but slightly embellished rhythm. They trade back and forth, continually attempting to outdo the other. Now imagine that one of the snare drummers is a computer. This MaxMSP patch listens (through a mic) to a rhythm being played, quantizes it, changes it slightly, then plays it back a bar later.

For this to work, though, both the human and the computer have to agree to a tempo, so this patch incorporates a tap-tempo metronome. To start, the human does a count-off by clicking sticks four times. The computer interprets the tempo and starts a metronome.

Dueling Percussion Screenshot

Download

duelingpercussion.zip

Setup

  1. Press reset a few times to make sure everything’s in a known state. Max patches can be weird in this regard.
  2. Set BOTH noteout objects to use your midi interface

Options

  1. Set the velocities for the metronome note. There’s one for downbeat and one for the others. They’re located at the bottom of the metronome.
  2. Set the note numbers for the metronome note and instrument note. I use a click for the metronome and a snare for the instrument.
  3. Set the minvel for bonk low enough to hear your instrument but high enough to not pick up stray noises. (This may not be easy)

Usage

  1. Hit reset again, just to be sure
  2. Click (or tap the mic) 4 times to start the metronome
  3. When the “listening” lights are on, play a rhythm
  4. Wait a bar as it plays back a similar rhythm in response
  5. Try enabling “Quantize” “Subdivide” or “Omit”
No comments

Cellular Automata Composition

Cellular Automata is a discreet mathematic model related to fractals. I’ve chosen to use a one-dimensional cellular automata simulator as the basis for a process composition using Max/MSP. This was originally an assignment for an electroacoustic music course instructed by Arne Eigenfeldt at SFU.

Cellular Automata Screenshot

Download

Cellular_Automata_Composition.zip

How to use it

  1. Make sure the midi objects are configured to play through quicktime or another instrument
  2. Turn on the metro object in the gray panel
  3. Start the simulation by clicking one of the large checkboxes in the red panel which represent cells
  4. As the simulation continues, you can continue to interact with it by turning cells on or off manually.

How it works

At every time step, each cell takes on a new value based on the values that it and its two neighbours had at the previous time step. The value is determined by the “celaut” object which I also created. This particular version of celaut uses the standard “Rule 150″ of cellular automata.

Each cell is mapped to a midi note which are divided among three channels. The programs of each of these channels change periodically to a new random value.

More info

More information about the theory of cellular automata is at:
http://en.wikipedia.org/wiki/Cellular_autonoma

Another example of its use in music is at:
http://www-128.ibm.com/developerworks/java/library/j-camusic/

No comments

Cardiris vCard 2.1 AppleScripts

I needed to use Cardiris on a mac to scan business cards and then easily import them into Mozilla Thunderbird. Cardiris can generate vCard3.0 files, but Thunderbird only accepts 2.1 (as of this writing). With this script, you can use Cardiris to generate a vCard2.1 file, and then automatically have it emailed to your email address for easy importing into Thunderbird.

Requirements

This script has been tested with Cardiris 3.0 on Mac OS X 10.3 and 10.4. The vCards it generates have been shown to import flawlessly into Mozilla Thunderbird 1.0.2 (20050404).

You must be able to send email through the sendmail program. In Mac OS X 10.3, this ability is disabled by default, but you can re-enable it using PostfixEnabler. 10.4 Tiger seems to work right out of the box.

Download

Cardiris vCard AppleScripts

Installation

  • Open “Email vCard2.1X” in a text editor and change the email address to the one you want to mail vCards to. It is listed twice in the file. Make sure and change it in BOTH places.
  • Save the file
  • Go and find your “Cardiris 3.0″ program (probably in Application folder)
  • Right click (or ctrl-click) on the program and choose “Show Package Contents”
  • Navigate to Contents/SharedSupport/Cardiris/BC
  • Place the two AppleScripts in that folder
  • Close everything & Launch Cardiris. The scripts will show up along side the other export options. You’re ready to rock.

FAQ

Q: When a try to use the script, why does the program crash?
A: The most likely cause of this is that while editing the script, you accidentally converted the file’s line breaks. The scripts MUST have macintosh line breaks.

Q: Can I write my own scripts?
A: Go ahead. Have a look at these scripts as well as the other export scripts that are included with Cardiris. Notice that the file is divided into two halves. The first half is executed for the first business card, and the second half executed for subsequent cards. Under most circumstances you’ll want the same thing in both halves.

License

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

The full text of the GNU General Public License is available at:
http://www.gnu.org/licenses/gpl.txt

No comments

HOWTO: Multirouting with Linux

Through the magic of routing, the Internet can supposedly withstand intermittent outages, congestion, and other nasties. This is because, in theory, any network has multiple paths to any other network—sort of like highways between cities. By having multiple connections to the Internet from different providers, a network can distribute the load over all of them, choosing the best available route for each packet. This is called Multihoming, and the protocol that makes possible is BGP. Problem is, the network needs an AS number for BGP to work, and no consumer-targetted broadband connection supplies one.

Typical small network configuration

Most networks that use regular broadband as their Internet connection have the following configuration. The service provider provides a DSL or Cable modem, and hooks it up to one computer to be designated the router. They generally give one or two IP addresses which may be static but are more likely dynamically allocated with DHCP. This router, which is often a computer but could also be a special-purpose appliance from Linksys or similar, sits between the network and the Internet connection. It usually runs a DHCP server on the internal network, assigning private IP addresses to all of the computers on the network. It also usually does NAT so that the computers on the Internal network can access the Internet. This works pretty well, but it’s all a bit of a hack in order to get around the problem of IPv4 address exhaustion. With NAT, the entire internal network hides behind the router, so while a remote server thinks it’s dealing with the router, the router knows to pass communication along to the correct internal computer.

Why multiple Internet connections are difficult

When BGP is used to route over multiple connections, each packet can go on along a different route. However, since we’re using regular consumer-grade Internet connections, each connection will have a different a IP address, and so as far as the rest of the Internet is concerned, each of them are completely unrelated. They might as well be hooked to completely separate networks. There is no way for a remote station to know that if one packet comes from one IP, and the next packet comes from a different IP, that they are both part of the same session and should be reassembled as such.

The solution hack

There is a way to get similar functionality by using multiple broadband connections without an AS number or any other cooperation from the service providers. It’s generally referred to as “Multirouting.”

Since it’s fundamentally impossible to route each packet individually when NAT is involved, the best that we can do is to route each session individually. This way, we ensure that all packets from a given session use the same connection. The drawback is that we are restricted to coarser control over how data is routed.

Pros

  • Redundancy: If one connection goes down, the others can pick up the slack.
  • Load balancing: Gain speed by spreading the bandwidth burden over all connections

Cons

  • Once a session is assigned to a link, it cannot be moved to another link. For example, if a user starts downloading a big file, and the link to which he is assigned fails half-way through, his session will terminate rather than being automatically moved to another link.
  • There is no automatic way of distributing traffic based on the current available capacity of each link. The best we can do is round-robin.
  • There is no automatic way of detecting a dead link. However, a simple script can send a ping across each link periodically and then reconfigure the routes to exclude a dead link (and re-enable it when it comes back up)

How to do it with Linux

I’ve successfully made this work using 4 different connections, including DSL, cable, and even a fiber connection that had an extra NAT layer upstream. This method is extremely flexible, but can be difficult to get set up correctly. Following is a contrived example using two connections to illustrate the method.

We’re going to assume we’ve got the following interfaces set up in linux.

Interface Connected To IP Address Subnet Mask Gateway
eth0 Internal LAN 192.168.0.1 255.255.255.0 N/A
eth1 DSL Modem 142.154.64.7 255.255.255.0 142.154.64.1
eth2 Cable Modem 24.19.12.45 255.255.255.0 24.19.12.1

1. Configure network interfaces

We’ll assume you’ve got all of your network interfaces configured and working. The command ifconfig -a should list all of them, and they should all have an IP address. You should be able to ping the gateway of each of your Internet connections (142.154.64.1 and 24.19.12.1 in our example), as well as any other machine on your internal network (192.168.0.x).

2. Configure NAT

We’ll also assume you’ve got NAT (aka IP Masquerading) working on each of the external interfaces (eth1 and eth2). For help with this step, see the IP Masquerade HOWTO.

At this point, your default gateway should be the gateway of one of your internet connections. From your router, you should be able to access the Internet, and computers on your internal network should be able to do the same. To make sure both connections are working, switch the default gateway to that of the other Internet connection like this:

# default via 24.19.12.1 dev eth2

Where 24.19.12.1 is the new gateway and eth2 is the Interface connected to that Internet connection. Once again, test that your router and internal computers can access the Internet. When testing, traceroute is your friend to see which connection is actually being used.

3. Create the new routing tables

Each interface is going to need its own routing table in addition to the main routing table.

Open the file /etc/iproute2/rt_tables in a text editor and add a line to define the names of your new routing tables. You’re going to add one for each Internet connection. Each line starts with a number, then a tab, and then a name. Ours looks like this:

1	dsl_internet
2	cable_internet

4. Populate the new routing tables

Both routing tables need to know about all network interfaces, including the loopback. Each routing table should have its connection’s associated gateway as its default route. You can populate them by running commands like these…

# ip route add 127.0.0.0/8 dev lo table dsl_internet
# ip route add 192.168.0.0/24 dev eth0 table dsl_internet
# ip route add 142.154.64.0/24 dev eth1 src 142.154.64.7
	table dsl_internet
# ip route add 24.19.12.0/24 dev eth2 src 24.19.12.45
	table dsl_internet
# ip route add default via 142.154.64.1 table dsl_internet

# ip route add 127.0.0.0/8 dev lo table cable_internet
# ip route add 192.168.0.0/24 dev eth0 table cable_internet
# ip route add 142.154.64.0/24 dev eth1 src 142.154.64.7
	table cable_internet
# ip route add 24.19.12.0/24 dev eth2 src 24.19.12.45
	table cable_internet
# ip route add default via 24.19.12.1 table cable_internet

Omit the src address for eth0 in order to permit DNAT (port forwarding).

5. Add rules

Now that we’ve created two new routing tables, we have to define the rules that will make use of them. This is especially important for DNAT (port forwarding). If a request comes in on 142.154.64.7, we definitely want to make sure that the reply goes out over the same connection, for example. These rules direct those packets to the appropriate routing tables, and can be added with these commands…

# ip rule add from 142.154.64.7 table dsl_internet
# ip rule add from 24.19.12.45 table cable_internet

6. Set up the main routing table

The main routing table will probably be mostly set up already. There should be an entry for each interface. To be sure, run these commands but ignore errors if they already exist.

# ip route add 192.168.0.0/24 dev eth0
# ip route add 142.154.64.0/24 dev eth1 src 142.154.64.7
# ip route add 24.19.12.0/24 dev eth2 src 24.19.12.45

You can also use ip route show all to see the entire main routing table.

Now, remove the previous default route from the main routing table like so…

# ip route del default

And add the new one that will achieve the round robin effect over all gateways… (all on one line)

# ip route add default scope global
	nexthop via 142.154.64.1 dev eth1 weight 1
	nexthop via 24.19.12.1 dev eth2 weight 1

Done. but…

You’re pretty much done. You should be able to access the Internet from both your router computer and your internal computers. Go to whatismyipaddress.com on all of your computers and you should see that some have one of your IPs, and some have the other. On successive requests, you can expect it to flip flop between the two.

7. Make DNS work

For your internal network, you’ll likely want to run your own caching DNS server. All of your computers will query it, and it will query one or more of your ISPs’ DNS servers, caching the result.

However, when your DNS server contacts one your ISPs’ DNS servers, it’s going to have to go through the router. You’re going to want to make sure that when it contacts an ISP’s DNS server, it uses that ISP’s connection to do so. You’ll need to set up rules to ensure that specific types of packets go over a specific connection.

Let’s say the DNS server from our cable Internet provider is is 24.19.100.1. We want any packet destined for that IP to use our cable connection and not our DSL connection. This rule does just that…

# ip rule add to 24.19.100.1 table cable_internet

It says that any packet that is going to 24.19.100.1 should use the cable_internet routing table instead of the default.

Similarly, if the DNS server from our DSL provider is 142.154.61.100

# ip rule add to 142.154.61.100 table dsl_internet

Now we can tell our DNS server to forward requests to either DNS server, and our router will ensure that those requests will go out over the correct connection.

8. Make more rules

You can create more rules for each IP that you want to force down a certain connection. Some examples:

  • You forward mail through the SMTP server of one or both of your ISPs. If said SMPT server only relays from hosts on its network, you’re going to need that ISP’s connection.
  • If one of your Internet connections is NAT’ed upstream, and they give you an IP of 10.x.x.x or something, you’re going to want to make sure that all IPs destined for a 10.0.0.0/8 address go through that connection.

9. BONUS: Failover Script

Now that you have this set up, you probably want it to work even when one of your connections goes down. Right now, if one of the connections goes down, half of the requests will fail. I wrote a script that pings the gateways every minute or so, and reconfigures the routing tables to take out unresponsive gateways until they come back. My script is ugly so I’ll leave it to to write your own.

Additional Resources

No comments