Posted by & filed under Programming.

Needed to create a list of the web safe colors for another site of mine. Yeah, I know that web safe colors are outdated. But it was still something I wanted on the site.

Typing in 216 hex color codes was not something I wanted to do though.

Looking over a list of the safe colors I noticed that every color was made up of only the hex pairs 00, 33, 66, 99, cc, and ff. Or, in decimal, 0, 51, 102, 153, 204, and 255. That made it pretty easy to loop through and create the RGB values.

function get_websafe() {
    $vals = array(0, 51, 102, 153, 204, 255);
    $colors = array();
    foreach ($vals as $r) {
        foreach ($vals as $g) {
            foreach ($vals as $b) {
                $colors[] = rgbToHex($r, $g, $b);
            }
        }
    }
    return $colors;
}

Also needed the rgbToHex function, but that was something that was already in place. I’ll go ahead and list it below.

function rgbToHex($r, $g, $b) {
	$hex = '';
	$hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
	$hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
	$hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
	return $hex; 
}

You can see the results here.

Posted by & filed under WordPress.

Needed a way to display meta field info in a post as part of a site rebuild I’m working on.

The meta shortcode plugin adds a short code to WordPress that will display the contents of a meta field if it exists, and optionally something else if it doesn’t.

Download
You can get the plugin from the WordPress plugin library.

Usage
Use the [ metafield ] shortcode, without the spaces, where you want the info to appear.

The following attributes are available.

  • field – The name of the field to use. This is the only required attribute.
  • before – Text or HTML to display before the meta field. Defaults to nothing for single meta values or <ul> for cases where there are multiple values for a meta field.
  • after – Text or HTML to display after the meta field. Same defaults as before except it closes the list.
  • sorted – If there are multiple values for a meta key, setting this to true will sort them alphabetically. Setting to false or leaving blank will output in the order entered in WordPress. This attribute has no effect if the meta key only has a single value.
  • empty – Displayed when the meta key is empty or not found. Defaults to empty which means nothing will be displayed if the key isn’t found.

Posted by & filed under Coding.

My desktop is running across 3 monitors, and I really think that I can be more productive using all 3. The setup allows me to keep Netbeans open on one monitor, Chrome open on the second to see whether the code that I just typed looks like I want it to, and references on the third.

The problem is that it’s harder for me to get into a working mode with 3. I’ve found myself switching to my notebook more often recently. It just seems easier to concentrate with one little 13.3 inch screen instead of 3.

Not sure what the answer is, or whether there is one. But there is some irony in the fact that I was trying to work on some code and the idea of this post distracted me enough to come here and type it out.

Posted by & filed under Coding.

Needed a way to practice a bit for the CCNA exam that I’m planning on taking within the next few months. I’ve found a bunch of multiple choice banks to cover a lot of the memorization, but was looking for a way to practice more with network addressing. Sure, there are some multiple choice banks out there. But real-world isn’t multiple choice, so I wanted a better way.

Spent about a day dug into bits and JavaScript and came up with network-practice.info. It lets you get random questions for binary to decimal conversions, decimal to binary, and network addressing either using classes or CIDR.

Network-Practice.info screen shot

An obligatory screen capture. Nothing exciting, but here it is anyway.

There are 4 types of questions and you can pick which types you want. And since the questions are built randomly with a bit of JavaScript, you can try as many questions as you like. When you’re finished, click the done button and you’ll get stats on how you did on each of the types.

Posted by & filed under WordPress.

Had to do a quick update for my Plain Text Custom Post Type WordPress plugin.

Right now I’m only using it one site, and I’ve never noticed a problem until this week. The JavaScript wasn’t working from another computer. Turns out it was conflicting with the stats module in Jetpack. Jetpack inserts a bit of code in either wp_footer or the shutdown action to do the tracking. It never was an issue with me because Jetpack doesn’t insert that code when logged in. Wasn’t logged in on the other computer and that’s when the conflict showed up for me.

So a quick remove_action to get the Jetpack action out of shutdown on the plain text posts and it appears to be working without a hitch now.

New version is up at the WordPress Plugin Site.