Friday, 13 January 2012

Why the World should use 'Time Machine'


So...


Yesterday afternoon, my 2009 MacMini froze and would not reboot.


"Not to worry" I thought. I have a script that shuts down Time Machine at 9am, but turns it on at 9pm - in effect forcing it to do a daily backup without crushing the performance of the Mac during the day.


So I inserted the OS disc (Lion) and restored the drive. I've never had to do this before, but its awesome - took 4.5 hours, but that seems fair given the amount of stuff on it.


Everyone should have Time Machine - or buy a Mac to get it. I've always assumed it would work, but never needed to test it.


The end result is I've lost a few client files I was working on, but nothing major.


The only question that remains is - am I right in thinking that the HDD is on its way out - it kept hanging on boot-up, but did not show errors in Disk Utility? The restored system seems fine, so I can't imagine its a logic board/RAM thing.

Thursday, 12 January 2012

Resetting Home Key on iPhone 4

So, the home key on my iPhone was becoming really unresponsive, like pretty much broken. Of course the phone is out of warranty.


BUT never fear - I found this at the Apple community:


Reset Home Button Steps:

(1) Tap Settings App, when open:
(2) Hold Power button until "slide to power off" bar appears.
(3) Don't slide it, release power button.
(4) Gently, continuously press Home button for few seconds until home screen appears.
(5) Done.

If this does not help, further points to Hardware Problem.

Tuesday, 29 November 2011

Copy an.ISO image to a USB Stick on a Mac

Disk Utility, for whatever reason, is prohibited from writing Joliet (ISO 9660) onto MS-DOS FAT 32 Flash Drives, though it should definitely work.

The best way to accomplish your goal is the following:

Open Terminal

Type 'diskutil list'. You'll see your primary hard drive (probably listed under /dev/disk0) and your Flash Drive, which will be listed as /dev/disk#, with # being any number that isn't zero. REMEMBER THE DISK LOCATION

In the next line, type 'diskutil unmountDisk /dev/disk#'. You'll see this message on success:
Unmount of all volumes on disk# was successful

Now type, 'dd if=(DRAG ISO/DMG HERE) of=/dev/disk# bs=1m'

Thursday, 27 October 2011

Install iLife from MacBook Air USB Key

Stick the USB stick into another Mac and try the command below in Terminal:

open /Volumes/Mac\ OS\ X\ Install/Packages/iLife/iLife.pkg

Friday, 21 October 2011

Get the text from a PDF

I needed this at short notice, and it works flawlessly.


I like the use of PDF’s, they work well and (usually) appear the same on ever computer. One of the advantages of PDF’s is the text embedded within the file, and the abilty to manipulate. Although many PDF readers have functions to copy and paste text, whats quicker than creating an Automator script to extract PDF text into a text file.
This process only take a couple of steps so read carefully.
1) Open Automator, found in Applications > Utilities
2) In Automator drag out “Get Selected Finder Items”, then “Extract PDF Text”. I recommend changing the output option to Rich Text.
3) Save the file. Either as an application or a file.
4) Test. Drag a PDF file onto the Automator file and let it do its work, after a short time you will have a text file with the extracted text.

Wednesday, 15 June 2011

How To scp, ssh and rsync without prompting for password


Whenever you need to use scp to copy files, it asks for passwords. Same with rsync as it (by default) uses ssh as well. Usually scp and rsync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expectscript to provide the password. Of course, I didn't. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...

Lets say you want to copy between two hosts host_src and host_desthost_src is the host where you would run the scp, ssh or rsyn command, irrespective of the direction of the file copy!
  1. On host_src, run this command as the user that runs scp/ssh/rsync
    $ ssh-keygen -t rsa
    This will prompt for a passphrase. Just press the enter key. It'll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default~/.ssh/id_rsa.pub:
    Your public key has been saved in <your_home_dir>/.ssh/id_rsa.pub
  1. Transfer the id_rsa.pub file to host_dest by either ftpscp, rsync or any other method.
  1. On host_dest, login as the remote user which you plan to use when you run scpssh orrsync on host_src.
  2. Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys
    $ cat id_rsa.pub >>~/.ssh/authorized_keys
    $ chmod 700 ~/.ssh/authorized_keys
    If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.
  1. Note that ssh by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don't forget to restart sshd so that it reads the modified config file. Do this only if you want to use the root login.
Well, thats it. Now you can run scpssh and rsync on host_src connecting to host_dest and it won't prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting tohost_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!

Wednesday, 1 June 2011

Adding Users to phpbb forums

So, we have a site that uses the PHPBB forum as a backbone, but we need to add users to it without them going through the normal procedure in the front end:

Here's how

    define('IN_PHPBB', true);
   
    global $db;
    global $config;
    global $user;
    global $auth;
    global $cache;
    global $template;
    global $phpbb_root_path;
    global $phpEx;
   
    $phpbb_root_path = 'forums/';  // forum directory path here
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    //include($phpbb_root_path . 'common.' . $phpEx);
   
    include('forums/common.php');
   
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
   
    require($phpbb_root_path .'includes/functions_user.php');
   
    $username = $_POST['user'];
    $password = $_POST['password']; // Dont encrypt the password!
    $email = $_POST['email'];
   
    // Check for unique username otherwise it will throw an error or might be blank page
   
    $user_row = array(
    'username' => $username,
    'user_password' => md5($password), 'user_email' => $email,
    'group_id' => 2, #Registered users group
    'user_timezone' => '1.00',
    'user_dst' => 0,
    'user_lang' => 'en',
    'user_type' => '0',
    'user_actkey' => '',
    'user_dateformat' => 'd M Y H:i',
    'user_style' => 1,
    'user_regdate' => time(),
    );
           
    $phpbb_user_id = user_add($user_row);