Posts Tagged ‘code’

Getting a list of numbers between two values

This is yet another extension.

I don’t like Enumerable.Range() for the sole reason you have to give a start index and a count. So I made up my own. This is an extension for an integer type and will allow you to specify two values that you want a range for

public static IEnumerable<int> RangeTo(this int startValue, int endValue, int step)
{
	return (endValue < startValue) ?
		Enumerable.Range(endValue, startValue - endValue + 1).Reverse() :
		Enumerable.Range(startValue, endValue - startValue + 1);
}

This will also allow for reverse lists – see how to use it below:

1.RangeTo(10);  // {1,2,3,4,5,6,7,8,9,10}
5.RangeTo(10);  // {5,6,7,8,9,10}
10.RangeTo(5);  // {10,9,8,7,6,5}
3.RangeTo(3);   // {3}

int x = 15;
int y = 17;
x.RangeTo(10);  // {15,14,13,12,11,10}
y.RangeTo(x);  // {17,16,15}
x.RangeTo(y);  // {15,16,17}
13.RangeTo(x); // {13,14,15}

Random sort on IEnumerable object

Quick extension on an IEnumerable object to return the collection in a random order:

public static IEnumerable<T> Random<T>(this IEnumerable<T> source)
{
	return source.OrderBy(x => Guid.NewGuid());
}

For example, to return a random set of 5 items from the collection:

var randomSet = myEnumerable.Random().Take(5);

If anyone knows of a better way, let me know :)

Photo Rotator 0.5 now in the App Store

Hurrah!
My very first App Store application has been released today. That is the Photo Rotator.

It’s a very small program with one purpose only, and that’s to rotate photos! Open the application, choose a picture, press a few buttons and the new photo is rotated.

Why do it? Well, I received a message containing a photo I wanted to set as my background. Problem was that the photo had the wrong orientation, so it would only show up sideways. I looked on the app store for similar programs and found some – but they charged for it!

It’s an incredibly simple program with a feature that should have been built in which is why I made one and it’s free. No charge, ever. Although, if you really like it then please feel free to donate by pressing the button at the side of this page (thank you).

Download Photo Rotator from the App Store

If you have any questions, bugs, comments then please email ipod@bolsterweb.com

RTSJ, the marble sorter and MaRTE OS

I figure that I may as well give a brief spec of my project for myself and anyone else that may care. The project I am doing is basically checking if the RTS module in the CS department should be teaching RTSJ rather than what is currently taught, Ada. This module is taught with a practical element that involves the students creating a system in Ada that runs a marble sorter which is connected to a barebones x86 machine. The Ada code is compiled and then linked with the MarteOS system so that the entire file is the operating system and run code in one.

So the project I’ve been working on is to update the jRate compiler with the MarteOS patch so that the marble sorting element of the course can be taught using RTSJ. The only thing that the patch seems to do is provide scripts for linking in MarteOS as well as providing the thread scheduler.

The basic elements such as handling and dealing with the interrupt model all need to be implemented, as well as accessing the device registers to be able to control the marble sorter (which is connected via a serial and parallel cable).

Any post about this will have the tag ‘masters project’ added to it and, although some of this has already been done, I want to write about it for my own self and if anyone is working on a similar thing.

Fon Bookmarklet

I’m about to go on a short holiday around Europe. I’ve my Fon router plugged in, ready to get the benefits of free internet on my iPod Touch whilst away. Typed a quick ‘fon bookmarklet’ search into google and only found a youtube video of some chinese person showing his working (but not actually giving the code)

So here’s mine. It’s simple, but it works:
javascript: document.getElementById('login_email').value='EMAIL_ADDRESS'; document.getElementById('login_password').value='PASSWORD'; document.getElementById('login_email').parentElement.submit()

And here’s it in link form for clicking and dragging to the bookmarks toolbar:
Fon Login

My own link has obfuscation on the password just so that it’s not blatantly obvious in the link (maybe I’ll do some obfuscation code eventually), but changing those details would work for the ‘Fon Login’ page that loads up when connecting to a FON_AP wifi point. It works in Safari, at least. The ‘parentElement’ is null in Firefox but since this is for an iPod Touch, I don’t really mind. If anyone knows why it’s null then just let me know.