Monday, 11 March 2013

MacBook Pro 15" Unibody keyboard trouble

Just had a look at a MacBook Pro with keyboard issues. Whenever you tried to type anything it'd make a "nope" noise. Restarted in single user mode "cmd + s", and whenever you tried to type it'd come up with all sorts of stuff.

I rebooted into Windows XP and could not use the ctrl + alt + del key to login. I assume it was a hardware failure at this point.

I tried to update firmware, I might have figured that there would be a keyboard firmware update but couldn't find any such thing.

I rebooted and connected an external keyboard which worked quite well, although when this was connected, occasionally it'd make a 'nope' noise.

I opened up the keyboard viewer in the top right corner and noticed that cmd + shift keys were always held down:

Looks like it thinks these keys are being constantly pressed.

Looking into replacing the keyboard, but after looking at this take-down tutorial and this video:

I think perhaps not.

Will update this when its' fixed.

Sunday, 10 March 2013

Prime Factorisation - programming

Thought I'd test my programming skills by making a program which tells you the prime factorisation of a number or range of numbers. i.e:

4 = 2 x 2
10 = 2 x 5
20 = 2 x 2 x 5

etc...

Here's the code which works it out for a series of numbers:

//
//  main.c
//  printInPrimeFactors
//
//  Created by Monkey on 10/03/2013.
//  Copyright (c) 2013 Monkey. All rights reserved.
//

#include

#define TRUE 1
#define FALSE 0

int isPrime (int number);
int printInPrimeFactors (int number);

int main(int argc, const char * argv[])
{
    //scan in a number
    int startNumber = 0;
    printf("Type a starting number: ");
    scanf("%d", &startNumber);
    
    int endNumber = 0;
    printf("Type an end number: ");
    scanf("%d", &endNumber);
    
    //find the prime factors of range of numbers
    for (int i=startNumber; i<=endNumber; i++) {
        printInPrimeFactors(i);
    }
    
        return 0;
}

int printInPrimeFactors (int number) {
    //printf("finding the prime factors of %d.....\n", number);
    
    //if it's a prime just print it and return to main
    if (isPrime(number)) {
        printf("%d\n", number);
        return 0;
    }
    
    //for nice formatting I'm printing the number =
    printf("%d = ", number);
    
    //testing to find a factor of the number, which is also prime
    for (int i =2; i < number; i++) {
        if (number %i == 0 && isPrime(i)) {
            //printf("a prime factor of %d is %d\n", number, i);
            
            //testing to see how many times the number can be divided by 'i' and printing i each time
            //printf("testing to see how many times %d can divide by %d\n", number, i);
            int result = number;
            while (result % i == 0) {
                printf("%d x ", i);
                result = result / i;
            }
            
            //print an extra line to make it look nice
            //printf("\n");
        }
    }
    
    //print new line for next number
    printf("1\n");
    return 0;
}



//a function which returns true or false if number is prime
int isPrime (int number) {
    //printf("testing to see if %d is a prime\n", number);
    int prime = TRUE;
    
    //test to see if it is divisible by any other numbers
    for (int i = 2; i < number; i++) {
        if (number %i ==0) {
            prime = FALSE;
            //printf("%d is not a prime number\n", i);
            return prime;
        }
    }
    return prime;
}

output:
Type a starting number: 100
Type an end number: 120
100 = 2 x 2 x 5 x 5 x 1
101
102 = 2 x 3 x 17 x 1
103
104 = 2 x 2 x 2 x 13 x 1
105 = 3 x 5 x 7 x 1
106 = 2 x 53 x 1
107
108 = 2 x 2 x 3 x 3 x 3 x 1
109
110 = 2 x 5 x 11 x 1
111 = 3 x 37 x 1
112 = 2 x 2 x 2 x 2 x 7 x 1
113
114 = 2 x 3 x 19 x 1
115 = 5 x 23 x 1
116 = 2 x 2 x 29 x 1
117 = 3 x 3 x 13 x 1
118 = 2 x 59 x 1
119 = 7 x 17 x 1
120 = 2 x 2 x 2 x 3 x 5 x 1

after all that I found this nice website which basically does the same!

Thursday, 7 March 2013

iPad 3 apple logo on black screen cycle

A friend brought his iPad round. It was constantly switching on, showing the apple logo on black background, going slightly grey for a split second and then switching off.

Holding down the power button did nothing.

Holding down the power button and front button put it in "Connect to iTunes" mode. If you leave it for more then a minute not connected to itunes it begins its' cycle again.

Connecting to iTunes asks if you want to reset to factory defaults. Clicked 'yes' and it's downloading the update as I type.

When it was updating/reseting the ipad it came up with error 1611. After looking into it I found this help page on Apples website describing possible reasons:

  1. Security software problem
  2. Hardware fault

I concluded that it was a hardware fault. Taking it back to apple store.

....

took it to Apple Store and was replaced - hardware failure

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:


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

function printPrimeNumbers (startNumber, maxNumber) {
    var counter = startNumber;
    while (counter < maxNumber){
        if (isPrime(counter)) {
            print (counter);
            }
        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;
                    }
                    i--;
            }
        }
         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)
and
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:

#include
#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;
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.