Made of Everything You're Not

Personal blog of PHP programmer Eric Lamb.
  • Blog
  • Portfolio

Archive for March, 2009

Google Visualization API Primer

Posted in Code, Programming on March 30th, 2009 by Eric Lamb – 0 Comments

The Google Visualization API is a JavaScript API for creating those fancy graphs and charts Google displays in all their cool toys like Google Analytics. There's just an obnoxious amount of chart types available in the Visualization API Gallery that include code samples along with every example. There's also the incredible Google Ajax API Playground which lets you play with the API and see real-time output.

Google Visualization

According the official website:

The Google Visualization API lets you access multiple sources of structured data that you can display, choosing from a large selection of visualizations. Google Visualization API enables you to expose your own data, stored on any data-store that is connected to the web, as a Visualization compliant datasource. Thus you can create reports and dashboards as well as analyze and display your data through the wealth of available visualization applications. The Google Visualization API also provides a platform that can be used to create, share and reuse visualizations written by the developer community at large.

I have no real interest in publishing public widgets and I've only used the API by generating the data declarations; so far anyway. That's actually what's so compelling about the API; since it's JavaScript based the API can be used with any server side language.

I'm mostly interested in using the charts and graphs for displaying data from a database on a website so that's all this article is going to focus on.

One more thing to keep in mind; the API is just JavaScript. There's nothing too fancy or random being done so even though the below may look complicated don't forget; IT'S JUST JAVASCRIPT.

Examples

Line Chart

Line Chart

<script type="text/javascript">
	google.load("visualization", "1", {packages:});
	google.setOnLoadCallback(drawChart);
	function drawChart() {
		var data = new google.visualization.DataTable();
		data.addColumn('string', 'Date');
		data.addColumn('number', 'Clicks');
		data.addRows(15);
		data.setCell(0, 0, 'March 14, 2009');
		data.setCell(1, 0, 'March 15, 2009');
		data.setCell(2, 0, 'March 16, 2009');
		data.setCell(3, 0, 'March 17, 2009');
		data.setCell(4, 0, 'March 18, 2009');
		data.setCell(5, 0, 'March 19, 2009');
		data.setCell(6, 0, 'March 20, 2009');
		data.setCell(7, 0, 'March 21, 2009');
		data.setCell(8, 0, 'March 22, 2009');
		data.setCell(9, 0, 'March 23, 2009');
		data.setCell(10, 0, 'March 24, 2009');
		data.setCell(11, 0, 'March 25, 2009');
		data.setCell(12, 0, 'March 26, 2009');
		data.setCell(13, 0, 'March 27, 2009');
		data.setCell(14, 0, 'March 28, 2009');	  
                data.setCell(0, 1, 5);
		data.setCell(1, 1, 13);
		data.setCell(2, 1, 27);
		data.setCell(3, 1, 15);
		data.setCell(4, 1, 12);
		data.setCell(5, 1, 15);
		data.setCell(6, 1, 8);
		data.setCell(7, 1, 9);
		data.setCell(8, 1, 15);
		data.setCell(9, 1, 12);
		data.setCell(10, 1, 8);
		data.setCell(11, 1, 21);
		data.setCell(12, 1, 10);
		data.setCell(13, 1, 7);
		data.setCell(14, 1, 3);
 
		var chart = new google.visualization.LineChart(document.getElementById('click_chart_div'));
		chart.draw(data, {width: 500, height: 240, legend: 'bottom', title: 'Click Tracks by Date'});
	}
</script>
<div id='click_chart_div' style='width: 650px; height: 240px;'></div>

Pie Chart

Pie Chart

<script type="text/javascript">
google.load("visualization", "1", {packages:});
google.setOnLoadCallback(drawChart);
function drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Day');
	data.addColumn('number', 'Clicks');
	data.addRows(7);
	data.setValue(0, 0, 'Monday');
	data.setValue(0, 1, 56);
	data.setValue(1, 0, 'Tuesday');
	data.setValue(1, 1, 93);
	data.setValue(2, 0, 'Wednesday');
	data.setValue(2, 1, 21);
	data.setValue(3, 0, 'Thursday');
	data.setValue(3, 1, 28);
	data.setValue(4, 0, 'Friday');
	data.setValue(4, 1, 14);
	data.setValue(5, 0, 'Saturday');
	data.setValue(5, 1, 17);
	data.setValue(6, 0, 'Sunday');
	data.setValue(6, 1, 24);
 
	var chart = new google.visualization.PieChart(document.getElementById('day_chart_div'));
	chart.draw(data, {width: 500, height: 400, is3D: true, title: 'Clicks By Day', backgroundColor: '#f9f9f9', legend: 'top', legendBackgroundColor: '#f1f1f1'});
}
</script>

