SimpleCrypt PHP class for simple cryptography

Posted by Glen on . One comment.

I have just pushed a simple class called SimpleCrypt to GitHub:

https://github.com/glenscott/simple-crypt

This is an OO wrapper around the most common mcrypt functions. An example of use:

require_once 'SimpleCrypt.php';

// show the algorithms available for use
print_r( SimpleCrypt::get_available_algorithms() );

// encrypt a string using Triple DES (CBC mode)
$crypt = new SimpleCrypt( 'tripledes', 'mysecretkey' );
$encrypted_data = $crypt->encrypt_data( 'stringtoencrypt' );
echo "Encrypted data: " . bin2hex( $encrypted_data ) . "\n";
echo "Decrypted data: " . $crypt->decrypt_data( $encrypted_data ) . "\n";

If you find it useful, please let me know!

Mac OS X 10.7.3 upgrades PHP from 5.3.6 to 5.3.8

Posted by Glen on . No comments.

As described in Apple’s security notes for Mac OS X 10.7.3, PHP is upgraded to version 5.3.8 as part of the update.

Map invoke errors when using MongoDB MapReduce

Posted by Glen on . No comments.

When running MapReduce operations on your data, you must make sure that any fields you refer to within your map operation are available for every document in your collection. If you try a map operation and some documents do not have the required field, you will get the following assertion error when running the command:

map invoke failed: JS Error: TypeError: this.fieldname has no properties

fieldname in this case is a field that does not exist in all of the documents.

To prevent this error, you can pass the optional query parameter to the command to make sure that only documents with this field are queried. For example, in PHP, add the following to the command operation:


$db->command(
    'mapreduce' => 'collection',
    'map'       => $map,
    'reduce'    => $reduce,
    'out'       => array( 'inline' => 1 ),
    'query'     => array( "fieldname" => array( '$exists' => true, ) )
);

This makes sure that MapReduce operations are only run on a subset of the collection.

Complaining to Virgin Media

Posted by Glen on . No comments.

spacer

Yesterday, the 17th January 2012, Virgin Media broadband customers experienced partial or total loss of connectivity throughout the afternoon and evening. As one of those customers affected by the outage, I am making a formal complaint to the company. As I work from home and require internet connectivity at all times, this outage had a serious affect on my business.

For others that are considering complaining, here is how you can do it — it took me a fair bit of searching to find this, so I hope this is helpful to others.

Firstly, you may wish to read Virgin Media’s Code of Practice for complaints.

To submit a complaint, you can use the web form located here:

Virgin Media – Contact Us

  1. Select General Enquiry
  2. Choose I have cable services
  3. Select Make a customer services complaint
  4. Click the red Next button at the bottom of the page

This leads you to a contact form where you can submit your complaint. You will also need you Virgin Media account number and the password you use for logging into the site.

Good luck!

Photo credit: Gene Hunt

Going Freelance – Part 3

Posted by Glen on . No comments.

spacer

In Part 2, I mentioned how I used Google Docs as a way of managing business records. Although this turned out to be a reasonable solution, I soon found myself wanting something more bespoke.

Enter FreeAgent. I heard a few other freelancers recommending this service, so I signed up for a free 30 day trial to see what the fuss was about. FreeAgent provides a way of managing your client details, invoices and tax affairs. The interface is very slick and friendly, and means keeping on top of record keeping is now much less of a chore!

I’ve now been using the paid service for 2 months and I can heartily recommend it. If you want to give it a go, you can use this link to get 10% off the subscription price of FreeAgent.

(photo credit: www.seniorliving.org)

Exporting specific documents from MongoDB

Posted by Glen on . No comments.

spacer

MongoDB comes with a useful tool, mongoexport, for exporting collections. However, you can also use it to export specific documents by utilising the query parameter. You can export a single document using it’s ObjectId using a command similar to the following:

mongoexport -h "host_name" -u "username" -d "database_name" -c "collection_name" -q '{"_id":ObjectId("4f045677a1ef264746000011")}' -o output.js -p
  • Replace host_name, username, database_name and collection_name with the appropriate values.
  • Replace 4f045677a1ef264746000011 with the ObjectID that you wish to export

You will be prompted for a password, and then the document will be written to output.js.

To export multiple documents, you can utilise an $in clause in the query parameter like this:

-q '{"_id":{"$in" :[ ObjectId("4f048dc6a1ef26da4b000008"),ObjectId("4ed8ee16a1ef26085600001a"),ObjectId("4efc46e0a1ef26b73d0007be")]}}'

To import these exported documents into another MongoDB server, you can use the mongoimport like so:

