Input Managers and the Leopard Firewall

I’d figured out some time ago that an Input Manager or two that I was using was interfering to some extent with the MacOS Leopard Firewall.

When you have the firewall in “Set access for specific services and applications” mode, and you start an application which tries to open a TCP or UDP port, then you get a message like:

openPorts.png

When you click one of the buttons, an entry is added to the preferences list:

firewallprefs.png

However, the application’s executable code is checked by the system to see that it is the same application as was run when this choice was approved. So, if you have something like an Input Manager, which alters the executable code as it is run, then you have this message appear every time you launch.

This was a real problem for me, using Inquisitor with Safari. Sure, it’s a great little tool to get the pre-search results in the browser before you press enter, but I decided it wasn’t worth the annoyance of having to click Allow each time I start up the application.

So, if you are having issues with the Firewall dialog appearing each time you start an application, and you haven’t installed a new version, consider removing any unneeded Input Mangers. You’ll probably need to remove them all to get it to stop, but that might just be worth it.

Naked Mole Rat

I swear this looks like something I have seen before. I just can’t put my penis on it…

image001.jpg

Using Dynamic DNS as (partial) authentication.

One thing that you can do with Apache is limit access to particular domains. For instance, you can have a process running on a Server that handles internal requests as well as external requests, and have the internal site never exposed to the outside internet. This can be done using the apache Allow and Deny directives.

But, sometimes I need to work remotely, and still have access to the intranet data, such as the company wiki and bugzilla database. But I don’t know which IP addresses I will be using, and whilst I can open it up to allow a range of IP addresses in, this means that someone else could see the data.

So, set up a dynamic DNS for your laptop, and put in an Allow for this DNS entry. Then, you just have to update the address whenever you want to access it - or even better, update it whenever your IP address changes. That means, even if someone comes on to the same IP address after you, as long as you have a new IP address, they won’t be able to get in.

This does point out the flaw in the system: if you log off, and don’t log back on (or don’t renew your IP address), then that person can access your intranet data. So, you should not use this as a sole means of authentication. Instead, use http authentication, or preferably, some other method of protecting access. But as a lightweight (ie, no VPN) system, this looks pretty good. It should even work if you are behind a firewall that prevents VPN access. And adding a new user requires a bit of work - creating a new Dynamic Hostname and adding this to the httpd.conf file - or wherever your server config data is stored.

It strikes me you could use sub-domains to do this, too, and have userxx.company.dyndns.org, or whatever. Then an allow of company.dyndns.org should allow anyone using a subdomain. I don’t know how you can do subdomains with DynDNS, but it may be possible with some other system. (Or, if you run your own DNS, you could come up with a method of doing it there, which gives you more flexibility. However, if you have a DNS, you can probably stretch to a VPN too).

Chess, just for fun.

We had a homework exercise the other day, that went something like this:

Consider the design a class, ChessBoard, to represent a chess board (an 8 by 8 grid of squares) where each square can have a single chess piece on it (pawn, rook, knight, bishop, king or queen) which is either black or white. Discuss the design of move methods for each type of piece. The methods should have parameters which specify where the piece currently is and where it is being moved to. Each method should check if the move is valid (the correct type of piece is on the square, the move is to a square that is on the board and it does not contain a piece of the same colour) - a proper implementation would also check that none of the other rules of chess are being violated.

Give declarations and initializations for each of the instance variables the class (ChessBoard) would need and declare any other classes necessary. Add a method to ChessBoard that will place all the pawns of a particular colour on the board. White pawns occupy the entire second row (1 pawn on each square of the second row) of the board while black pawns occupy the seventh row of the board.

Complete the implementation of the moveKnight method below and the class Position (you could just use java.awt.Point). Knights move 2 square either horizontally or vertically (along rows or columns) and then 1 square to the left or right.

