Friday, October 26, 2012

Create an ISO image of a DVD on Mac OS X

It seems to be a bit more difficult to create ISO images on the recent Mac Mountain Lion. Though I never did it before, it seems that an option to create an ISO was a part of the Disk Utiltiy application. Now though you can only make a .dmg.

You can try to copy all the files from a DVD to a folder and use Disk Utility to create an ISO but you'll have problems with extended attributes if copying a Mac OS X Install disc.

This works ok.

1. Open Terminal.

2. Now find where the DVD is mounted.


Type :
drutil status
This will tell us where the drive is mounted. It will look something like:

John-Mac-mini:Desktop John$ drutil status Vendor   Product           Rev  HL-DT-ST DVDRW  GA32N      KC12
           Type: DVD-ROM              Name: /dev/disk1       Sessions: 1                  Tracks: 1    Overwritable:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB     Space Free:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB     Space Used:  843:15:63         blocks:  3794688 /   7.77GB /   7.24GiB    Writability:       Book Type: DVD-ROM (v1)

We can check using: mount

John-Mac-mini:Desktop John$ mount/dev/disk0s2 on / (hfs, local, journaled)devfs on /dev (devfs, local, nobrowse)map -hosts on /net (autofs, nosuid, automounted, nobrowse)map auto_home on /home (autofs, automounted, nobrowse)/dev/disk2s3 on /Volumes/My Book Time Machine (hfs, local, nodev, nosuid, journaled)/dev/disk1s3 on /Volumes/Mac OS X Install DVD (hfs, local, nodev, nosuid, read-only, noowners)

I notice that in my example mount gave:
/dev/disk1s3
and drutil gave:
 /dev/disk1

You need to unmount the DVD drive by running: umount
This will need to be run as super user (sudo) and this will require your password.

sudo umount /dev/disk1
Password:


You now need to run the dd command:
sudo dd if=/dev/disk1s3 of="my file name.iso"















Copy DVD contents to a folder on OSX using Terminal

Open, Terminal

Type  
df
This will give us the device names.

You will see something like:

/dev/disk1s3    13158216   12992304    165912    99%   1624036    20739   99%   /Volumes/My DVD stuff

You can highlight and copy the DVD information  using cmd C.

Copy your equivalent to this: 
/Volumes/My DVD stuff

Then navigate to the target folder (using the cd command) such as:

cd /Users/John/Desktop/my target folder/

Now we can do the copying from the DVD to where we are.

cp -rpv "/Volumes/My DVD stuff" ./
If you want it to run quietly, then leave of the v option for verbose. Then if it will only report errors to the screen.

cp -rp


Job done.



Wednesday, October 24, 2012

How to instal Remote disc on an older mac

If like me you have an old Macbook pro and the optical drive has decided to lay down and die, then it's a bit of a problem upgrading the OS if you don't have the App Store.

I wanted to upgrade to Mountain Lion but the version was pre-Snow Leopard (I should have noted the version as I'm writing about it!).

Trouble is, to get from ye-olde version to Mountian Lion I needed to get the App Store, and to do that I need Snow Leopard, which comes on a DVD and will then let me get to the App store. Easy.

I needed to place the Snow Leopard DVD into the drive on my iMac (Mountain Lion), share the DVD drive by selecting Sharing in System Properties.

Then, I needed Remote disc on the old Macbook Pro. Problem is, it's only on newer kit. Well actually it's not. It's actually there, I just needed to configure it.

Open terminal on the Macbook and type:

defaults write com.apple.NetworkBrowser EnableODiskBrowsing -bool true
then

defaults write com.apple.NetworkBrowser ODSSupported -bool true
Then restart the Macbook and in the Finder's sidebar there will be a disc icon. Click on it and off you go.

You can install from there. Fantastic I thought.

I went into System Preferences, Energy Saving, on both computers and set the computers not to go to sleep.

Installing across wifi took 3.5 hours then failed.

I tried again. It failed after the remote drive became unavailable.

I got a router and two cables and networked them together so it would be quicker but now the macbook tells me the HD is damaged.

I ran disk utility on it all it says it's fine so the media is ok.

Pooh.

Remote Disc was working, but I couldn't upgrade the OS with it.

In the end I,
1. Created an ISO of Snow Leopard
2. Formatted a memory stick (journaled)
3. Put the ISO on the stick and installed from there.

It worked - not entirely though. An issue with Spotlight remains that I haven't had time to resolve.
Oh - and my only Macbook is too old for Mountain Lion, or Lion. :)

