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.

Share
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);
}
?>

Share
Feb 212011
 

I visited Weather Underground today to find a great, new, redesigned site. I always thought the old one looked cheesy and the new one is a huge improvement in my opinion. Like Lifehacker’s redesign, I was bothered with the extra white space so I used Stylish and Property Inspector in Chrome to widen it up and put the forecast module next to current conditions on the weather page.

.switch336 {
/* Only way to make it work is to hide the ad */
	display: none;
}
 
#wuPage984 {
	width: 1380px;
}
 
#innerContent {
	text-align: center;
}
 
#layerForecast {
	float: none ;
	display: inline-block ;
	margin: 20px ;
}
 
#layerCurrent {
	display: inline-block ;
	margin: 20px;
}
 
#layerRegional {
	margin: 0 auto ;
}
 
.primeContent636 {
	float: none;
	margin: 0 auto;
}
 
#hpSearch {
	margin: 12px auto;
}
 
#layerCommunity {
	float: left;
	width: 670px;
}
 
#layerTravel {
	float: right;
	width: 670px;
}
 
#layerStations {
	clear: both;
}
 
#community_details {
	margin: 0 auto;
	width: 638px;
}

There are still a few oddities when visiting other pages of the site, but this is designed for people who go straight to the weather page and don’t want to bother with scrolling down to find the 5 day. If anyone has some styles to prevent me from having to hide the large ad box, I’m open to suggestions.

Share
Feb 112011
 

The new design of Lifehacker and other Gawker sites bothered me because of the narrow view area and hash-bang, javascript only, style navigation. I haven’t finished rebuilding a clean Gawker interface without the JS, but I did whip up some styles that widen the site. You can use it with Stylebot, Stylish, Greasemonkey (if you convert it to JS).

 
#main-container {
	width: 1150px;
}
 
#container {
	width: 1100px;
	color: #ffffff;
}
 
.permalink h1.title {
	width: 750px;
}
 
.post-body {
	width: 750px;
}
 
#gallery_container {
	width: 765px;
}
 
.inner {
	width: 785px;
}
 
div.gallery_image {
	width: 770px;
	margin-top: 0;
	margin-right: auto;
	margin-left: auto;
	text-align: center;
}
 
div#thumb_navigation {
	width: 785px;
}
 
div.threadnav.chrome.tc.cn_thread_firstpage {
	width: 785px;
}
 
div.imgwrap.abovewrap {
	width: 780px;
	text-align: center;
}
 
.ad_300x250 {
	display: none;
}
 
.post img {
	display: none;
}
Share
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.

<?php
$user = urldecode($_GET['user']);
if(isset($_GET['callback'])) $callback = $_GET['callback'];
 
function getStats($name) {
		$hiscores = array("Overall",
				"stats" => 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:<br><ul>';
	echo '<li>user=username</li>';
	echo '<li>Optional: callback=funcName</li>';
	echo '<li>Optional: lowercase=yes (all json will be lower case)</li></ul><br>';
	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

Share