Google Analytics Custom Segmentation by Role in Drupal
At the company I work for, I was already using Google Analytics to track visitors to the website, but I wanted a little more information. I wanted to see how many visitors were staff, versus other visitors. Put the Pieces on the Table The first piece we needed was already in place. We are using Drupal for our website, and every staff member needs to log in from time to time for various staff only resources. Regardless of any other permissions they may have, everyone who is staff is made part of the role “staff”. Google lets you add up…Read the Rest
Update Multiple Rows At Once With Different Values in MySQL
I’ve had to figure this out on my own twice now, so I guess it’s time to document it. It is possible, and fairly easy, to update multiple rows of a MySQL table at the same time, with different values for each row. Unfortunately it’s not as easy as inserting, but once you see what’s being done you will probably say “Oh, of course!”. The key to the multiple row update query is the CASE statement. MySQL’s CASE reference page doesn’t even have the word “UPDATE” on the page anywhere, but don’t let that fool you, it can be used…Read the Rest
Segmenting Drupal Users By Role in Google Analytics
We use Google Analytics and Drupal at work. We have been tracking our website usage for quite a while now, but we had no idea what percentage of our visitors were staff. We have 13 main locations, so IP filtering could’ve gotten us most of the way, but staff members do work from home and on the road quite a bit too. In the end I decided that the best route would be to use Google Analytics _setCustomVar funcitons to record the data we wanted. Staff members at work have the role “staff”, so that’s what I wanted to select…Read the Rest
ISOlator
Got a Linux CD you want another copy of, but don’t want to download it again? Got a CD that needs to be in the computer to play your game, but you don’t want to risk scratching the original? Need to make backups to protect against kids? ISOlator is for you. ISOlator takes a CD, DVD, or other mounted volume and makes an ISO out of it. The ISO can then be burned to CD, stored on your backup disk (you DO backup, right?), or put to use however you like. ISOlator uses the Unix command line program ‘dd’ to…Read the Rest
Writing a daemon with PHP
PHP isn’t used to write daemons very often, and other languages (like Perl or C) might be more suited to your typical daemon. There are times when PHP is the right choice though, for instance if the rest of your project is a PHP website and you want to keep the same code language across the project. Everything here is available elsewhere online, but I couldn’t find a page that brought it all together neatly (fork, exec, waitpid, signal handling), so here it is. In this case, I wanted to be able to use the same DB connection file and…Read the Rest
Handling Signals in PHP
Handling signals in PHP is really not to difficult once you get the hang of it. What’s a signal? When an operating system wants a process to terminate, it will usually send the SIGTERM signal (terminate). SIGTERM is essentially a request. It tells the program “I would really really really like you to shut down”. Most programs, being polite do so. There are many signals which you can see in your man pages (man 7 signal), but just a couple of important ones. kill sends a SIGTERM, Ctrl-C sends SIGINT, closing your terminal sends SIGHUP. SIGKILL can’t be handled and…Read the Rest
Add OpenSearch search to your site
One of the original reasons I switched to Firefox was the built-in Google search box. Now even Internet Explorer has built in search. You can search Google, Bing, Wikipedia, etc, but what if you want people to be able to search your site from their browser? What if you want to search some other site from your browser? Enter OpenSearch. OpenSearch describes a format for a special XML file you host on your site. When an OpenSearch compatible client comes along, they can detect that file and allow the user to search using the parameters you specify. Basically, it’s a…Read the Rest
Custom CSS Stylesheets for Small Screens
I’ve gotten a good handfull of visitors from EeePC related sites, so I assume that some visitors are coming on their EeePCs. I was playing with some other site layout issues at the same time anyways, so I decided to do a couple of things to make it easier on those with small screens. Notice: This info is old and probably out of date. A better method of doing this probably exists. If it’s helpful, great, but please take it with a grain of salt. Smart Chunking The main reason this site doesn’t play well with small screens is because…Read the Rest
Convert an image to fake Sepia with PHP
It’s pretty easy to do image manipulation with PHP. Here’s a sample of converting an image from color into sepia using PHP’s imagefilter. Be sure that your memory_limit will handle the image sizes you want to process. @imagecreatefromjpeg will return FALSE if it can’t load the image (because of a bad file path, file size or whatever). This isn’t a real sepia conversion, but it’s a decent fake. The image is converted to greyscale, the brightness turned down, and then colorized with a red tint. PHP’s imagefilter has lots of other neat tricks it can do, so be sure to…Read the Rest