Monday, September 3, 2012

Javascript functions

(A) The standard way - the Function Definition

This is the std. way a function could be written in Javascript. It's easily recognisable from major programming languages: it has the function keyword, a name, parameters, a function body delimited by curly-braces, and a return.
It is also useful to know, or it might just be interesting, that functions are Objects.

function square(x) {
    return x * x;
};


Invoked by:
square(5);

(B) Standard function declaration assigned to a variable - the Function Expression

This next example assigns the function to a variable. The interesting here is that you can not invoke the function by the function name. You must invoke it by the variable name.


var squareFunction = function square(x) {
    return x * x;
};


Invoked by:
squareFunction(5);


Anonymous function

This next one is the Anonymous function. It is a simplification of the previous.
The function name is omitted. It is usual to use this anonymous version as it is less verbose, however the previous one can be useful when debugging as the function name will appear in the call stack.


var squareFunction = function (x) {
    return x * x;
};

Why the two ways and which one should I use

There are two benefits to using the Function Expression (assigning the function to a var)
1. One is it keeps the function name to the local scope and doesn't pollute the global namespace.
2. The name will show up in debuggers.


The immediately invoked anonymous function

The difference is
1. Wrap the function in brackets
2. Immediately invoke the function afterwards



( function (x) {
    return x * x;
})(numberToSquare);

This is used a lot in jQuery.

Dmitry's

Go and read Dmitry's blog on functions for the whole story. Now here's a bloke who knows his stuff. http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses

Saturday, July 28, 2012

Virtual box fails after OSX Mountain Lion upgrade

I just knew it would be trouble.

The lengthy upgrade to OSX 10.8 upset VirtualBox.
This is what greeted me on the restart.


So now what.
I knew I had an old version (4.1.4). And I knew deep down that upgrading wouldn't help.



I needn't have been so pessimistic because all I needed to do, was use the uninstall script.
Unlike other apps where an uninstall can be simply moving the app to the trash, with VirtualBox you run the script in the bottom right hand corner of the instal windows.



You might have a problem with the script with some errors in the terminal wind - caused by open files or some such. The easiest thing to do is restart OSX and don't run an VirtualBox versions. Then run the Uninstall tool. Then go and install VirtualBox.
Helpful?

Simplifying the solution

When solving something, designing a solution or building an interface. We should start by remembering Occam's razor. This is succinctly stated by Einstein as:

"Everything should be made as simple as possible, but not simpler." - Albert Einstein

But this is a bit elegant, sexy and abstract perhaps. Steve Jobs wrote the following that is a bit more concrete and :

“When you first start off trying to solve a problem, the first solutions you come up with are very complex, and most people stop there. But if you keep going, and live with the problem and peel more layers of the onion off, you can often times arrive at some very elegant and simple solutions. Most people just don’t put in the time or energy to get there.” - Steve Jobs


What is really helpful to those in the team that want the little addition to improve the solution.

“Sometimes a design decision is what you don’t put in, as opposed to what you put in.”- John Gruber

I was prompted to write this blog following a chat I had with a colleague and reading Shawn Blanc's posting http://shawnblanc.net/2012/07/mountain-lion-and-the-simplification-of-os-x/

Thursday, July 26, 2012

Question the norm in the dev team

 Apologies but it's a bit pompous of me using Einstein in the same post as my work, but here goes.

"Concepts that have proven useful in ordering things easily achieve such authority over us that we forget their earthly origins and accept them as unalterable givens." - Albert Einstein. 


It seems to me that software development generates a lot of acronyms and methods all providing the definitive in wisdom. As you get longer in the tooth you get cynical and question these saviours. Einstein was on a totally different level of course but the principle is worth thinking about in the development team.


