Thursday, 25 September 2014

Password-less login over SSH

You can login to a remote Linux server without entering password using ssky-keygen and ssh-copy-id.

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file.
ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

1, Create public and private keys using ssh-key-gen on local-host

me@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host
Step 2: Copy the public key to remote-host using ssh-copy-id

me@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
    me@remote-host's password:

Now try logging into the machine, with
ssh 'remote-host'"
 check in .ssh/authorized_keys

Login to remote-host without entering the password

me@local-host$ ssh remote-host
Last login: Sun Nov 15 12:22:33 2008 from 191.128.6.2

me@remote-host$   [Note: You are on remote-host here]

Sunday, 10 August 2014

Regex way of saying "search until X but not including X" is:

Regex way of saying "search until X but not including X" is:
(?:(?!X).)*
where X can be any regular expression.
This is using a lookahead assertion, more specifically a negative lookahead.  Explanation:
(?:       # Match the following any number of times: 
 (?!lazy) # (first assert that it's not possible to match "lazy" here  
 .        # then match any character  
)*        # end of group, zero or more repetitions.

Tuesday, 29 July 2014

PHP onject to array

Handy bit of PHP to convert and object to an array 
 
public function objectToArray($obj) 
{
    if(!is_array($obj) && !is_object($obj)) 
    return $obj;

    if(is_object($obj)) 
    $obj = get_object_vars($obj);

    return array_map(array($this, 'objectToArray'), $obj);
}

Wednesday, 23 July 2014

Mobile DJ site for Somerset and Bristol.

The website for Keith Hards Wedding and Mobile  DJ Somerset is now live, bookings can be made from January 2015. I will be available throughout Somerset and Bristol, have an all new setup including 8 scanner lights, Wharfedale Pro sound system and windup truss system.

Tuesday, 24 June 2014

VMware network problem after sleep and wakeup on windows

After putting your windows machine to sleep and waking up, you will most likely find that the networking no longer works. I have encountered this problem on several machines.

Not to fear I have a solution.

Create a windows batch file .bat and insert the following commands. These commands will reset the VMware network adaptor.

net stop vmnetbridge
net start vmnetbridge
pause


You will need to execute the batch file as Administrator

Wednesday, 11 June 2014

Shameless plug for my fathers online model engine store

My dad's online model engine shop nitrosteamengines.co.uk looks like it needs a bit of an update. It's time to drop oscommerce as good as it's been over the last 5/6 years!
Time to investigate Magento, OpenCart and Zen Cart to see if they will offer a better solution.

Monday, 24 February 2014

PHP Array to stdClass <–> stdClass to Array

Function to Convert stdClass Objects to Multidimensional Arrays

<?php
 
 function objectToArray($d) {
  if (is_object($d)) {
   // Gets the properties of the given object
   // with get_object_vars function
   $d = get_object_vars($d);
  }
 
  if (is_array($d)) {
   /*
   * Return array converted to object
   * Using __FUNCTION__ (Magic constant)
   * for recursive call
   */
   return array_map(__FUNCTION__, $d);
  }
  else {
   // Return array
   return $d;
  }
 }
 
?>

Function to Convert Multidimensional Arrays to stdClass Objects

<?php
 
 function arrayToObject($d) {
  if (is_array($d)) {
   /*
   * Return array converted to object
   * Using __FUNCTION__ (Magic constant)
   * for recursive call
   */
   return (object) array_map(__FUNCTION__, $d);
  }
  else {
   // Return object
   return $d;
  }
 }
 
?>

Function usage

 // Create new stdClass Object
 $init = new stdClass;
 
 // Add some test data
 $init->foo = "Test data";
 $init->bar = new stdClass;
 $init->bar->baaz = "Testing";
 $init->bar->fooz = new stdClass;
 $init->bar->fooz->baz = "Testing again";
 $init->foox = "Just test";
 
 // Convert array to object and then object back to array
 $array = objectToArray($init);
 $object = arrayToObject($array);
 
 // Print objects and array
 print_r($init);
 echo "\n";
 print_r($array);
 echo "\n";
 print_r($object);
Test output:
stdClass Object
(
    [foo] => Test data
    [bar] => stdClass Object
        (
            [baaz] => Testing
            [fooz] => stdClass Object
                (
                    [baz] => Testing again
                )

        )

    [foox] => Just test
)

Array
(
    [foo] => Test data
    [bar] => Array
        (
            [baaz] => Testing
            [fooz] => Array
                (
                    [baz] => Testing again
                )

        )

    [foox] => Just test
)

stdClass Object
(
    [foo] => Test data
    [bar] => stdClass Object
        (
            [baaz] => Testing
            [fooz] => stdClass Object
                (
                    [baz] => Testing again
                )

        )

    [foox] => Just test
)