mongoimport -h "host_name" -u "username" -p -d "database_name" -c "collection_name" output.js

iCal 502 error when syncing with Yahoo! Calendar

Posted by Glen on . 14 comments.

In the last few days, my iCal has been giving me the following error message when trying to access my Yahoo! Calendar via CalDAV:

The request for account "Yahoo! Calendar" failed.

The server responded with
"502"
to operation
CalDAVAccountRefreshQueueableOperation.

spacer

Yahoo! have acknowledged this is a problem on their side:

We are aware of a Calendar (Proxy error) and our engineering team is working to resolve this issue. We apologize for the inconvenience and hope to have it resolved soon.

(source: Syncing / Mobile Sync | Yahoo! Calendar Help)

update 2nd November 2011: I am no longer seeing this error message, and Yahoo! have removed the notice from their help page. Looks like the issue has been resolved!

update 3rd November 2011: Seems like I spoke too soon, the error is back!

Camera and photo improvements in iOS5

Posted by Glen on . No comments.

spacer

The camera functionality in the iPhone has always been one of my most used features. iOS5 brings some enhancements, which are listed below:

Camera improvements

  • Double-click the Home button when device is asleep to bring up a camera shortcut on iPhone 4S, iPhone 4, iPhone 3GS and iPod touch (4th generation)
  • Volume Up button to take a picture
  • Optional grid lines to line up shots
  • Pinch to zoom in the preview screen
  • Swipe to camera roll from preview screen
  • Tap and hold to lock focus and exposure; iPad 2 and iPod touch (4th generation) only support exposure lock

Photo improvements

  • Crop and rotate
  • Red-eye removal
  • One-tap enhance
  • Organise photos into albums

This list was taken from the official release notes, which were accessible via iTunes pre-installation.

Getting started with MongoDB and PHP on Mac OS X

Posted by Glen on . No comments.

spacer

Introduction

MongoDB is a document-orientated database written with scalability and high-performance in mind. It is one of a growing number of NoSQL systems – a database that does not rely on SQL or relational theory at all.

Getting a MongoDB server working with PHP on Mac OS X is relatively straightforward, and this tutorial shows you how.

Installing the MongoDB Server

The first step requires you to download and install the actual MongoDB system. The example shown below downloads v2.0.0 64 bit binaries for OS X. For other binaries, please check out the MongoDB Downloads page.

cd /tmp
curl -O fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.0.tgz
tar zxvf mongodb-osx-x86_64-2.0.0.tgz
sudo mv mongodb-osx-x86_64-2.0.0 /usr/local/mongodb
mkdir /usr/local/mongodb/data

Configuring the MongoDB server

We need to create a small configuration file so that MongoDB knows where its data files reside. Create the file /usr/local/mongodb/mongod.conf and add the following line:

dbpath = /usr/local/mongodb/data

Starting MongoDB

To manually start the MongoDB server, use the following command:

/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongod.conf

This will start the server and will by default log all output to STDOUT.

Installing the MongoDB PHP Extension

Installing the PHP extension is simple:

sudo pecl install mongo

Once this has completed, add the following line to your /etc/php.ini file:

extension=mongo.so

Restart apache using sudo apachectl restart, and the extension should be available. This can be verified with the phpinfo call:

spacer

Example PHP script

To test your setup, the following simple script can be used to create a new collection and add two new records:

    <?php

    // connect
    $m = new Mongo();

    // select a database
    $db = $m->comedy;

    // select a collection (analogous to a relational database's table)
    $collection = $db->cartoons;

    // add a record
    $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
    $collection->insert($obj);

    // add another record, with a different "shape"
    $obj = array( "title" => "XKCD", "online" => true );
    $collection->insert($obj);

    // find everything in the collection
    $cursor = $collection->find();

    // iterate through the results
    foreach ($cursor as $obj) {
        echo $obj["title"] . "\n";
    }

    ?>

The script should output the following:

Calvin and Hobbes
XKCD

And that’s it! You now have a working MongoDB setup on Mac OS X.

For more information on the PHP extension for MongoDB, please see the following pages in the PHP Manual:

PHP: Mongo – Manual

Steve Jobs, 1955 – 2011

Posted by Glen on . No comments.

For me, it wasn’t the iPod, iPhone or iPad but the Mac that was Steve Jobs’ greatest success. After buying an indigo iMac in 2000, it reignited my passion for computing and I never looked back. The Mac made computing pleasurable, and for that I will be eternally grateful to Steve’s vision and passion. A truly inspiring man.

Thanks, Steve.

spacer

Older posts