Wednesday, July 4, 2012

First Order Logic

This stuff is great fun.
There are a number of differeing styles of notation and my logic, how I still think, started in electronics and then early Computer Science lessons so I might be a bit wrong in places. It's something I enjoy and I hope to apply it more.

A Predicate

A predicate is a statement that is TRUE or FALSE
An example could be:
A dog is a mammal.
A dog is a fish.
Both of the above are predicates but the second one is false.

We can write those in psudo computer speak as:
IsaMammal(dog)
IsaFish(dog)
Both of the above would return a Boolean.

Symbols we use all the time


→ - Implies

¬ - Not

These two are quantifiers, for obvious reasons 
∃ - There exists. This means that there is one or more, there is at least one value that makes the predicate true.
∀- For all




Inference

This stuff is basic, but interesting if you've not seen it before.
(1) ¬(a and b) = ¬a or ¬b
(2) ¬(a or b) = ¬a and ¬b

(1) Not (a and b), is the same as (not a) or (not b)
(2) Not(a or b) is the same as saying,  (not a) and (not b)

In electronics we used to use "+" for OR, "." for AND and a bar across the letter for NOT.
_   _
a + b  Not a OR Not b  

_____
a + b Not (a or b)

We used to say "break the bar change the sign" to remember the following:
 ___   _ _
 a.b = a+b
 ___   _ _
 a+b = a.b

Not sure if that's of any use but it's true none the less.  DeMorgan's Theorem.

We can use them thus:

If someone says that something is ¬(a and b) 
then to prove them wrong, we have to prove  ¬a or it is ¬b




Two more

(1) This is nearly, or pretty obvious I think: 

If we know that a implies b,
a→b and we know a, then we also know b

(2) This one probably isn't so obvious:
If we know that a implies b,
a→b and we know it is ¬b, then we also know ¬a
Notice that the two rules have a reversal. The first one is Modus Ponens and the second is Modus Tollens. We don't really need to know that but it's posh.

Using modus Ponens:
If we know the creature is a Dog, then we know it is a mammal.
Dog(creature) → Mammal(Creature) 
Using Modus Tollens,
If we know the creature is not a dog, then we know it is not a mammal
¬Mammal(Creature), therefore ¬Dog(Creature)

There are two more, similar

a → b = ¬b → a
¬(a→b) = a and ¬b


Using first order logic to define a Prime number


prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

We can write two predicates:
Divisible(a, b) - the integer a is divisible by b.
Greater(a, b) - the integer a is greater than b.

So we can create a predicate for Prime numbers.
Prime(n) returns true if n is a prime, otherwise false if it is not.

Prime(n) = ∀i Greater(i,1) → ¬Divisible(n, i)
Prime(n) = ∀i Greater(i,1) and ¬Divisible(n, i)
The above says, n is a prime number
if for all numbers, i, i is Greater than 1, and n is not divisible by i



Prolog

Just for interest. here's the Prolog code to check if a number is a prime number

Example:  isprime(3).

code:

divisible(X,Y):-
      N is Y*Y, 

      N =< X, 
      X mod Y =:= 0.

divisible(X,Y):- 

      Y < X, 
      Y1 is Y+1, 
      divisible(X,Y1).

isprime(X):- 
     Y is 2, 
     X > 1, 
     \+divisible(X,Y).








Sunday, July 1, 2012

Hick's Law - A Design principle

"The time required to locate and use an option increases as the number of options increases."
Basil Fawlty: Next contestant, Mrs. Sybil Fawlty from Torquay. Specialist subject - the bleeding obvious.

I'm not sure how useful this principle is on its own but I am reminded of it because of a piece of software I have had the great misfortune to come across recently. I don't have to use it but I feel very sorry for the people that do. An absolute horror of a piece of software. 

I am reminded that although it enables users to do stuff, it doesn't make it easy, and it certainly doesn't generate any delight. Those are what we should be looking for now in our applications.

Oh the software: iMIS.
What is it with the "i"? 
Why do they do that?
There is nothing remotely "i" about their system.

For my mind it's Hick's law that makes Pages so much better than MS Word.