Jul 31, 2009

Rocketfish Bluetooth Dongle in Ubuntu

UPDATE: This does not work in Karmic as the Bluetooth settings dialog has been changed. This will still work in Jaunty if you have not yet upgraded.

I recently bought a Rocketfish Bluetooth dongle for my computer so that I can see about hooking up the Wiimotes to it. Unfortunately it didn't work out of the box, but it was detected by lsusb. Here's how to get it working.

First, see if it is detected when you plug it in. The little light should be on, and if you go into a terminal (Applications->Accessories->Terminal) and type:
lsusb
You should see a "Primax Electronics, Ltd" and/or "Broadcom Corp." (I get 3 of these) in there. If you've gotten this far, good. Otherwise it is possible that your adapter is broken, try testing it on another computer.

Second, you need to reset the device, not sure why. In the terminal type:
sudo hciconfig hci0 reset
sudo hcitool dev
This should print out a list that looks like this:
Devices:
hci0 00:02:76:17:91:42
This should make the device work.

If you go into System->Preferences->Bluetooth you should now be able to set up your Bluetooth devices. Click the "+" button, which will go through the little wizard. On the "Device search" page, wait a second while it detects the devices (theres a few little usability issues in the Bluetooth thing, supposedly the fixes are in for Karmic) and you should see your other Bluetooth device(s) pop up in the box. After that theres usually some kind of pairing system that you'll need to do, it depends on the device you're trying to connect. I tried with my cell phone and you have to enter the pairing code on your cell before it lets you connect the two.

Jul 30, 2009

Gmail password recovery

After reading this post on password recovery, it turns out that if you don't log into your secondary email address, it could expire. This is pretty obvious, however we don't really think about this very often. It also poses a security risk, since if say your old account expires, but someone else comes along and registers it, they can do a password reset on your current email account. And if they control your current email account, they pretty much control your online identity.

So if you're using Gmail, maybe it is a good idea to update your alternate email, and make sure that you can still log into it. It turns out that my alternate email was my Bishop's email, which is no longer available. The instructions for updating your alternate email are here: http://mail.google.com/support/bin/answer.py?hl=en&answer=6566

One thing I noticed is you can put your phone number in to SMS your password reset code to you. Does anybody know if this is a security risk or not?

Jul 28, 2009

Using Scala Actors and Case Classes

When I posted about actors last month I didn't really provide many code examples. That's mainly because I didn't really know a good actor library for the languages that I like to use. So I decided to dig a bit deeper into Scala to use the built-in actor library. It's pretty good!

So before I get started, I'll describe how it works. You have these classes that inherit from Actor. In these classes you define an act() method. This is similar to the run() method in the Java Thread class.
When an actor receives a message, it goes into the actor's mailbox. You can check the mailbox with the receive() method.

How are we going to represent these messages? Well, a rather convenient approach is to use a feature of Scala: case classes. These are lightweight classes which basically just have a constructor and some public attributes. Kinda like structs from C, but with a constructor and inheritance.

So for my example, I'm coding a basic simulation environment. We want this simulation to be multi-threaded, so that we can take advantage of multiple CPUs in a machine. And we've decided to use Scala actors for it. This will be an agent-based simulation, so we will obviously need an Agent class. We will also have a Simulator class which drives the simulation.

Let's start with two types of messages. For each time step, the Simulator sends an Act message to each Agent. When the agent is done processing, it sends a DoneAct message back to the Simulator saying it is done. Since the number of Agents is fixed, let's just use a counter to keep track of the finished agents.

Here is the Simulator class:
class Simulator extends Actor {
// need to override start to tell all our agents to start as well
override def start() : Actor = {
agents.foreach(agent => agent.start)
return super.start()
}

// something to add agents
def add(agent : Agent) = agents += agent

def act(){
// loop indefinitely
loop {
// check the mailbox
receive {
case Act => {
// this keeps track of how many agents we are waiting for
agents_left = agents.size

// the binary ! operator is what is used to send a message
agents.foreach(agent => agent ! Act)
}
case DoneAct = {
agents_left -= 1

// if we've gotten messages back from all agents, let's start
// the next simulation step
if (agents_left == 0)
this ! Act
}
}
}
}

var agents_left = 0
var agents = new LinkedList[Agent]()
}
Our Agent class:
class Agent(simulator : Simulator) extends Actor {
def act() {
loop {
receive {
case Act => {
// do some actions
simulator ! DoneAct
}
}
}
}
}
This class is a lot simpler, mainly because we haven't actually defined anything to do yet.

For completeness, here are the Event classes:
abstract case class Event()

case class Act() extends Event
case class DoneAct() extends Event
And a main function:
object Sim {
def main(args : Array[String]) {
var simulator = new Simulator()

// add a bunch of agents
simulator.add(new Agent(simulator))
simulator.add(new Agent(simulator))
simulator.add(new Agent(simulator))
simulator.add(new Agent(simulator))

// start the simulator, and send it an Act message
simulator.start
simulator ! Act
}
}
So this simulation is pretty basic. In fact, it's pretty useless. It doesn't actually do anything. However this gives us a framework for creating a simulation. Let's tweak the agent class a little:
abstract class Agent(simulator : Simulator) extends Actor {
def act() {
loop {
receive {
case Act => perform()
}
}
}

def perform() {
// do nothing
}
}
We can now use our Agent class as a base class for other agents. I will end this post now, however next time I will make some subclasses of Agent to actually do something.

