New webserver
October 5th, 2007I am currently testing wordpress on a new domain, check it out.
http://www.thomaslorentsen.com
However, this url will still work. Once I am happy with this new server, i point this address to the new one
I am currently testing wordpress on a new domain, check it out.
http://www.thomaslorentsen.com
However, this url will still work. Once I am happy with this new server, i point this address to the new one
I got bored and wrote a script to start my music when I get home and stop it when i leave. Heres quick guide to how i did it.
Problem
Want to enter house with music playing, but not leave the music playing all day.
Waiting for lifts may mean waiting outside, whack my music loud enough to hear from outside (poor neighbors
) but when people come, too far to reach the computer.
How I use to do it
Tell amarok to stop after such and such songs
What you may need:
You do not require a “social” life, if you do not go outside, you could use this script to switch to dramatic music when your phone dies or warn you that some one has entered the area who has bluetooth.
I used HCITool, which is a command line bluetooth program for linux, to scan for my device. Using “HCITool | grep noobtron, I can determine by the output if I am here or not or at least bluetooth is switched on.
The Script
The purpose of the script is to run, gets the results from running hcitool. Also checks the current state if the current state is different to the new state (hcitool returning different result) then change the state and do something.
So, if I am at home, the script will see my phone, check if my phone was there on the last scan, if not it will start the music. If it notices I was already home on the last scan it does not need to start the music. If I am not at home, it will stop the music on all cases.
If there was a problem scanning, the program will do nothing, sometimes hcitool decides to not work every now and then. This should be fine as the next scan it usually works but if you do something such as switch off bluetooth, then it wont work.
By the way, when you do want to stop the music, maybe you like to sleep with your music off, this script wont restart playing your music until you press play. Why? Because it keeps a log of the previous state it was in, if it was in “your at home” state it does not tell the amarok to play the music. However if you leave the house and come back the script will start the music normally.
I punched in a script in a few minutes and this is what I came out with:
* warning, messy code *
========= btswitcher.py =========
#!/usr/bin/python
import sys, os
# Runs a command, quits on errors
def run(command):
process = os.popen3(command)
err = process[2].readlines()
if len(err) > 0:
print “quitting”
print command, err
sys.exit(0)
return process[1].readlines()
# scans for mobile
def scan():
return run(”hcitool scan | grep noobtron”)
# returns the previous state either “True” or “False”
def checkprevstate():
return run(”tail -1 /home/tom/bin/state.log”)
# turns music off
def switchoff():
run(”/usr/kde/3.5/bin/dcop –user tom –all-sessions amarok player stop 2> /dev/null”)
print “switched off”
# turns music on
def switchon():
run(”/usr/kde/3.5/bin/dcop –user tom –all-sessions amarok player play 2>/dev/null”)
print “switched on”
# If the switch is in the true or false state
def getSwitch(state):
return state[0] == “True”
# main script
def main():
# checks for phone
scanned = scan()
mobile = “”
for s in scanned:
if s.find(”") > 1:
mobile = “im here”
# checks current state
state = checkprevstate()
if state == None:
run(”touch /home/tom/bin/state.log”)
state = [”False”]
if len(state) >= 1:
state[0] = state[0].strip()
else:
state = [”False”]
state = getSwitch(state)
print state,
# determines what to do with my music
if len(mobile) > 0:
if not state:
switchon()
state = not state
else:
if True:
switchoff()
state = not state
print “->”, state
run(”echo %s >> /home/tom/bin/state.log” % state)
if __name__ == “__main__”:
main()
========================
Cron Jobs
Using cron jobs I can run the script every minute.
* * * * * /home/tom/bin/btswitcher.py
Conclusion
So when I get home, my music now switches on. When I leave, my music switches off. This saves me like 1 second of my life on every time I have to adventure into the outside work. Pretty handy when I can not reach far enough to switch my music on or off.
This script might not be too helpful in a large house or one with thick walls, but you probably want the music to play somewhere else. This could be solved with more then one bluetooth node to find you and possibly play music in the room your in.
PS: please excuse the obvious spelling mistakes
I programmed an exciting new game called Crane Game. At the moment it is a very simple game providing hours of fun for the hardcore gamer.
When you start the game, you have a crane which you can control the speed and direction. So you can move it up down left and right. This is done by the directional keys

You can pick up the create by using the magnet which is switched on and off using the space bar. If you release the create it will fall to the ground again. The create will stick to the crane so you can move it.

Moving the create to the exit will complete the game!

Such a simple game however, adding obstacles will make this game much harder and more exciting. This will be done in the next version.
Heres some source code, its a bit messy but it shows how it works.
CraneGame.java
I got bored and wanted to make something so I made a slider game. It not completed but in theory you should be able to slide the bits of the image into the space, chances are you played this game before. At the moment it just replaces the bank square with the clicked square. This game provides intense game play with many hours of enjoyment!
However I used a different method to code the game.
When the game is started, it loads the image and splits it into 9 sections which is stored into a 1d array. The images in the array are simply swapped around to the position they are needed to be. Some simple code can translate the 2d positions on the window.
You would think to do the blank space bit, i have an array where I move round a value and set it to 0 when i dont want that image to show.
Well, instead of wasting 18bytes of memory, I decided to put all the information needed to do this in just a 2byte int. each square is represented by a binary number. All I am doing is just swapping the binary numbers around from 1 to 0 when i dont want a block to show.
This can simply be done by getting a binary value and “notting” it. It easier explained using the art of diagrams!
table = 111111110 < would make the top left block not show
table = 111111110 ^ 101 = 111111011 < will now make the top right not show
table = 111111011 ^ 10000100 = 101111111 < will make the bottom middle not show
Simple eh. You can see the algorithm in the mouseClicked method. So even though there is no extra performance at all, the program does work using only 2bytes to know what it needs to show.
Even if this game looks pointless, theres plenty of useful code in there too!
Slider.java

Random picture of a cat :S

Lots of sliding been done! Hours of fun!
Website working again since it died.
This is a simple program written in Java 6 to allow a user to be reminded of events. A user can enter a a message and when to display the message, it works simular to Monty on the kent uni irc channel.
It is currently in development but here are some current screen shots of it so far.

When you start the program It just gives a simple message notifing it is running.

To add a reminder you can right click and press add.

You can type in your message as you would say it. You can tell it to work in seconds, minutes, and hours. More options will be added soon.

It will display a message saying that it understands and the time and date it will remind you of this message. Looks a bit cryptic at the moment, but this will be sorted soon.

Your message can be as long as you want it to be, the program understands if you say 1 minute, or 2 minutes. This makes typing the reminder seem more natural as you wouldnt say 2 minute or 1 minutes.

You can open the program by double clicking its icon in the system tray. You will see a table of events. Improvements to this will be done soon.
,
And finally, the reminder is displayed on your screen in as a balloon.
I am hoping to make a few more improvements to this program but for a few hours work it isnt bad. It is also my first program I coded in Java 6 and specially for Windows Vista, but I am sure it will look just as good in most other Operating Systems.
I shall release the source when I am done!
UPDATE:
Current binary can be downloaded from here
Credits
Credits to www.famfamfam.com for System Tray Icon
Well, I heard that some one had a little problem with Windows Vista and Windows XP. They had installed Vista, but then they decided they wanted to install XP on the same partition as they no longer wanted Vista.
They encountered some problems saying that you can not install XP over a Vista partition. Well, I thought this is just silly. So, I tried for myself.
Well, I made a recording of me trying this out but it is too big to upload so you will have to take my word, but you can try this for yourself.
I installed vista, on a computer with only one drive and one partition. Once it was installed, I restarted and put in my XP disk to install that over it. Well, when I choose to install XP i got this message.

Well, it seems that the hard drive used to install Vista can no longer be detected by XP. It is possible that Vista edits the drive boot partition to something that cannot be understood by XP.
So, it seems that you cannot install XP after installing Vista on the same hard drive.
I am sure that it is possible to repair the drive so XP can be installed, however a program may be required to do this. It is possible to fix this problem if you do format this disk using software supplied by the hard drive manufacturer. Apparently, Vista changes the file system layout effectivly moving the MBR. XP expects to see the MBR at a certain location but it doesnt making it not detect the drive.
I been currently working on a collision dection method for my game. I decided to use a tree to hold all the information of the positions of objects. I wrote a tree to hold a X and a Y value and I can search through it. Theres a few simple functions where I can find a object at a certain point but also some more complex functions for getting all the objects in a certain area.
I implemented my collision detection into my new game and this is how it looks so far. I added some code which highlights the block that is being currently collided with to demonstrate the feature.
Linkeh
At the moment it will return the list of all the blocks in the area that i want to move too. If there is something in that area, then I cant move. However, my collision detection can also allow me to see if there are ladders to allow me to climb once i implemented that feature.
However, the problem with this algorithm so far is that it only works on blocks that dont move.
So far, so good.
I got my first job interview! Its from a comany called JET that research into nuclear fission. Got the interview next week. Really happy as this was my first application I sent for work next year. There based in Oxford but they are paying for my travel. Should be fun!