Archive | Code Samples

View Unique Images Bookmarklet

I was getting tired of opening a ton of tabs to view images in a gallery so I made a small bookmarklet to handle it for me. This little bit of code will grab all of the unique image links from a page and open them as images in a new window (BMP, JPG, JPEG, PNG, GIF).

View Unique Images

Want To See It?

Date Counter Bookmarklet

Ever needed to calculate a date in the future but didn’t feel like looking it up? My girlfriend Katie was looking up dates for an invoice so I created a bookmarklet that takes a number of days and then alerts it to screen so you can copy and paste it. I might end up fixing it in the future so that it’ll print the result to whatever field is currently focused, but for now, you’ll all have to make due.

FutureDate

Want To See It?

Need State and Country Dropdowns? No Problem!

Frequently while programming, I find myself in need of a complete list of the States, their abbreviations and sometimes even Countries. Usually I end up prowling Google trying to find some sort of list that I can then import in to a database. Each time I did it I kept wondering why I hadn’t created some script for that yet.

I know it’s more efficient to make use of a database with tables for States and Countries, however, in the event that I don’t need one or am just doing some sort of one off solution, I’ve created a couple functions and two arrays to help myself, and maybe you guys out. Need Dropdown? I Have ‘Em!

Geolocation Whitelisting/Blacklisting

Sometimes I get a request to either blacklist some countries from viewing content due to copyright restrictions or to only allow specific countries to access some of the site’s content. I had a bit of a tough time trying to figure out the best method to get the IP ranges.

In order to block them, I had to first decide how I wanted to implement it. Should I do it right from Apache? Perhaps through the .htaccess file? The best solution that I’ve found so far is to use the free API of hostip.info.  With a quick cURL request in PHP to their servers, I can pass an IP address to them and have it return a 2 letter Country Code such as US. Using that data, I can then either whitelist or blacklist certain page elements depending upon how I implement it. Lay It On Me!