Jul 18, 2009

Fractal Time Analysis Results

In my last post about fractals, I wrote up about how I wanted to analyze which seeds would take a long time to render and which would be fine.

The process goes like this:
real, im = -1, -1
times[IMG_SIZE][IMG_SIZE]
x, y = 0, 0

while x < IMG_SIZE
y = 0
while y < IMG_SIZE
render

times[x][y] = processing time
y++
x++

normalize times // min will be 0, max will be 255
output to bmp
So what you end up with is a greyscale image. The brighter it is, the longer it took to render.

The result is...well, amazing. Like really. See for yourself:



Does that look familiar to anyone?

I used a fairly small image size here (it was even smaller before). Problem is that rendering time is O(n2), so it takes 4 times as long when I double the size - originally I wanted to have an 800x800 image - turns out that'd take like a week for the thing to process! I might try tweaking the code to be multithreaded, that would probably half the time on my machine.

Jul 17, 2009

Penumbra

I just heard about this game called Penumbra through Slashdot (you may have seen it there too). It's a survival horror game, which is probably what you could classify System Shock and Bioshock as. Since I liked both of those games - although I didn't play System Shock all the way through because it ended up just crashing all the time - I decided to buy this one.

It's only $5 USD. No taxes, no shipping, that's it. The only catch is that you have to buy it this weekend. After you pay you get a download link, it's about 850MB.

Even better, it has native Linux support. Since I hate having to reboot to play games (it's one of the reasons I don't play many games anymore) this is a huge bonus.

I've decided that stuff like this is a much better deterrent to piracy than DRM or any of the other restrictive junk they've got out there. Since $60 is retardedly expensive for a game, why pay it when you can just download it for free? There is a bit of a guilt thing that the programmers aren't getting their pay, but $60 is more than I'm willing to pay. $5 though? That's peanuts. I'm willing to give the game a go for that cheap, even without trying the demo (which is something they have, by the way).
I'd be willing to pay up to maybe $20-30 for a game. I bought Crayon Physics which works really well under Wine, and it was about $20. Turned out to be a really interesting game.

So yeah, if you like survival horror, go out and grab this one! It's only $5!

Jul 12, 2009

The Value of Twitter

A while back I wrote a post about Twitter and how I didn't really like it. This was mainly from a personal perspective, where it was just me and my friends on Twitter and people would just tweet about random stuff.

These days however I've been using Twitter as an advertising tool for the Pirate Party of Canada and it is really working well. I tweet about a meeting or an announcement, and people retweet it, and the news gets spread really quickly. Compare this to Facebook (well Facebook now has a more Twitter-esque model on the front-page but we don't really have a Pirate Party page on the site other than the group) where you can't really broadcast a message easily to lot's of followers. Well, you can send a message to all the people in a group, but there are a lot of people that the message doesn't apply to and it's probably annoying for some people in say, Vancouver to always be receiving messages like "there's a meetup in Saint John, NB". Whereas on Twitter you can just ignore the tweet.

So in summary, Twitter is a pretty good communication tool for a one-to-many broadcast. In case you hadn't figured that one out already :)

Jul 9, 2009

Kitties and CPU Fans

A lot of us like kittens, they like to play and run around and chase things - just earlier my kitten was sitting in the screen doorway watching a squirrel, it was pretty funny.

They also like fans on computers. Things moving! Oh my god! So they stick their little claws in there trying to kill your fans. Try to keep them from doing this, the ends of their claws can splinter and while it may not hurt them very much (at least it doesn't seem to, he just keeps doing it) one thing you don't want is little bits of claw firing into your system.

Recently my computer started making a lot of noise from the fans. I figured that it was the heat, it is July after all. However I noticed that the fan on the side of my case wasn't working, and the CPU fan was working extra hard - way harder than normal.

I decided to open up and take a look. Sure enough the case fan had enough fur around the spinning part to slow it down to the stopping point, but here's what was worse - the CPU fan:


That is only about 10% dust!

Jul 7, 2009

Disable Notifications in Jaunty

For those of you like me who can't stand the new notifications in Jaunty (for me they are extremely distracting, like when a window pops up on top of what you are typing into) there is a nice little tweak to get rid of them described here.

For those who don't want to go and read it, here is the short form:
cd /usr/share/dbus-1/services
sudo mv org.freedesktop.Notifications.service org.freedesktop.Notifications.service.disabled
Then restart (I think you only need to restart X for this, so just log out and log back in again).

Jul 1, 2009

Arrr - Pirate Party of Canada

With the recent success of the Swedish Pirate Party, these kinds of parties are popping up all over the world. At the moment I am helping revive the Pirate Party of Canada which can hopefully run in an election sometime soon!

So if you are interested in protecting yourself from another C-61, join up and give us a hand!