boolean moveKnight(Position currentPosition, Position newPosition) { ...

Now, that was just not enough for me. So I designed and implemented, just for fun, a framework to handle all of the pieces, and all of their possible moves. I went a bit full-on: my classes are listed below.

  • ChessGame
  • ChessBoard
  • Location (each square is a Location, this makes it easy to do stuff later on)
  • Team
  • Move
  • Piece (abstract)
  • King, Queen, Bishop, Knight, Rook, Pawn

Now, most of this is fairly easy: using OO is golden for something like this, where there are stacks of cases where inheritance means you can implement it once, and this is fine for most cases, but where not you can just override it once or twice. And having this level of abstraction in each case has also been quite handy. For instance, by having a Move class, which has a Piece, and two Locations (start and finish), it’s a simple thing for me to keep a record of the game (LinkedList of Moves), and calculate things, like whether a particular piece was the last to move (for en passant).

There are actually only a couple of tricky things to worry about with Chess. Most of these are related only to the King: you have to check before each move to see that the move won’t put your team’s king into check, and if you are already in check, then ensure that the move you make takes you out of check. Otherwise, it’s a fairly simple algorithm. To set up the rules, not to actually play.

As it turns out, the Pawn is actually the hardest piece to code for, since it moves in a variety of different ways in different contexts. It’s harder to code for the normal behaviour (ignoring en passant) than it is to handle castling.

The only thing I haven’t implemented yet (apart from being able to drag and drop or click on pieces) is whether the game is in checkmate. I’m not quite sure how to do this, just yet.

Anyway, here is a screenshot of my simple chess game. It’s the biggest thing I’ve written in Java so far, and doing all of the UI code, was, as expected, a whole lot more painful than Cocoa.

Picture 1.png

I still don’t have my head around the Drag and Drop stuff to do with Java, nor really at this stage have I figured out how to make each Location clickable, and then use this to execute moves. I think I’ll make it so that a click checks to see if a piece is of the right team, and present in the chosen location, and then highlights that square so you can see what piece you are moving. Then clicking on a second Location will move that piece to there, if it is a valid move.

I guess after that, I just need to make the intelligence to play…just kidding. That might wait till I am studying AI, next semester…

Copycatting

Did you ever notice that The Gossip • Standing In The Way Of Control is a ripoff of Loverboy * Turn Me Loose?

Now, these links were obtained from the iTunes Australian Store, by right-clicking on them. But they don’t work for me when I try to use them to get back to those tracks…odd.

xkcd vs Calvin

electric_skateboard_double_comic.png

From xkcd - A webcomic of romance, sarcasm, math, and language - By Randall Munroe

Ah, this combines my two great loves… python and Calvin and Hobbes.

When are you starting your assignment...?

Had a funny thing happen today. Tomorrow we have an assignment due for the one topic that is actually somewhat challenging: Programming Language Concepts. The task is to write a QuickSort program in c-like Java, and implement it using both a recursive and an iterative design. There is an extension task due next week, to do the same for a MergeSort program.

I’ve been working on this since about the second week. It hasn’t consumed all of my time, but it has taken a significant number of hours of coding time, testing time, and finally several hours of run-time to gather average data. This is even before writing up the assignment, although I’ve probably done way more work than was required in this aspect.

So, when it a lab session today (which I had done before-hand, something that few students in any of my topics appear to have grasped is probably the best way to work…), one of the students mentioned he hadn’t started his yet. This had myself and another student, who have bounced several ideas and problems off one another, aghast with jaw-dropping splendour (!).

I know he was for real, as an hour or so later, in a different lab room, he was asking another student for assistance with his development. This other student was someone who had done the topic in the past, and was giving him some assistance with his algorithm development. But I don’t possibly see how he can come close to finishing a program, let alone the other stuff, by 5pm tomorrow.

It occurs to me that I was like this other student, a long time ago. No I wasn’t, I wouldn’t have even bothered.

Oh dear, I’ve turned into an annoying mature-age student who gets work done ahead of time, and answers all of the questions in class.

Revision Control as timing guide

I use Mercurial for all of my new work. It’s a great distributed revision control system. I even use it for all of my Uni programming, and other work. It allows me to easy switch back to previous checkpoints if I need to get them marked off, for instance.

The work we have been doing in one of my topics is still way to easy, although it is getting a bit better. But using Mercurial allows me to see how long each of the tasks took me to do.

Not sure how long the first Checkpoint took, as I didn’t have a commit to do then. But the next one took exactly 15 mins. The third one took 14 minutes, and the final one took 24 minutes. That last one was a fair bit of refactoring though, so that wasn’t too bad.

As for the bonus checkpoint? That can wait until morning.

Changing UNIX shell without actually changing it

Very rarely, I encounter a computer system I have to use regularly, but I don’t have superuser status on. Notably, at Uni, I have access to a SunOS system, where I actually have to use it from time to time. Most of the time this is just via ssh, but sometimes it’s a physical login to a SunRay workstation.

I much prefer bash over other shells, not because it is necessarily better, but that it is just the one I use most of the time. I’ve got some nice systems to help me out, like using a different colour for the user@host string on each machine, so I can easily see which machine the current ssh session is actually logged into.

However, at Uni there are lots of restrictions. We can run /usr/bin/bash, but we can’t change our default shell to it. In fact, we can’t change our default shell at all, which is kinda dumb. I’ve tried all sorts of tricks, but I just can’t do it.

The next step is to have your .login, or whatever, run the shell you want. For me, this is safe-ish, since tcsh (the current default shell) executes the contents of .login, but bash doesn’t. If you are using one shell that uses a particular login or profile file, and you want to change to another which uses the same file, you might struggle, or get stuck in an infinite loop. Which is probably worse.

Just having /usr/bin/bash -login in your .login file will then cause bash to run, and execute the contents of your .profile: without the -login it won’t execute the contents of said file. But what about when you exit the bash shell, using Ctrl-D, or exit, or logout, or whatever?

If you put a logout after the /usr/bin/bash -login line will cause the original shell to logout immediately after leaving the bash shell. Which is exactly what we want.

Now, all I need to do is figure out how to get rid of the line that says : tcsh: using dumb terminal settings.

That one’s too easy. Use xterm instead of xterm-color in the Settings➞Advanced area of the Terminal Preferences:

xterm-color.png

zsync

zsync is a file transfer program. It allows you to download a file from a remote server, where you have a copy of an older version of the file on your computer already. zsync downloads only the new parts of the file.

From zsync

Noted for future reference.