Data, Maps, Usability, and Performance

API canvas d3 data geo GeoJSON html5 image JavaScript json maps mysql PHP WordPress

Results for tag: PHP

Leaflet Map with UTFGrid and PHP Served Mbtiles

Leaflet Maps, UTFGrid, MapBox, TileMill, and Mbtiles

Final Demo: Largest Cities on Leaflet Map

It has been fun visualizing all kinds of data with D3, Raphael, OpenLayers, MapBox, PolyMaps, and ModestMaps, but now I really want to dig into Leaflet and UTFGrid. UTFGrid is a concept created by MapBox to improve the performance of map interaction across browsers when you are dealing with large amounts of vector data. In more detail, UTFGrid rasterizes polygons and points in JSON as a grid of text characters to enable fast lookups. It is as amazing and simple as it sounds and Leaflet has a UTFGrid plugin among its many great plugins.

Today I will show a basic example of Leaflet, demonstrate how to use MapBox maps in Leaflet, create a map out of city data in TileMill with UTFGrid, serve those map image tiles with PHP from my own server, and put it all together to create a demo of a fast dynamic Leaflet map with top 1,000 cities by population.
Read more

Traceroute on a Map using Pingdom API, MaxMind, and D3

Visualizing traceroute on a map

Today, I was looking at the traceroute module for NodeJS and was thinking about combining the results of a traceroute with a geolocation service that translates the IP addresses into Geo coordinates that can be placed on a world map built with D3. MaxMind Geolocation database seemed like a good idea and I was trying to figure out how to do that on Redis for nodeJS. Then I stumbled on GeoIP which seems to make it easier to use MaxMind with Node. Actually, Philip Tellis created geoip-lite which is a native NodeJS API for the GeoLite data from MaxMind. MapTail, for example, uses geoip-lite to display visitors on a realtime map.

But, I do not have a public server with NodeJS and when I noticed that Pingdom tools has a traceroute method in their API, I decided to implement this project in PHP, using curl to retrieve traceroute information from the Pingdom API, converting IP to location using MaxMind on MySQL, and placing the geo coordinates on a D3.js map. Let’s get started.
Read more

LastFM API with PHP

Using the Last.FM API

Today I needed to quickly retrieve and store music artist photos and album covers. After looking around, I decided that Last.FM is a good place to do that and I signed up for an API key. I want to provide an artist name and run some API calls that will grab an artist photo, retrieve the top albums, and allow me to also search for a particular album. I also want to store these images on disk and convert everything to JPG format. Considering these use cases, I decided to code this up in PHP but any other server side language would also be fine. Here is my script and I am also going to include links to other implementations of pulling data from Last.FM using their API.
Read more

Tumblr API Example using oAuth and PHP

Tumblr API with PHP

I was recently looking at the Tumblr API and oAuth implementation in PHP. At the time, I did not have access to my server to install John Jawed’s oauth pecl package so I looked elsewhere. I did not find a lot of good examples of using oAuth with just PHP, most demos showed using username and password credentials through the old version of the Tumblr API. I wanted to see a complete oAuth example with PHP. Finally, I did find the a thread on the Tumblr API discussion group which had a really simple and well commented example of using oAuth with a modified version of Abraham’s TwitterOAuth library adapted to support the new Tumblr API. I downloaded the zip and was able to make it work, connecting to Tumblr, pressing Allow, and then making some API calls.

But, the example did not show how to make API calls without constantly needing to authenticate the application (press Allow) and I wanted to see an example of just uploading pictures to Tumblr without the extra step. When you register an application with Tumblr, you get an OAuth Consumer Key and a Secret Key for you API calls and oAuth authentication. You also specify a callback url, a place where Tumblr will send you upon successful authentication. Now, it’s important to note that some methods only require the API key (blog info, posts, likes) but any content creation requires oAuth authentication and below I will go over the basic steps of OAuth and explain how to make a post to Tumblr using oAuth, PHP, and a single API call:
Read more

Online Screenshot Generator with Imgur

wp screenshot service

As I have mentioned previously, WordPress has a great screenshot service that allows you to make quick screenshots from any valid url. The image above is a WordPress generated screenshot, just look at the source of this page. People like to visualize things, so screenshots in articles can improve the user experience and it’s nice to offload the work to a third party (WordPress). However, dynamically generated screenshots have a performance cost and it’s kind of wasteful to keep asking WordPress to regenerate the same screenshot when my use case only needs a screenshot generated once.
Read more

30 Code Playgrounds and Sharing Tools

code toolbox

Most people know about jsFiddle because it is an amazing tool that allows you to quickly test and share small pieces of code. No wonder my jsFiddle examples post is getting a ton of traffic. But, there are many other awesome web based sandbox testing tools that you might find useful. Did you know that there are SQL and NodeJS sandboxing tools out there? It is so convenient to quickly mess around with code online and collaborate with other programmers. Below you will find some of the best free code playgrounds and sandboxing tools for testing, debugging and sharing your code snippets (I put my favorites in bold).
Read more

Better Typos Generator Based on Common Misspellings

common typos

Previously, I wrote about generating typos based on misplacing your finger on a keyboard, or proximity based misspelling. But, another way to think about typos is to consider the words that people generally misspell. If you could query a list of misspelled words, it would be pretty easy to search and replace correct word or words with typos. Generally, the use case is for the reverse, correcting someone’s typos, but in some cases I think you could get some extra SEO juice from generating a couple typos for your main keywords. So, the idea is that I will pass a phrase, perhaps a title of some blog entry, and a function will return an array of phases with common misspellings of different words in the phrase. But first, let’s start with a list of common typos.
Read more

Typos Script to Generate Misspellings

SEO Typos Script

I was thinking about misspellings recently and wanted to put together a small PHP script that will generate typos from a given word. The idea is based around typos being generated based on proximity of other letters or numbers next to the correct character on a keyboard. There are other ways to think about misspellings, but it makes sense that most typos occur as a result of a user accidentally pressing the wrong key. So, we just create an array for each key, which has all the surrounding keys, and then use these arrays in a loop which replaces characters in a string with other characters that are close in proximity on the keyboard.
Read more

A-Z Category Index WordPress Plugin

Category WordPress Plugin

If you have a lot of categories on your WordPress website, you might want to organize these categories by each alphabetical letter. In other words, build an A-Z index that allows an end user to click on any letter, which then loads a page that lists all the categories that start with that letter. This is often the design or interaction in music websites which deal with many artists and albums.

I noticed that some people have been looking for this type of WordPress plugin but most of the plugins I have found for such organization have been developed around posts not categories. So, I decided to build this plugin, but more importantly, document the process, as this WP plugin will make a new table in the database, runs queries, hook into WordPress actions, leverage a page template, and much more.

My first thought is that you could manually create this A-Z index, create all the pages for each letter, create a template file for these pages where you would grab all the categories and loop through them to retrieve the correct categories per letter. The small problem with that approach is that it is manual work and the big problem is that it is not going to perform very well when you have 100s if not 1000s of categories.
Read more

HTML5 GeoLocation Address Form Filler

HTML5 GeoLocation Address Plugin

I have recently filled out an address form and realized that HTML5 GeoLocation could really improve this user experience. Why do I have to fill in my city, state and zip when the browser can figure this all out with the GeoLocation API. Actually, the browser can only retrieve your Geo coordinates but I have already blogged about converting latitude and longitude coordinates to a street address via various APIs. So, it only makes sense to put in a button on an address form which would allow the end user to retrieve that information programmatically. Sure, the street address could be off sometimes but you can always correct the form instead of writing everything from scratch. So, let’s do it.
Read more