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

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.

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;
}
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');
		$data = stream_get_contents($connection);
		fclose($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;
}
 
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.

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

Aug 232010
 

The Graph API gives you access to public information. If you need more you have to have an access token. There are a couple of ways of gaining one, but first you need to create an application and get an App ID & App Secret.

  1. Create application here: http://www.facebook.com/developers/
  2. Click Setup Application in the upper right and follow the steps
  3. Create a link to the auth page:
    1. https://graph.facebook.com/oauth/authorize?client_id=APP-ID-HERE&redirect_uri=http://URL-TO-REDIRECT-TO&scope=read_stream&type=user_agent
    2. client_id should be set to your application ID. You can find it on this page.
    3. redirect_uri is the URL you want Facebook to redirect to with the access token in the URL in this format: http://example.com/facebook-app.php#access_token=452452ACCESS-TOKEN-HERE
  4. When the user clicks the link they will be brought to a Facebook Allow/Deny app page. If you need additional permissions such as access to feeds you’ll have to configure scope (&scope=read_stream,read_friendlist). Read here for more information.
  5. After the user allows the app they will be forwarded to the redirect_uri and the access token will be in the URL in the format mentioned above.

This code can be used to pull the access token out of the URL:

?View Code JAVASCRIPT
var url = location.href;
var access_token = url.split('=')[1].split('&')[0];
/* Assumes default format without any parameters/variables added to the url by the user */

The access token can be accessed via the “access_token” variable