Category: Software Development
-
Generate random hex color with PHP
There’s many ways to skin a cat, or generate a color. You could randomize a number between 0 and 16777215 then convert it to hex: $rand_color = ‘#’ . dechex(mt_rant(0, 16777215)); Or you could do what I like to do, just md5 a random string and grab the first 6…
-
Run a block of PHP code a certain percentage of the time
Sometimes, you may want to run code all of the time. Other times, you may want to run code some of the time. This is how garbage collection in PHP works. Based on your configuration for gc_probability and gc_divisor, garbage collections runs a fraction of the time (defaulting to 1/100…
-
CSS :not issue in Safari on iOS9
Seems that every time that Apple releases a new version of iOS I encounter some weird rendering issue. This time around with iOS9 I encountered an issue where the full / desktop version of the site looked like it still using some of the mobile / smaller device stylings. After…
-
Stop submitting feature requests for Open Source Software
A few years back I wrote about my experiences contributing to and maintaining open source projects. Since then, I’ve done my share of forking, pull requesting and even starting up new projects that people are forking and pull requesting. I make a very conscious effort to contribute to projects that…
-
Bitmaps vs. Sets to track Monthly Active Users in Redis
Recently I was building a piece of functionality to track the daily and monthly active users on one of my sites. I already track this data in MySQL but retrieving the data was sluggish, even after creating a few new indexes, so I decided that I would use Redis. The…
-
How to block AdBlock users without JavaScript
This is probably one of the most rotten experiments I have done in recent times. I wanted to see what would happen if I blocked site usage from folks using ad blocking software. Would it cause a stir? Would people figure out that their ad blocker is to blame? Would…
-
Detect bots and spammers with Project Honey Pot and PHP
Project Honey Pot is one of my favorite services. They offer an API that allows you to pull information on an IP address. This comes in very handy when vetting traffic coming to your website. I discovered the service a few years back after realizing that I had some spammers…
-
How to convert a string to a time with PHP
Converting a string to a timestamp is one of my favorite things about PHP. In fact when trying to decide which language to build [HolidayAPI][holidayapi] in I couldn’t find an implementation of PHP’s strtotime() that rivaled the original. The strtotime() function takes a textual string as input and then spits…
-
Set array pointer to a specific key or value in PHP
PHP arrays are absolutely fantastic. They hold stuff, doesn’t really matter what. The interfacing is pretty consistent and there’s a boat load of built-in array functions. What PHP lacks is the ability to set the array pointer to an arbitrary key or value. There are ways to move forward and…
-
Basic page routing in PHP
Last week we talked about setting up a local development server with PHP’s built-in web server and I mentioned that we’d delve into page routing. Routing refers to taking the URI that a person was requested, let’s say /about and routing that to the appropriate code. Sure, you could just…