Apr 032016
 

Google Drive API provides a way to get the MD5 checksum of uploaded files. This can be used to verify if files uploaded correctly. I’ve created a small Javascript program that uses the Google Drive API available here: Google Drive MD5 Fetcher. You’ll need to authorize access first, then put the name of the file in the search box and it will fetch MD5s from Google. You can right-click to view source and see how it works.

May 072012
 

Here’s a basic script I made that uses PHP, cURL, and barcoding.com. It reads UPCs from csv files (or just a list) and sends a request to barcoding.com. Barcoding.com then returns an image with the barcode. Keep in mind barcoding.com is a free service and isn’t designed to be used in the way this script uses it, so please use it carefully.


<?php
$file = 'upcs.csv'; // Path to CSV file
$field = 0; //Column number of the UPC (0 if in the first column, 1 for the 2nd column, etc)
$output = 'C:\\upcs\\'; //Directory to save outputted UPCs to

$csvFile = fopen($file, "r"); //open the csv file for reading
while($data = fgetcsv($csvFile)) { //for each, add upc to array
if(strlen($data[$field]) === 12) { //prevent from adding data that isn't a 12 digit upc
$upcA[] = $data[$field];
}
}
fclose($csvFile);

function saveBarcode($url, $code) {
global $output;
$url = "http://www.barcoding.com".$url;
$ofile = "$output$code.png";
if(@$out = fopen($ofile, "x")) { // prevent problems when the file already exists
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FILE, $out);
curl_exec($ch);
curl_close($ch);
fclose($out);
}
}

function makeBarcode($code) { //generates barcode image from upc using barcoding.com
$url = "http://www.barcoding.com/upc/buildbarcode.asp?cpaint_function=BuildBarcode&cpaint_argument[]=$code&cpaint_argument[]=9&cpaint_argument[]=5&cpaint_response_type=TEXT";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$url = curl_exec($ch);
curl_close($ch);
saveBarcode($url, $code);
}

foreach($upcA as $upc) {
makeBarcode($upc);
}
?>

Sep 052010
 

Runescape offers an interface for fansites to grab hiscores info without having to load the entire hiscores page and use complicated scripts to pull out each piece. You can get the info by visiting this page: http://hiscore.runescape.com/index_lite.ws?player=yourusername

The page will feed back info in line break and comma separated form. Each skill is separated by a line break and rank/level/xp are seperated by commas. In its default form it’s not very usable, you’d need to write some sort of script to format it. I was bored and decided to make a PHP script that converts the page into JSON format, making it very easy to use with a Javascript front-end.

 array(        
						"Attack", "Defence", "Strength",
						"Hitpoints", "Ranged", "Prayer",
						"Magic", "Cooking", "Woodcutting",
						"Fletching", "Fishing", "Firemaking",
						"Crafting", "Smithing", "Mining",
						"Herblore", "Agility", "Thieving",
						"Slayer", "Farming", "Runecrafting",
						"Hunter", "Construction", "Summoning",
						"Dungeoneering"
						),
				"minigames" => array(
						"Duel Tournaments", "Bounty Hunters",
						"Bounty Hunter Rogues", "Fist of Guthix",
						"Mobilising Armies", "B.A Attackers",
						"B.A Defenders", "B.A Healers",
						"Castle Wars Games", "Conquest"
				)
		);
		$name = strtolower($name);
		$connection = fopen('http://hiscore.runescape.com/index_lite.ws?player='.$name, 'rb');
		if($http_response_header[0] === 'HTTP/1.1 200 OK') {
			$data = stream_get_contents($connection);
			$data = explode("\n", $data);
			$overall = explode(',', $data[0]);
			$stats['overall'] = array("Rank" => $overall[0], "Level" => $overall[1], "XP" => $overall[2]);
			for($i = 0; $i < 25; $i++) {
				$cItem = $hiscores['stats'][$i];
				$num = explode(',', $data[$i+1]);
				$stats['skills'][$cItem] = array("Rank" => $num[0], "Level" => $num[1], "XP" => $num[2]);
			}
			for($i = 0; $i < 9; $i++){
				$cItem = $hiscores['minigames'][$i];
				$num = explode(',', $data[$i+27]);
				$stats['minigames'][$cItem] = array("Rank" => $num[0], "Score" => $num[1]);
			}
			
			$stats = json_encode($stats);
			$stats = str_replace('-1', '', $stats);
			if($_GET['lowercase'] === 'yes'){
				$stats = strtolower($stats);
			}
			return $stats;
		}
		else {
			return '{"error":"User not found"}';
		}
		fclose($connection);
}

if(isset($_GET['user'])) {
	$cStats = getStats($user);
	if(isset($callback)) {
		echo $callback.'('.$cStats.')';
	}
	else
	{
		echo $cStats;
	}
}
else
{
	echo 'Usage:
    '; echo '
  • user=username
  • '; echo '
  • Optional: callback=funcName
  • '; echo '
  • Optional: lowercase=yes (all json will be lower case)

'; echo 'Callback function is used for cross-domain AJAX requests'; } ?>

You can access the script here or download it here. For usage information visit the script page.
Old School Runescape version available here

JSON Formatter for Runescape Hiscores by pceasies is licensed under a Creative Commons Attribution-Share-Alike 3.0 Unported License