Navarr's Tech Side The Technical Side of my Life

28Jun/100

Magical Typesetting in PHP

So, well working for Route 50 I came up with a fantastic idea for “typesetting” that well exceeded the norm.  Something we constantly have issues with is what type of string was sent to MySQL originally (some of us have different conventional ideas about where escaping HTML should be located.) as well as outputting that string in its correct format.

Me, with my fantastic idea, came up with a couple variables classes that I put in a file named class_typesetting.php.  The version on gist.github is slightly modified from the original version on the server.

It creates three classes, GenericVariable, String, and Number.  So far we haven’t used GenericVariable, but since the introduction of the classes I’ve taken it upon myself to introduce them to any new code I write.  When we create Core v5 (which will Objectify everything) strings taken from SQL will automatically be re-stored as String class variables.

First, lets examine some useful functionality.

<?php
$title = new String($_POST[“title”]); // <strong>Hello 'World'</strong>
?>
HTML Output: <?= $title->html ?> (&lt;strong&gt;Hello 'World'&lt;/strong&gt;)
Text Output: <?= $title->text ?> (Hello 'World')
SQL Output: <?= $title->sql ?> (<strong>Hello \'World\'</strong>)
HTML Attribute Output: <?= $title->html_attr ?>(&lt;strong&gt;Hello &#039;World&#039;&lt;/strong&gt;)

This allows for quick and easy access to the variables without having to worry about escaping them.

I recommend you hit the download link (class_typesetting.php) and play around with it.  Tell me about anything that’s not working correctly and if possible implement it in your future code.  (This means I’m putting this code in the “Public Domain”).

1Mar/100

TwCLI

So, you think you’ve had a lot of fun with twitter on the web and all those twitter clients you’ve played around with?  What if I told you that you haven’t seen anything yet?  What if I told you that you could use Twitter in a TRUE Command Line Interface with specific commands for interacting with twitter.

Welcome to one of my latest and greatest creations, TwCLI.

TwCLI supports almost everything twitter has to offer, and will soon be expanding to support even more!  TwCLI (Click to Enlarge) TwCLI includes a long list of commands, help information for each command, a theme-able interface (Specify a Pre-Determined theme, import from your twitter profile, or even specify an external CSS file!), Geo-Location, Retweets, and even Contributor Support!

Go ahead, give it a try and tell me what you think!

25Feb/101

How to Retrieve a Zipcode Using JavaScript

// Retrieve user’s Zipcode
// Demo at http://sandbox.gtaero.net/zipcode.html
function retrieve_zip(callback)
{
	try { if(!google) { google = 0; } } catch(err) { google = 0; } // Stupid Exceptions
	if(navigator.geolocation) // FireFox/HTML5 GeoLocation
	{
		navigator.geolocation.getCurrentPosition(function(position)
		{
			zip_from_latlng(position.coords.latitude,position.coords.longitude,callback);
		});
	}
	else if(google && google.gears) // Google Gears GeoLocation
	{
		var geloc = google.gears.factory.create('beta.geolocation');
		geloc.getPermission();
		geloc.getCurrentPosition(function(position)
		{
			zip_from_latlng(position.latitude,position.longitude,callback);
		},function(err){});
	}
}
function zip_from_latlng(latitude,longitude,callback)
{
	// Setup the Script using Geonames.org's WebService
		var script = document.createElement("script");
		script.src = "http://ws.geonames.org/findNearbyPostalCodesJSON?lat=" + latitude + "&lng=" + longitude + "&callback=" + callback;
	// Run the Script
		document.getElementsByTagName("head")[0].appendChild(script);
}
function example_callback(json)
{
	// Now we have the data!  If you want to just assume it's the 'closest' zipcode, we have that below:
	zip = json.postalCodes[0].postalCode;
	country = json.postalCodes[0].countryCode;
	state = json.postalCodes[0].adminName1;
	county = json.postalCodes[0].adminName2;
	place = json.postalCodes[0].placeName;
	alert(zip);
}
retrieve_zip("example_callback"); // Alert the User's Zipcode
20Feb/100

simpleTAPI is Broken

Apparently I’ve completely broken simpleTAPI somewhere between Build 27 and Build 30.  I thought I had fixed it with Build 29, but it seems that I was mistaken.

In lieu of this, I am putting simpleTAPI on a temporary hiatus.  I will be re-constructing it from scratch (though, probably looking back and using a good bit of the original code).  The next version should have several configurable options, and will hopefully interact with the Twitter API much better than the previous versions.

Build 30 was supposed to return results as an array([“TAPI”] => data, [“result”] => data).  But all I’m getting from it at the moment is “Unable to Authenticate User.”

Those wanting to use simpleTAPI should use Build 27, though you will have to deal with some minor quirks in the way results are returned.  (the TAPI array is simply appended to the results array, making things slightly complicated if you don’t unset($result[“TAPI”]);

What will be simpleTAPI 0.4 should have better error handling, better return data, and better built-in caching.  I’m also hoping to build in support for xAuth and Delegated OAuth, if at all possible.  (Though probably not since simpleTAPI is built upon another OAuth library).

So, I’m asking for any and all feature requests.  Is there something about simpleTAPI you don’t like or want to be improved?  Please, post in the comments below!

15Dec/090

Hunting Down the Bugs – TwCLI on Chrome for Linux Beta

This is the first post of a new series, looking at some of the odder bugs encountered while developing for the expanding Web, no matter how basic a bug it may be.

Thanks to twitter user @paperfairy, a bug was discovered on my Command Line Twitter Client, TwCLI.

For some reason, when submitting a command in Chrome for Linux, the page would simply refresh, and the command would never be sent.  At first, I had no possible way to track down this bug.  I didn’t have a linux box (with a GUI, anyway) so I simply told him that it was unfortunate, but it’d have to stay a bug.  Until a recent post on lifehacker brought my attention to Portable Ubuntu. I immediately installed it, opened up the Chrome website in Firiefox, installed Chrome Beta, and headed over to TwCLI to see what was amiss.

Of course, it was a single line in a detection script to send Geo-Data to Twitter (as long as the user approved it, of course):

else if(google.gears) {

This single line was throwing an exception I hadn’t encountered in other browsers – Google wasn’t defined.  Oddly, I thought it would handle that properly, since google wasn’t defined, it would just skip over it, but instead it threw an error and halted all further javascript code.

The fix was simpler than tracking down the bug, I simply had to add this to the start of the javascript code:

try{ if(!google) { google = 0; } } catch(err) { google = 0; }

And voila, I had both a check for google, and a catch if it decided to throw errors while checking for it.

Whether this is a Chrome bug or not, I don’t know – I simply don’t know enough about JavaScript in order to say so either way.  But, are undefined variables supposed to throw errors, or are they simply supposed to return false?

11Dec/090

JavaScript & CSS3 Lightbox

Usage:

  • Call createLightbox(); to create the actual lightbox element (does not display anything).
  • Call fillLightbox(string content) to fill the lightbox with RAW HTMLor

    Call appendLightbox(element childElement) to append a DOM Node directly into the lightbox.

  • Call setLightboxSize(int width, int height, null, string unit) to set the width and height of the lightbox.  Unit will default to pixels “px” if not specified.
  • Call showLightbox() to actually display the lightbox to the user.
  • Call boolean lightboxVisible() to determine if the lightbox is still visible or not.
  • Call hideLightbox() to remove the lightbox from view.
  • Call cleanLightbox() to delete all content inside the lightbox container.
29Nov/090

Google Voice OMS Code on Github

I pushed the 子猫ちゃん Google Voice OMS service’s code to github, so you can now download it – albeit, to make it work it’ll take a lot of hacking and a lot more editing.

Either way, I’ve gotten no donations and no offers for free SSL hosting, so it looks like this project just will not be seeing the light of day.  It’s a shame, I worked a long time to make it work, and it’s obviously something a lot of business professionals would be able to find a use for.

Oh well, you can find the project on github.

Remember to abide by the Usage License!

22Nov/090

simpleTAPI v0.2.1 – Build 16 (Twitter API Library)

I’ve renamed the Twitter API Library to “simpleTAPI.”  Yes, I’m not very good at names when it comes to this sort of thing.  We’ve jumped forward two builds since my last post here.

Build 15

  • The addition of a quick variable, bool Twitter::geo_enabled.
    Returns TRUE if the user has turned on geo functionality, FALSE if not.

Version 0.2.1

  • Re-Organized classes.  Separated TwitterOAuth and OAuth into separate files, and moved them along with Twitter into a “twitter” folder.  All classes can be loaded simply by including Twitter.lib.php.

Build 16

  • Fixed a minor inconsistency in TWML where different functions returned different links to a twitter user’s profile.
  • Fixed a bug where specifying screennameonly=TRUE for TWML::name resulted in an empty hyperlink.

Examples

  • Started work on Example files to teach how to use simpleTAPI.  Currently, the only one included is a basic Update script.  This file includes logging in, updating a status, and returning the same status as well as some basic TWML examples.

So, enjoy!  I will continue to improve this library.  Please remember to post all issues and feature requests either on this blog or the github page.

19Nov/090

Twitter API Library Build 13 (Breaking Change)

I pushed Build 13 today.  This build adds the recent addition of descriptions to a user’s list.

This change breaks:

  • TwitterAPI::lists_create and
  • TwitterAPI::lists_update

The new profiles for these commands are as follows:

TwitterAPI::lists_create( str $name [, str $description = NULL [, bool $privacy = TWITTER_PRIVACY_PUBLIC ] ] )

TwitterAPI::lists_update( str $name [, str $new_name = NULL [, str $description = NULL [, bool $privacy = NULL ] ] ] )

17Nov/090

Twitter API Library Build 12

If you’ve been watching this blog, you’ll notice I skipped Build 11 – It was small, and was trumped by its quick replacement – Build 12.  Builds 11 and 12 fixed five previous known issues, while build 12 fixed a non-issue with build 11.  Fixes listed below:

  • The following now work with all users:
    • Twitter::get_sn_from_id()
    • Twitter::get_name_from_id()
    • Twitter::get_id_from_sn()
    • TWML::name()
    • TWML::profile_pic()
  • Addition of User Cache commands for use by TWML and the get_x_from_y() commands.

As always, the most recent build is available at github.