Thursday, 28 February 2013

Finding Prime Numbers

Thought I'd test out some programming I'd learnt so I'm now writing a program to find large prime numbers. Here's the basic program which I'll improve over time:

function main () {
    print ("hello");
    printPrimeNumbers (1, 100);
    return 0;

function printPrimeNumbers (startNumber, maxNumber) {
    var counter = startNumber;
    while (counter < maxNumber){
        if (isPrime(counter)) {
            print (counter);
    return 0;

function isPrime (number) {
    var prime = true;
    if (number > 3){
        if (number !== 0){
            var i = (number-1)/2;
            while (i>1) {
                if (number % i == 0) {
                    prime = false;
                    return prime;
         else {
                prime = false;
    return prime;

Basically, isPrime (number) is the function which is doing all the work at the moment. If the number is greater then 3 and not divisible by 2 then: see if it can be divided by any number smaller then itself. This number starts from itself divided by two to reduce the number.

Found this little site which gives nice little examples of small C programs

So far this works. It is in fact already optimised slightly with the:
 if (number !== 0)
var i = (number-1)/2;

I havent actually read up on any optimisations anyone else has done. I think I'll carry on and when I get stuck I'll do some research.

My next main idea is to record all prime numbers starting from one up to the maxNumber. Then, to find out if the next one is a prime, just divide by all other primes before it. Should then not have to do as much work, perhaps by 3/4? The two down sides are that:

  1. I'd have to store these numbers somewhere
  2. I'd have to have all the primes up to the number you want to know whether is a prime or not.
Heres the script I came up with in C:

#define true 1
#define false 0
#define STARTNUM 1
#define ENDNUM 100000000

int printPrimes (int startNumber, int maxNumber);
int isPrime (int number, int primesArray[], int numberOfPrimes);

int main (int argc, const char * argv[]) {
    printf ("hello \n");
printPrimes (STARTNUM, ENDNUM);
    return 0;

int printPrimes (int startNumber, int maxNumber) {
    int counter = startNumber;
int numberOfPrimes = 0;
int primesArray [100000];
    while (counter < maxNumber){
        if (isPrime(counter, primesArray, numberOfPrimes)) {
            printf ("%d\n" , counter);
primesArray[numberOfPrimes] = counter;
/*printf("Printing the Array of Primes\n");
for (int c = 0; c < numberOfPrimes; c++) {
printf("%d\n", primesArray[c]);
    return 0;

int isPrime (int number, int primesArray[], int numberOfPrimes) {
    int prime = true;
    if (number <= 3){
            for (int i=1; i
if (number % primesArray[i] == 0) {
                    prime = false;
                    return prime;
    return prime;

Works pretty well.

A future idea is to find the frequency of primes and find a relationship. Perhaps taking it one step further and finding the frequency of frequencies. I'm not sure how to represent frequencies though?

Tuesday, 26 February 2013

EBS 4 Agent and Silverlight on OS X 10.6.6

We use EBS and have recently upgraded to version 4 which isn't officially supported for Mac :(. But it does work, although we have intermittent cases when a user gets a white screen.

To fix, you simply need to delete the:
~/Library/Application\ Support/Microsoft/Silverlight

folder. Simple.

I noticed that on 10.7.4 machines the folder is read only.

Friday, 22 February 2013

Workgroup Manager Crashing on connecting to server

Recently I've had an issue with Workgroup Manager crashing when it connects to the Xserver:

Error of type eMemoryAllocError (-14901) on line 401 of /SourceCache/WorkgroupManager/WorkgroupManager-361.3.1/DirNodeRefController.m
Please not I'm using:

  • Workgroup Manager Version 10.6.3 (361.3.1)
  • OS X 10.6.8
  • OS X Server 10.4.11

Doing a copy and paste in google brings up on 1 result which happens to be on Apple Discussions.  The discussion is exactly what I was looking for. Here it is.

Basically they describe the problem after a security update (not sure whether it was on the client or server). Luckily there is a work-around by ManuelSF, but people are not really liking it. Here it is:

  1. open workgroup manager
  2. click cancel at the login screen
  3. go to server in the menu bar and select view directories
  4. you should see your directory
  5. click on the lock in the upper left-hand corner to unlock and edit the directory.
Works better then it did before surprisingly!

Creating cogs in Illustrator

Thought it worth remembering (although it is very easy) but I wanted to create cogs in Illustrator. Luckily there are lots of youtube videos on the subject, here are two good ones:

and also this one:

The first involves making a circle, drawing a box whose centre is lined up with the circles but is draw on the edge of the circle. This box is then rotated around the centre of the circle by clicking on the box, clicking the rotate tool, and 'alt' clicking on the centre of the circle.

The second involves cutting a circle using rotated and copied lines and circles, and deleting the cog bits from the outside.

I prefer the first method, as cog notches do not wedge shaped the wrong way.

Thursday, 21 February 2013

deploying Flash Player on OS X using Apple Remote Desktop

So, all computer suites now have outdated flash players. To deploy I found it VERY difficult to find the official solution. Adobe tend to want each computer to be installed by a user:

But of course students log in and do not have permission to install! Luckily someone found a quick solution here. Turns out the flash installer (.app!!!) comes with a pkg file. Solved. (haven't tried it yet!!)

Just tried it on OS X 10.6 and worked perfectly!!

Don't know why this isn't documented very much.


  1. download flash player
  2. right click on the install flash file and select "Show package contents"
  3. go to Contents > Resources > Adobe Flash Player.pkg
  4. copy this and use Apple Remote Desktop to deploy!

The latest news is that you're best off applying for the latest distribution, which involves filling out a small form, confirming your email address, and then waiting for approval. Takes about 1 hour. Here's a link:

They then send you a link to the installer (pkg file) Yay!

Sunday, 17 February 2013

Joomla 3 and MAMP

So, just trying to start a new site in Joomla 3. On the first page one of the items says this:

Magic Quotes GPC OffNo

It basically won't install unless Magic Quotes GPC is turned off.

Found the answer here by 

All other answers were pointing towards fooling Joomla into thinking that either it didn't need GPC turned off, or that it needs the feature turned on. The correct way would of course to have the system setup to how joomla would need it (hence the verification stage here).

Basically, found php.ini in two folders:

in 5.3.6 I only found the following lines:

; Magic quotes
; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off
in 5.2.17 I found these more promising lines:
; Magic quotes
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = On
; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off  
; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off 

I edited the line in 5.2.17 to no avail. I also looked in MAMP which said it was using php 5.3.6 anyway.

I looked on MAMP's website and found that the latest version of MAMP comes with version 5.4.4. I also read that PHP 5.4.4 has depricated Magic Quotes! as of 5.3.

So, the easier solution would be simply to upgrade MAMP.

After doing so I found that I had to put my MYSQL password in for MAMP to be able to use mysql. In these files (found in a previous blog):

  1. Go to MAMP/bin/mamp/index.php and change the password bit
  2. Got to MAMP/bin/MyPHPAdmin/ and change the password bit in here too
Joomla 3 worked after this.

Monday, 11 February 2013

Joomla drop down menus

So I want to create drop down menus. Not having done this on a basic website it's worth looking at "Son of Suckerfish". Here's a nice article they've written for

So, the best way is to do it with the template, but another way might be to use extensions. Ive found this one called "Matic Menu" which looks very nice.

Art tool light looks quite easy to implement. Only trouble is that it applies to alltemplates. I'd rather have it only switch on for the template it was meant for.

Joomla Template selector

So I would like an extension which will allow users to select which template they would like. Eventually I would like an extension which would allow users to create and upload templates which users could then select.

First off I am trying Template Selector.

Well, it works exactly like it says on the box. Only had a little trouble working it, but it's my fault.

  1. download
  2. install
  3. go to Extensions > Plugin Manager
    1. switch it on
  4. go to Extensions > Module Manager
    1. switch it on
    2. activate for all pages
    3. select which templates to select

Only issue is that you need to make sure the position the module is in is present in all the templates it will be switched between.

To take it back to the default template simply delete the cookies in the web browser.

Sunday, 10 February 2013

Joomla ecommerce extentions

So I now need to start thinking about eCommerce and what is the easiest way of eCommerce with Joomla. Having a quick look I found JoomShopping which looked very easy indeed. I shall write notes down here to help remember things.

A quick look gives great first impressions. It's taken about 10 mins to:

  • install
  • setup category
  • setup item
  • create menu item which shows the categories
  • tested buying
  • paypal appears to be an option but needs looking into

Thursday, 7 February 2013

Converting PDF pages into pictures (OS X Mac)

So one thing I wanted to do recently was to have all the pages of a 20 page pdf file as individual picture files. But how to do this?

Well, I found information on this forum. Half way down gr8tfly says to:

  1. load up the pdf file (i loaded in Preview)
  2. File > Print
  3. Click on PDF at the bottom left of the print dialogue box

  4. Select "Save PDF to iPhoto"
  5. Click "Print"
  6. Open up iPhoto
  7. Eventually it'll load the pages in as pictures. You can drag these out of iPhoto and do whatever you want with them.
In theory, Save PDF to ......... should work, but for some reason it wouldn't ask me which folder to save it all in. Easier to work out with iPhoto.

HP Designjet 130 IP Address

One of the most annoying things I have to deal with is printers' IP addresses. This is especially difficult if the printer doesn't have a screen. Take the HP Designjet 130. It actually has a screen, but cannot represent digits. Not only this, but on top of this, it only has 3 buttons, none of which mention "setup". So, when the computer cannot send jobs to the printer how do you find out what is wrong? Well:
  1. load up a browser window and browse to the last known IP address of the printer...
    1. no response.
  2. ping the IP address which you think it has......
    1. no response.
  3. hold in the power button (while it's switched on) and press the paper feed button 4 times!!!!!!!
    1. it should print some (not sure how many) pages of information. 1st one has IP address.

I do remember wanting to write this down about 7 months ago but I can't find it anywhere. Anyway, here it is.

HP, could you please make the instruction number 3 in the list above more self-explanatory. i.e. have a button or just hold in the power button for setup printouts. 4 button presses is over the top.