CloudSight API PHP example

Here is an example PHP function for the CloudSight API, given there are not many examples online.

Simply input your API key and the url which could be either a local or internet file, the function will return the string description of the image.

	function cloudsightapi($key, $file_url) {
		$parse = parse_url($file_url);
		$size = getimagesize($file_url);
		$boundary = md5(time());
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_URL, "");
		if (isset($parse['host'])) {
			$headers = array('Authorization: CloudSight '.$key, "Content-Type:multipart/form-data");
			$postFields = array(
				'image_request' => array(
					'remote_image_url'  => $file_url,
					'locale' => 'en-US'
			$body = http_build_query($postFields);
		} else {
			$headers = array('Authorization: CloudSight '.$key, "Content-Type:multipart/form-data; boundary=".$boundary);
			$body  = '';
			$body .= '--'.$boundary."\r\n";
			$body .= 'Content-Disposition: form-data; name="image_request[locale]"'."\r\n\r\n";
			$body .= "en-US"."\r\n";
			$body .= '--'.$boundary."\r\n";
			$body .= 'Content-Disposition: form-data; name="image_request[image]"; filename="'.basename($file_url).'"'."\r\n";
			$body .= 'Content-Type: '.$size['mime']."\r\n";
			$body .= 'Content-Transfer-Encoding: multipart/form-data'."\r\n\r\n";
			$body .= file_get_contents($file_url)."\r\n";
			$body .= '--'.$boundary .'--'."\r\n\r\n";
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

		$ret = curl_exec($ch);
		$json = json_decode($ret, true);
		$token = $json['token'];
		$status = $json['status'];
		while ($status == 'not completed') {
			//grab the result
			curl_setopt($ch, CURLOPT_POST, false);
			curl_setopt($ch, CURLOPT_POSTFIELDS, null);
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
			curl_setopt($ch, CURLOPT_URL, ''.$token);
			$ret = curl_exec($ch);
			$json = json_decode($ret, true);
			$token = $json['token'];
			$status = $json['status'];
		$label = $json['name'];
		return $label;

Automatically reboot a TP-LINK TD-W8960N Modem through PHP script

I recently got a bit fed up of the ADSL2+ speeds I was getting and constant line resyncing. I thought I would set up a script to automatically reboot the modem when sleeping.

It turns out that previously it was very simply to reboot TP-LINK modems, but it has got a lot more difficult recently. This page, which I initially found through googling, lead me on a wild goose chase more then anything else. It turns out it was better to start from scratch, with the comments helping me to work out the username/password hashing.

One of the advantages with my script below, is I also capture the sync speeds, and you could use that to determine if the modem should be rebooted.

Naturally in my goto PHP language. Code below, simply modify username, password and modem IP.

	$username = 'admin';
	$password = 'XXXXXX';
	$ip = '';

	// code below
	$ip = "http://{$ip}/";
	$auth_enc =  base64_encode($username.':'.$password);
	$cookies = dirname(__FILE__).'/cookies-tplink.txt';
	//delete the existing cookie file, important
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
	curl_setopt($ch, CURLOPT_COOKIE, 'Authorization=Basic '.$auth_enc.';path=/');
	curl_setopt($ch, CURLOPT_REFERER, $ip);
	curl_setopt($ch, CURLOPT_URL, $ip);
	$output = curl_exec($ch);
	//grab the connection information
	curl_setopt($ch, CURLOPT_URL, $ip.'info.html');
	$output = curl_exec($ch);

	preg_match_all('%<td class=\\\\"dataStyle\\\\">(\d*?)</td>%im', $output, $result, PREG_PATTERN_ORDER);
	$Upstream = $result[1][0];
	$Downstream = $result[1][1];
	//grab session key from reboot router page
	curl_setopt($ch, CURLOPT_URL, $ip.'resetrouter.html');
	$output = curl_exec($ch);
	if (preg_match('/var sessionKey=\'(.*?)\';/im', $output, $regs)) {
		$sessionKey = $regs[1];
	//reboot the modem
	if ($sessionKey && false) {
		curl_setopt($ch, CURLOPT_URL, $ip.'rebootinfo.cgi?sessionKey='.$sessionKey);
		$output = curl_exec($ch);
		echo "Modem has been rebooted\r\n";

What are my consumer rights if a price decreases? (Australia)

I thought I would answer a question that I had recently, where I purchased and paid for a product, and then only a week later the product went on sale for lower. Unfortunately, there are no statutory consumer rights if the price decreases, unlike those for manufactures warranty, acceptable quality and fit for purpose. But thankfully, a lot of stores have very favourable return policies.

Many stores allow you to return a product if you simply change your mind, for example Ikea (WA) has a 90 day return policy, Super Amart a 30 day return policy, Big W a 30 day return policy on non-electrical items, Officeworks and Bunnings don’t have any time-limit on their returns. These are only a few examples. Now, generally, if stores offer these return policies, they generally understand that if the price decreases within this period, you should be entitled to a refund in the difference in price.

The reason for this is there is nothing stopping you from buying the product at the discounted price and then returning it on the older receipt with the higher price. The stores would probably prefer this as it means they get a returned product in original packaging.

For my recent transaction, after the store said they could not do anything about the price reduction, only when I explained I wanted to return the item and buy it at the lower price, they got the picture and put through a refund of the price difference.


How to pass the PMI Project Management Professional Certification PMP exam

Having recently passed my PMI PMP exam on the first try, I thought I would share my thoughts on how to also pass the PMP exam.

The resources

The resources I used were quite limited.

  • PMBOK – I read through once very early on when I was completing the 36 hours of coursework and never used it again.
  • PMP Exam Prep by Rita Mulcahy, was a key resource, and I’ll explain more on that shortly.
  • The PMP Exam: How to Pass on Your First Try by Andy Crowe, another key resource and very easy to read.
  • Head First PMP, Book by Andrew Stellman, an online recommendation with the other two resources, but I didn’t like the graphic format and didn’t get through the first chapter.
  • PMI PMP Exam Prep by Pocket Prep, Inc. android app, I used this more as a motivational tool and training reminders.

The questions

The PMP questions are all situational, and in my opinion the practise questions in the above resources a lot easier.

  • Plenty of network diagrams which were easy marks
  • Plenty of basic Earned Value questions, like given PV, EV and AC, what is the status of schedule and budget.
  • No ethics questions.
  • A lot of change control management questions.

The learning

Instead of memorising the process group and knowledge area map, I should have been memorising Rita Mulcahy’s process diagram. These would have helped significantly in the situation, especially for the planning domain which I was Moderately Proficient.

Airbnb coupon code new signup $50 AUD with referral

Here is an Airbnb coupon code, get $50 AUD when you take a first trip of $100 AUD or more using out referral link below:

You can also get $100 AUD when you welcome your first guest as a host.

thydzik’s MAME cabinet update

After over a decade and the MAME cabinet collecting dust, I decided to rejuvenate my MAME cabinet once again.

First to go was the 26″ KORTEK color monitor, which was roughly 30 years old. I stripped out all the legacy IPAC and JPAC harness and went with a basic USB arcade decoder, the USB to Xin-Mo Arcade 2 players with 30 inputs.

I found the Asus VW266 26” Widescreen LCD Monitor, which was the perfect width for the cabinet.thydzik-mame-cab-2016-update

thydzik’s MAME cab

Fix fading red (magenta) toner on HP Color LaserJet 2600

My HP Color LaserJet 2600N printer recently experienced the infamous faded red tones, this is due to the magenta toner being positioned at the bottom of the unit and the optics being the most susceptible to dust and debris.

Here is the details of repairing the unit based on Don Thompson’s Service Seminars whitepaper found at the end of this post.fix-fading-red-magenta-toner-on-hp-color-laserjet-2600-the-unit

The HP LaserJet 2600N printer, first remove all the toner, the paper trays and the output trays. Then remove the screw on the left hand side of the unit near the paper tray.

fix-fading-red-magenta-toner-on-hp-color-laserjet-2600-unscrew-the-screw-at-footerUnclip the plastic hook and remove the left hand side plastic cover.

Unclip plastic clip

Unclip plastic clip

Do the same for the screw on the right hand side of the unit near the paper tray.

Remove right hand screw near paper tray

There is a second screw to remove near the network ports. Then remove the right hand plastic cover.

Remove screw near network ports

Remove the nine screws from the back of the unit.

Remove nine screws from back

Remove all connectors as circled, all the plugs are different sizes making it easy to reassemble. Care should be taken removing the ribbon cables as they are similar sized. Also remove the black cable trays by sliding them to the left to release the catches.

Remove all connectors as circled

Remove total eleven screens, those in the photo and those under removed cable trays and ribbon cables.

Remove the circled screws and those under cable tray

Lift the PCB plate away revealing the black box of optics. Unscrew the screws holding the black box.

The scanner optics box

Remove the single screw at the bottom of the printer holding the optics box in place. Remove the optics box.

Screw at bottom of optics

Once the optics box is removed, unclip the spring to allow access inside.

Optics box

Using an air blowing brush similar to those used on DSLR cameras, clean all the lens and mirrors.

Opened optics box

Reassemble everything in reverse order. Care should be taken making sure the ribbon cables are seated in both ends.

Further details can been found in Don Thompson’s Service Seminars whitepaper.


Hyundai does not recommend an engine flush during routine service

I recently had my Hyundai Tucson services with the Hyundai authorised dealer recommending an engine flush, even prior to inspecting the vehicle. An ‘engine flush’ clears the gunk out of your engine by pouring a chemical into the engine and idling. Due to the use of chemicals, it can possibly be damaging to modern car’s engines.

I was concerned due to no mentioned of an engine flush in the Hyundai Recommended Maintenance Schedules, so I contact Hyundai directly, this was their response:

I have been in contact with our technical department both locally and overseas and they have advised that Hyundai don’t recommend an [engine] flush at service.