PhpDelicious: Wrapper for del.icio.us API

Posted in Code, Programming on March 27th, 2009 by Eric Lamb – 5 Comments

Here's a cool little php class for managing a delicious feed; PhpDelicious. According to the official site:

PhpDelicious is a PHP 5 library for accessing the del.icio.us API. It combines data from the main REST and JSON APIs and presents a consolidated interface. It also implements a file based caching system which eliminates the need to query on every request and ensures access to the API won't be throttled due to excessive requests.

delicous

The class is really well written for php5 only but it could be rewritten in php4 with a bit of work and third-party modules. phpDelicious does have some requirements though:

  • PHP 5
  • CURL (or can use normal file reading functions if suitable URL wrappers installed)
  • json_decode function for JSON API based methods (native in PHP 5.2 and above)
  • XML Parser Functions

phpDelicious started in 2006 and has quite a few updates up to July of 2008 (I don't know if it's dying or if there's nothing left to do...).

The class includes an example script that shows how to pull everything and add a single item that should get anyone up and running ASAP.

Usage Examples

Here are a couple examples to get you started:

Instantiate Session

<?php
require('php-delicious.inc.php');
define('DELICIOUS_USER', 'YOUR_USER');
define('DELICIOUS_PASS', 'YOUR_PASS');
$oDelicious = new PhpDelicious(DELICIOUS_USER, DELICIOUS_PASS);
?>

The above needs to be done before the below will work...

Add an Item to Bookmarks

<?php
$aPost = array();
$aPost = 'http://www.yahoo.com';
$aPost = 'Yahoo! home page';
$aPost = 'Lame search engine';
$aPost = date('Y-m-d H:i:s'); //mysql timestamp
$aTags = array('lame','dumb','search engine'); //must be array
$oDelicious->AddPost($aPost, $aPost, $aPost, $aTags, $aPost, true);
?>

Delete a Bookmark

<?php
$sUrl = 'http://www.yahoo.com';
$oDelicious->DeletePost($sUrl);
?>

Grab All Bookmarks

<?php
if ($aPosts = $oDelicious->GetAllPosts()) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost.'">'.$aPost.'</a>';
        echo $aPost;
        echo $aPost;
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab Some Bookmarks

<?php
$sTag = '', // filter by tag
$sDate = '', // filter by date - format YYYY-MM-DD HH:MM:SS
$sUrl = '' // filter by URL
if ($aPosts = $oDelicious->GetPosts($sTag,$sDate,$sUrl)) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost.'">'.$aPost.'</a>';
        echo $aPost;
        echo $aPost;
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab Recent Bookmarks

<?php
$sTag = '', // filter by tag
$iCount = 15 // number of posts to retrieve, min 15, max 100
if ($aPosts = $oDelicious->GetRecentPosts($sTag,$iCount)) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost.'">'.$aPost.'</a>';
        echo $aPost;
        echo $aPost;
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab All Tags

<?php
if ($aTags = $oDelicious->GetAllTags()) {
    foreach ($aTags as $Tag) {
        echo $Tag;
        echo $Tag;
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Rename a Tag

<?php
$sOld = 'foo';
$sNew = 'bar';
$oDelicious->RenameTag($sOld, $sNew);
?>

Grab All Dates

<?php
if ($dDates = $oDelicious->GetDates()) {
    foreach ($dDates AS $Date) {
        echo $Date;
        echo $Date;
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Additional Functionality

After going through the class, it seems there's some more functionality available. I have no idea what the purpose of the below calls are for though.

I tried looking through Delicious for references to "bundles", "network" and "fans" but I couldn't find anything about them though I was pretty lazy about it. Of course, I don't really use Delicious too intensely so this could be standard, no brainer, stuff to the "real" users.

Please note though: I WAS NEVER ABLE TO GET THE BELOW TO RETURN ANYTHING BUT ERRORS. I only include them here for completeness.

Get Url Details

<?php
if ($dLinkDetails = $oDelicious->GetUrlDetails()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Network

<?php
$sUsername = 'USERNAME_TO_CHECK';
if ($dNetworkDetails = $oDelicious->GetNetwork($sUsername)) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Your Network

<?php
if ($dMyNetworkDetails = $oDelicious->GetMyNetwork()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get User Fans

<?php
$sUsername = 'USERNAME_TO_CHECK';
if ($dFansDetails = $oDelicious->GetFans($sUsername)) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Your Fans

<?php
if ($dMyFansDetails = $oDelicious->GetMyFans()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Please keep in mind what I said above; I was never able to get the fans, bundle and URL details functionality to work properly.

Still, PhpDelicious makes it really easy to do minor jobs against your delicious data.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:

AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file
  2. choose "AxCrypt"
  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok

To decrypt:

  1. right click over archive
  2. choose "AxCrypt"
  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok

If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:

AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file
  2. choose "AxCrypt"
  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok

To decrypt:

  1. right click over archive
  2. choose "AxCrypt"
  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok

If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:

AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file
  2. choose "AxCrypt"
  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok

To decrypt:

  1. right click over archive
  2. choose "AxCrypt"
  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok

If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:
AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file

  2. choose "AxCrypt"

  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok


To decrypt:

  1. right click over archive

  2. choose "AxCrypt"

  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok


If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:
AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file

  2. choose "AxCrypt"

  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok


To decrypt:

  1. right click over archive

  2. choose "AxCrypt"

  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok


If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:
AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file

  2. choose "AxCrypt"

  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok


To decrypt:

  1. right click over archive

  2. choose "AxCrypt"

  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok


If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

axcrypt

According to their site:
AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file

  2. choose "AxCrypt"

  3. choose "Encrypt"

    AxCrypt Encrypt

  4. enter a passphrase

    AxCrypt Enter Passphrase

  5. click ok


To decrypt:

  1. right click over archive

  2. choose "AxCrypt"

  3. choose "Decrypt"

    AxCrypt Decrypt

  4. enter passkey

    axcrypt_decrypt_enter_passphrase

  5. click ok


If you need to share sensitive files between people this is a really nice project.

AxCrypt File Encryption for Windows

Posted in IT on March 26th, 2009 by Eric Lamb – 0 Comments

AxCrypt is a pretty nice open source (OSS) encryption program for Windows. What makes me want to write about it though is that it integrates directly with Windows Explorer and includes a right click context menu for easier manipulation of files so there isn't a program that has to be started or opened (I always hate the wait for a program to start up...).

[caption id="attachment_1230" align="aligncenter" width="191" caption="axcrypt"]axcrypt[/caption]

According to their site:
AxCrypt is the leading open source file encryption software for Windows. It integrates seamlessly with Windows to compress, encrypt, decrypt, store, send and work with individual files.

AxCrypt is pretty straight forward;

To encrypt:

  1. right click over a file

  2. choose "AxCrypt"

  3. choose "Encrypt"

    [caption id="attachment_1238" align="aligncenter" width="300" caption="AxCrypt Encrypt"]AxCrypt Encrypt[/caption]

  4. enter a passphrase

    [caption id="attachment_1239" align="aligncenter" width="279" caption="AxCrypt Enter Passphrase"]AxCrypt Enter Passphrase[/caption]

  5. click ok


To decrypt:

  1. right click over archive

  2. choose "AxCrypt"

  3. choose "Decrypt"

    [caption id="attachment_1240" align="aligncenter" width="300" caption="AxCrypt Decrypt"]AxCrypt Decrypt[/caption]

  4. enter passkey

    [caption id="attachment_1241" align="aligncenter" width="279" caption="AxCrypt Enter Passphrase"]axcrypt_decrypt_enter_passphrase[/caption]

  5. click ok


If you need to share sensitive files between people this is a really nice project.
« Older Entries
  • Subscribe: Entries | Comments
  • About Me

    Email Email
    Twitter Twitter
    310.739.3322
  • Categories

    • Brain Dump
    • Business
    • Code
    • IT
    • Programming
    • Rant
    • Servers
  • Archives

    • February 2012
    • October 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Advertisement

Copyright © 2008 - 2013 Eric Lamb - All rights reserved