Friday, September 9, 2011
Drive out to Marysville
Just wanted to go for another drive and managed to get caught in the snow.
Saturday, August 27, 2011
Thursday, August 25, 2011
Non sequential sequence
Every now and then I've wanted to go from 0 to n in almost a random fashion. One way to solve this problem is to create a list of all the numbers from 0 to n and then shuffle the list. This works for small numbers and is definitely random but what if you have a larger set of numbers and aren't so fussed about the randomness?
I was finally able to enter the right terms into my search engine to read up on linear feedback shift registers.
I had a quick peek around the net to see if there was one written in Java and came up empty handed. So I wrote one.
A quick & on the input to get the bits we were concerned with, >> to shift the bits and ^ the relevant bits to work out if I should stick a 1 on the high order bit.
Turns out that was a bit overkill, just needed to know if the amount of relevant bits was even or odd. If odd, add the high order bit (and shift the whole lot of course).
The interesting bit was the values for the taps based on the number of bits in the 'register' you want.
The Wikipedia article says that for a LFSR to cycle through all numbers, there needs to be an even number of taps, the set of taps needs to be relatively prime.
Not being up with the maths of that last bit, I delved deeper into Wikipedia.
Then I realised I had the tools to brute force this puppy. Create a number of LFSR with different tap values and see which ones cycle through all numbers!
This table starts to look like 3 is a good number to use, but it doesn't work for 8, 9, 10 and 11 bit registers. So unfortunately to get a good sequence of numbers, you need to know a good tap. I just haven't worked out a nice way to find out what they are.
Might as well include a table of the numbers generated by the different taps. I'll use a 5 bit register because of the multiple taps.
I was finally able to enter the right terms into my search engine to read up on linear feedback shift registers.
I had a quick peek around the net to see if there was one written in Java and came up empty handed. So I wrote one.
A quick & on the input to get the bits we were concerned with, >> to shift the bits and ^ the relevant bits to work out if I should stick a 1 on the high order bit.
Turns out that was a bit overkill, just needed to know if the amount of relevant bits was even or odd. If odd, add the high order bit (and shift the whole lot of course).
if(Integer.bitCount((input & trap) ^ trap) % 2 == 1) { return (input >> 1) | (1 << bits - 1); } else { return input >> 1; }
The interesting bit was the values for the taps based on the number of bits in the 'register' you want.
The Wikipedia article says that for a LFSR to cycle through all numbers, there needs to be an even number of taps, the set of taps needs to be relatively prime.
Not being up with the maths of that last bit, I delved deeper into Wikipedia.
Then I realised I had the tools to brute force this puppy. Create a number of LFSR with different tap values and see which ones cycle through all numbers!
Size | Taps |
---|---|
3 | 11 101 |
4 | 11 1001 |
5 | 11 1001 1111 10111 11011 11101 |
6 | 11 11011 100001 100111 101101 110011 |
Might as well include a table of the numbers generated by the different taps. I'll use a 5 bit register because of the multiple taps.
101 | 16 | 8 | 4 | 18 | 9 | 20 | 26 | 13 | 6 | 19 | 25 | 28 | 30 | 31 | 15 | 7 | 3 | 17 | 24 | 12 | 22 | 27 | 29 | 14 | 23 | 11 | 21 | 10 | 5 | 2 | 1 |
1001 | 16 | 8 | 20 | 10 | 21 | 26 | 29 | 14 | 23 | 27 | 13 | 6 | 3 | 17 | 24 | 28 | 30 | 31 | 15 | 7 | 19 | 25 | 12 | 22 | 11 | 5 | 18 | 9 | 4 | 2 | 1 |
1111 | 16 | 8 | 20 | 26 | 13 | 22 | 11 | 21 | 10 | 5 | 2 | 17 | 24 | 28 | 14 | 23 | 27 | 29 | 30 | 31 | 15 | 7 | 19 | 9 | 4 | 18 | 25 | 12 | 6 | 3 | 1 |
10111 | 16 | 24 | 28 | 14 | 7 | 19 | 25 | 12 | 22 | 27 | 29 | 30 | 31 | 15 | 23 | 11 | 5 | 2 | 17 | 8 | 4 | 18 | 9 | 20 | 10 | 21 | 26 | 13 | 6 | 3 | 1 |
11011 | 16 | 24 | 12 | 22 | 11 | 21 | 10 | 5 | 18 | 9 | 4 | 2 | 17 | 8 | 20 | 26 | 29 | 30 | 31 | 15 | 23 | 27 | 13 | 6 | 19 | 25 | 28 | 14 | 7 | 3 | 1 |
11101 | 16 | 24 | 12 | 6 | 19 | 9 | 4 | 18 | 25 | 28 | 30 | 31 | 15 | 23 | 27 | 29 | 14 | 7 | 3 | 17 | 8 | 20 | 10 | 21 | 26 | 13 | 22 | 11 | 5 | 2 | 1 |
*In my code I refer to traps. Miss read the wiki :P
Wednesday, August 24, 2011
Overengineering
A while ago I used to be able to VNC from my phone to my desktop to remotely play, pause and change the volume of winamp. I didn't use it often but it was handy.
At some point, my phone just gave up on the VNC connection. I don't know whether it can't handle the screen size (poor iPhone 3g) or if there is an incompatibility in the VNC versions. I did try updating RealVNC and using a different client on my phone but no success.
I had toyed with Java Robot before and figured it would be worth a laugh.
So fired up eclipse and wrote a program that paused, played, turned up the volume and turned down the volume. Fumbled through the Robot javadoc and re-factored it a bit so it looked nice. Got it running fairly quickly.
Next problem, how to control it. I figured html would work for an interface. That means I need to set-up a http server to listen for requests. I was hoping to just fudge through it, read the socket until I got something that looked like a location and push back content.
I wasn't really in the mood to read through the RFC for http so I turned to the Internet.
It came back with NanoHTTPD
I wasn't happy with the way you were expected to subclass it to handle specific URLs so I re-factored it a bit before getting to work.
Put some html together to be served and then it basically fell together.
I love it when you start from the top and bottom of a problem and the middle is just a bit of fiddling around.
So here it is, my winamp remote:
Yup, not much but it made me a happy little coder.
Been wasting most of today re-factoring NanoHTTPD. One of it's selling points is that it is just a single file which was handy for this project, but annoys my sense of organisation. I've split it in 2, one for the pure Http stuff and the other for utilities like turning it into a file browser.
Got rid of the need to consistently spawn new threads, clean up it's stream handling a bit and brought it up to scratch in terms of Java 1.5.
Was wondering if anyone else was interested in this? Should I make the controls configurable so it can control other applications?
At some point, my phone just gave up on the VNC connection. I don't know whether it can't handle the screen size (poor iPhone 3g) or if there is an incompatibility in the VNC versions. I did try updating RealVNC and using a different client on my phone but no success.
I had toyed with Java Robot before and figured it would be worth a laugh.
So fired up eclipse and wrote a program that paused, played, turned up the volume and turned down the volume. Fumbled through the Robot javadoc and re-factored it a bit so it looked nice. Got it running fairly quickly.
Next problem, how to control it. I figured html would work for an interface. That means I need to set-up a http server to listen for requests. I was hoping to just fudge through it, read the socket until I got something that looked like a location and push back content.
I wasn't really in the mood to read through the RFC for http so I turned to the Internet.
It came back with NanoHTTPD
I wasn't happy with the way you were expected to subclass it to handle specific URLs so I re-factored it a bit before getting to work.
Put some html together to be served and then it basically fell together.
I love it when you start from the top and bottom of a problem and the middle is just a bit of fiddling around.
So here it is, my winamp remote:
Yup, not much but it made me a happy little coder.
Been wasting most of today re-factoring NanoHTTPD. One of it's selling points is that it is just a single file which was handy for this project, but annoys my sense of organisation. I've split it in 2, one for the pure Http stuff and the other for utilities like turning it into a file browser.
Got rid of the need to consistently spawn new threads, clean up it's stream handling a bit and brought it up to scratch in terms of Java 1.5.
Was wondering if anyone else was interested in this? Should I make the controls configurable so it can control other applications?
Monday, June 6, 2011
How many possible 24bit 10Mp photos there can be?
This tweet came from Neil Creek and a simple tweet response was not going to be enough.
His original thought was 16777216 colours x 10 million pixels which is not enough. This number, whilst big, would only represent each pixel being changed through each colour, whilst the rest of the image stayed the same. This would be very boring.
What you need to calculate is 2^24 * 2^24 * 2^24 ... 10 million times. (2^24^10000000)
Since my computer has been sitting here for 10-15 minutes trying to calculate this value and I have been unable to find out how to simplify this sort of equation, we'll just have to make the question easier.
If there were 10,000,000 colours and we still work with 10 million pixels we end up with a number that starts with 1 and has 70 million 0's after it.
That's 1e70million.
Distance from earth to the sun is 1.5e8km
Distance from Earth to Alpha Centauri is 4e13km
Estimated distance across the universe is 1.5e24km
The reason I wanted to make a post out of this is imagine the sort of images that would be produced.
His original thought was 16777216 colours x 10 million pixels which is not enough. This number, whilst big, would only represent each pixel being changed through each colour, whilst the rest of the image stayed the same. This would be very boring.
What you need to calculate is 2^24 * 2^24 * 2^24 ... 10 million times. (2^24^10000000)
Since my computer has been sitting here for 10-15 minutes trying to calculate this value and I have been unable to find out how to simplify this sort of equation, we'll just have to make the question easier.
If there were 10,000,000 colours and we still work with 10 million pixels we end up with a number that starts with 1 and has 70 million 0's after it.
That's 1e70million.
Distance from earth to the sun is 1.5e8km
Distance from Earth to Alpha Centauri is 4e13km
Estimated distance across the universe is 1.5e24km
The reason I wanted to make a post out of this is imagine the sort of images that would be produced.
- Works of Shakespeare
- A picture of you looking at this large set of images
- You could be arrested for looking at child pornography
- You would eventually see the winning tattslotto numbers for the coming weekend
- You would see an image of how you die
Not that it matters. If you looked at 14 of this pictures a second, you would only see 1.2 million a day.
Friday, March 18, 2011
Meta post
I just want to put it on record that I've gone through all of my posts to upload the images to blogger.
2 hours isn't really a long time to spend on it but it feels like it has been a week.
I got half way through and wondered if I should be uploading them to twit pic or flickr so that their existence isn't tied to the blog...
Tuesday, February 15, 2011
So here I am
As I mentioned on the original post:
Hit the export button on word press.
Converted with http://wordpress2blogger.appspot.com/ because my blog is under 1MB.
Import to blogspot.
Delete the spam that came through.
Done.
Much nicer process than manually copying and pasting entries.
Although I've noticed that it didn't export the images. I'll have to get a copy of them, upload them somehow and relink them. Bit of a pain.
Problems?
So for when I'm typing a new post, when I press enter it goes back to the start of the current line AND appends a new line to the end. Very odd
There is also a word verification for creating a post?! You know who I am. I can't spam my own blog can I?
Hope that goes away...
(oh, apparently it is because I just imported all of my posts)
Hit the export button on word press.
Converted with http://wordpress2blogger.appspot.com/ because my blog is under 1MB.
Import to blogspot.
Delete the spam that came through.
Done.
Much nicer process than manually copying and pasting entries.
Although I've noticed that it didn't export the images. I'll have to get a copy of them, upload them somehow and relink them. Bit of a pain.
Problems?
So for when I'm typing a new post, when I press enter it goes back to the start of the current line AND appends a new line to the end. Very odd
There is also a word verification for creating a post?! You know who I am. I can't spam my own blog can I?
Hope that goes away...
(oh, apparently it is because I just imported all of my posts)
Thursday, January 27, 2011
De-booking
So the time has come when it no longer makes sense for me to keep some of my books.
Their age makes me wonder if anyone else could actually use them but I'd hate to just throw them out without trying.
Core Java 2 Fundamentals (Volume 1) (1999)
Guide to Linux Installation and Administration (2003)
Information Systems Development (2003)
Creating Web Pages with HTML and Dynamic HTML (2003)
C++ for Java Programmers (2000)
Simply SQL (2008)
Business Data Communications (2003)
Problem Solving and Program Design in C (1996)
Java. An Introduction to Computer Science& Programming (2001)
Structured Cobol Programming (1994)
Programming with Visual Basic 6.0 (1999)
These are all offered at the one low price of .... nothing. I just want to see them used. Leave comment or contact me the best way you know how if you are interested in any of them.
I'd also be interested to hear what I can do with these books if I can't get rid of them. Is there any value dropping them off to the Salvo's or are they closer to junk?
Are they the sort of thing to donate to a library or are they too old?
Their age makes me wonder if anyone else could actually use them but I'd hate to just throw them out without trying.
Core Java 2 Fundamentals (Volume 1) (1999)
Guide to Linux Installation and Administration (2003)
Information Systems Development (2003)
Creating Web Pages with HTML and Dynamic HTML (2003)
C++ for Java Programmers (2000)
Simply SQL (2008)
Business Data Communications (2003)
Problem Solving and Program Design in C (1996)
Java. An Introduction to Computer Science& Programming (2001)
Structured Cobol Programming (1994)
Programming with Visual Basic 6.0 (1999)
These are all offered at the one low price of .... nothing. I just want to see them used. Leave comment or contact me the best way you know how if you are interested in any of them.
I'd also be interested to hear what I can do with these books if I can't get rid of them. Is there any value dropping them off to the Salvo's or are they closer to junk?
Are they the sort of thing to donate to a library or are they too old?
Subscribe to:
Posts (Atom)