Web Development/Programming

Tech Tips, Web Development/Programming

WordPress Plugin to Generate Post Slugs

If you have migrated your WordPress blog from another blogging platform but the post slugs weren’t generated, you can my Generate Post Slugs Plugin to have the slugs generated from the post title.

Why I Wrote This Plugin

I wrote this plugin for use on this very blog because when I ported my custom blog software entries to WordPress, I didn’t bother to generate slugs with the import script I cobbled together. A few weeks ago I made my URLs SEO-friendly and realized that all those posts I imported years ago were missing slugs.

License

By downloading, you acknowledge that this plugin is released under the GPLv2 License AS IS with no implicit or explicit warranty of fitness for any purpose. While I have tested the plugin with WordPress 3.2.1 and have used it to fix the slugs for posts on this very site, it is STRONGLY SUGGESTED that you make a backup of your WordPress installation prior to using it.

Getting the Plugin

If you accept the license terms outlined above, click here to download the Generate Slugs Plugin.

Installing the Plugin

Installation is just like any other WordPress plugin. On the plugin install page in your WordPress Dashboard, upload the zip file. Then activate the plugin under the Installed Plugins menu and follow the instructions provided there to use the plugin to generate your slugs.

I hope this helps someone.

Android, Kindle Fire, Web Development/Programming

Android App Web Color Prototyper Sneak Peak

A couple weeks ago, I alluded to an Android app I’m writing in conjunction with Mike Bryant. As requested by some friends wanting to know what the app does, it is meant to help web designers prototype color schemes quickly.  You set colors for various parts of a sample page and get to see an instant preview of what the colors will look like.  When you’re done, the app will email you the sample page (and more importantly) the CSS that creates the previewed color scheme.

Here’s a screenshot of the app in progress (codenamed WebIris) running on an Android 2.3 tablet emulator (which not-so-coincidentally is setup in a Kindle Fire configuration).

(Click for a larger view)

Remember, this is an early preview. Not all the bells and whistles are represented in this preview ;) We are targeting the app for Android 2.3 devices and beyond. Stay tuned!

Apple, Google, Microsoft Windows, OS X, Social Commentary, Web Development/Programming

Let’s not forget Dennis Ritchie

While Steve Jobs’ death has been covered extensively by the media, I think it’s important that the world learn about the death of a man whose contribution to the information age is so immense that it is beyond measure. On October 12, 2011, Dennis Ritchie was found dead in his home at the age of 70. Ritchie is the inventor of the C programming language and a co-inventor of Unix, the father of all modern operating systems. The man was, without a doubt, brilliant. His contributions are what every nerd should aspire to.

Why is the C programming language so important? Because C was the perfect bridge between man and machine. Before C was invented, programmers had to write the code that runs operating systems (and most everything else) in assembly, which is just one step above binary. Assembly, while powerful, is also extremely cumbersome. Writing even the most trivial of programs is very time consuming. Ritchie’s C language put the development cycle of operating systems and applications into overdrive, allowing programmers to crank out innovation quickly and easily. On top of this speed and power, Ritchie gave his newly-minted language away for free to universities, who were free to do with it as they wished. C has since been used on nearly every system imaginable, from super computers, to PCs, to Macs, to video game consoles.

Nearly every programmable device in existence today owes its ability to be useful to Dennis Ritchie. Without his brilliance and willingness to give that brilliance away, we would still be in the dark ages of Information.

Tech Tips, Web Development/Programming

A PHP Script to automatically clean files affected by the the eval(gzinflate(base64_decode…) hack

In late April, my server got hacked. Most of my php files had code that looked like this placed at the top:

eval(gzinflate(base64_decode('DZZFssRYokOX... long string of gzipped-base64-encoded php code);

I’m not sure how the bad guys got in, but I changed all my passwords and updated all the software on the server. Then, like any obsessive programmer, I set forth making a script to clean up the mess programatically. My solution was a two-step process. I used GNU find command to find all my php scripts with the code “eval(gzinflate” in them. I chose to search by this code because I can’t think of too many legitimate reasons to do this, and it matched all the infections I found manually. The full command I used for this was:

find /full/path/to/public_html -name "*.php" -exec grep -li "eval(gzinflate" {} \;

This command finds all php files then uses grep to look inside each file for “eval(gzinflate”.

I copied the results of this command to a text file called fullInfected.txt .

After I had a list of infected files, I wrote a php script that’ll go through each file on the list, do a search, and remove all lines with the infected code in it. I saved the script in the same directory as my fullInfected.txt file. You can get that file (with a few sample supporting files) here: CleanEvalBase64_decodeHack script.

There are two variables that can be set at the top of the file: One for the name of the file with the list of infected files in it ($listOfFiles) and another for the text to search for ($findWhat). I uploaded the script to the server and ran it via SSH:

php clean.php

When the script runs, it will log a list of which files were cleaned.

This script is released as-is, with no implied warranty whatsoever under the Creative Commons Attribution-ShareAlike 3.0 Unported License. Make a backup of your server before using this and test this very thoroughly on a small sample of infected files.

I’m sure there’s more efficient ways to do with with shell commands and/or regex, but I didn’t know how to do it that way. Good luck getting cleaned up!

Tech Tips, Web Development/Programming

Browsers, browsers, browsers!

Nerds of the world: rejoice! The browser wars are ablaze for the first time in over a decade. Microsoft, Mozilla, Google, Apple, and Opera are duking it out, feature-for-feature and there’s no clear winner. For the record, I don’t want anyone to win because competition makes software better since developers have to work hard to keep and maintain their market share. While the four major players volley for our affections, Netizens all over the world win! As I mentioned in a recent post, most of what we do with computers is moving to the net. Therefore, the availability of quality browsers is a big deal for techies and Luddites alike.

The First Browser Wars

The First Browser Wars ended around 1997 with the release of Internet Explorer 5. At the time, there was IE, Netscape, and (to a much lesser extent) Opera. When Microsoft decided to unload its war chest in 1995 with the intent of destroying Netscape, it was a matter of time before the boys of Redmond stomped Netscape into the ground. In the span of 2 and a half years, the battle was over.

In 1997, I was just learning how to make web pages. I couldn’t have been happier that Internet Explorer was the winner since that meant I didn’t have to work so hard trying to make my pages look the same on both browsers.  I still tested my sites in Netscape Communicator, but IE was the only browser I really worried about. Life as a budding web designer was good.

My happiness was ill-founded, though, because without competition, Microsoft stopped updating Internet Explorer after the release of IE 6 in September 2001. It would be seven and a half years before Balmer and company decided to release a new version. During IE 6, there were security threats uncovered at least every couple months. While it was nice having only one platform to worry about, it was frustrating and scary to have to worry about security every time you visited a page. Opera never went away during this time, but it never gained much traction in the U.S. at the end of the First Browser Wars

The Second Browser Wars and Beyond

A spunky upstart named Mozilla arose from the ashes of Netscape after Netscape’s Gecko source code was released in 2000. In 2004, Firefox 1.0 was officially released. I honestly never thought Firefox would gain as much traction as it did, but it turns out, FF 1.0 was the scout that signaled the beginning of the Second Browser Wars.

Fast forward 7 more years since FF 1.0 was released and Google has entered the market with Chrome, which shares common roots with Apple’s Safari (via the Webkit engine). It’s apparent that all are scrambling for more market share if you consider that the browser version numbers are increasing at an alarming rate. While some of the version incrementing is for marketing purposes (because we all know higher version numbers mean a better product…), the browsers really are getting better from all the vendors.  Here’s my quick breakdown of the strengths of each browser:

  • Internet Explorer 9 – Microsoft has gone out of its way to make IE safer to use for everyday surfing. It automatically checks for phishing attacks, warns users if it detects so much as a mouse fart on a website, and integrates with MS Security Essentials. While it’ll take awhile to shed its reputation as the insecure kid on the block, Microsoft is trying hard to prove otherwise.
  • Firefox 5 – Firefox is my favorite because of its vast library of plugins, especially plugins that make life easy for web developers. Mozilla keeps making Firefox faster and has taken an aggressive stance toward security since version 3.5.
  • Chrome 12 – Google’s brainchild is the fastest kid on the block. It’s super clean interface and seamless updating architecture has appealed to millions since its debut in late 2008. Google is showing its serious about being the one and only browser folks turn to for their Internet needs.
  • Opera 11 – The underdog of the roundup, the Scandinavian wonder invented tabbed browsing in 1996 and continues to set the bar for standards compliance, and it manages to be incredibly fast as well. The only browser found on the Wii, Opera can also be found on PCs, Macs, iPod/iPad, and mobile phones. Opera is the most hardware-agnostic of the bunch.
  • Safari  5 – Admittedly, Safari is my least favorite, however, it is by far the best mobile browser in existence, as it renders pages on the iPod Touch and iPad perfectly. Safari is what all mobile browsers should strive to be.

I hope the Second Browser Wars rage on for a long time and we, the consumers of Internet goodness, continue to reap the benefits of the battle. Unlike the First Browser Wars, the current struggle is being fought on technical merit and security. Neither Microsoft nor anyone else can crush the competition strictly with wads of money. No matter who you choose as your browser, I wish everyone happy surfing!

Microsoft Windows, Tech Tips, Web Development/Programming

Re-Register Apache and Mysql as Services After Moving Zend Server Directory to a New Computer

I recently got a new Toshiba A665-S5183X Core i7 laptop and I really love it.  The only thing about getting a new computer (especially if you’re a geek) is transferring files and settings from the old machine to the new one. I used Windows 7’s Easy Transfer to move over all the usual documents (pictures, papers, etc), and I also transferred about 15 GB of programs that are not registry dependent. One of the folders I transferred was my Zend Server CE installation. Zend Server includes the Apache Web Server as well as Mysql Server. I wanted the two installed as a service, but I didn’t want to have to reinstall, since I had customized many settings in several places in the installation and didn’t want to start over. So how hard is it to reinstall the two servers as a service? As it turns out, not hard at all.

First, open an Administrative Windows Command Prompt. The rest is as easy as follows.

Install Apache As a Service

cd into your Apache2 bin directory and type

httpd -k install -n “Zend-Apache2” -f “C:\program files (x86)\C:\Program Files (x86)\Zend\Apache2\conf\httpd.conf"

This command will install Apache 2 as a service named Zend-Apache2 in  your services.msc service control utility (where you can start/stop your Apache service). Additionally, it will tell the service to use the specified httpd.conf file (which can be anywhere you want). The service installer will even be nice enough to warn you of errors or warnings in your specified conf file.

Install Mysql As a Service

cd to your Mysql bin directory and type:

“mysqld” –install MySQL-Zend –defaults-file=”C:\Program Files (x86)\Zend\MySQL51\my.cnf”

As above, whatever the word you type after the install directive will be the name of your service in services.msc. The defaults file represents the path to your Mysql cnf file.

Happy web developing with Zend framework running as services on your new box!

Tech Tips, Visual Basic, Web Development/Programming

Reversing a String in VB.net

The following code snippet shows how easy it is to reverse a string in Vb.net:

Dim originalString As String = "Some text here"
Dim reversedString As String = originalString.Reverse.ToArray
'reversedString now equals "ereh txet emoS"

As you can see, this is very easy to do, however, most of the examples I found online were overly complicated. So, I thought I’d post my nice easy way.  Happy coding!

Web Development/Programming

Diagrams, diagrams, diagrams

I’ve been sitting here for the last couple hours contemplating a program design in my head. (Actually, I’ve been contemplating this design for a month or so, but I really was putting some brain power into it for the last couple hours. Anyway…back to my point…) I have decided to start putting the ideas into some codified form in an effort to start documenting my code and designs better. In trying to figure out which diagrams to draw, I realized that it has been so long since I have done a formal diagram to formal standards that I have actually forgotten a lot of the minor notations. I’ve decided to go with UML, but I have forgotten the rules for using a filled in shape vs. an empty shape, not to mention all the line styles needed to convey relationships…GASP! Looks like tomorrow that I’m going to have to dust off the UML Distilled book laying around here somewhere.

It’s no wonder that I’ve forgotten a lot of these diagramming tools: Many of the clients I work for don’t have a clue what they’re looking at. For the last 4 years, I’ve been relying on text-based use cases because everybody, regardless of technical skill, can communicate with them. Frankly, I’ve gotten use to and comfortable with this format. There are some serious drawbacks to this though, namely the difficulty in seeing interactions between more than a couple modules at once. I seriously need some activity diagrams so I can start writing better test cases. I need to quit being such a Duct Tape Programmer. It’s quick, but it makes maintainability much harder than it has to be.

The best news is that free, open source diagramming tools are exponetially better now than they were just 4 years ago, so as soon as I acquaint myself with some of the formalities, I should be able to have my diagrams cranked out in no time.

Tech Tips, Web Development/Programming

Introducing Phind, a simple PHP script for finding foreign keys in MySQL tables

For years, I have wanted a way to programatically find foreign keys in MySQL tables using PHP. After a lot of thought, I have written Phind. Phind basically consists of one function getForeignKeys() whose only parameter is the table name. If that table has foreign keys, Phind returns a multidimensional array containing an index for the key as the first index, and the part of the key as the second index.

My ultimate goal is to use Phind to create a PHP CRUD generator written entirely in PHP. That’ll probably be a long way off, though. I just don’t have time to sit down and finish something like that right now.

The source code for phind is here: Simply rename the file from phind.txt to phind.php when you save it. You can also go here to see Phind in action on a table in a database on my server named ‘contacts.’ Eventually, I will add more examples to the documentation included with the phind.php file, but for now, it’s sparse. However, I’m sure there are enough PHP guys who have been looking for a way to make sense of what foreign keys are in a table and where exactly they are pointing to.

I hope this helps somebody.

Tech Tips, Web Development/Programming

How to Fix Image Resizing Problem in the Arthemia WordPress Theme

I downloaded the Free Arthemia WordPress theme the other day to use with my students’ FBLA site. I really like how the theme looks like a professional newspaper like the New York Times as wells as how easy it is to add Headline and Featured stories just by assigning a category to them.

One thing I could get working was the images that show up with the Headline and Featured stories when you add the Image custom field to an article. The images would just show up as a red x. When I tried to view them in Firefox, I got the following error:

finfo_open(): Failed to load magic database at ‘/usr/share/misc/magic’.

After poking around on the Internet for a minute, I found that there are some files that PECL finfo uses to sniff out the MIME type of files. Apparently, the files are some sort of flat file database that holds, well, MIME types.  Luckily, I extrapolated a solution after seeing a workaround on a forum. If you’re using Arthemia Free Version 2 and are having the same problem getting your images to load, here’s all you must do.

Replace lines 216-220 of the /wp-content/themes/arthemia/scripts/timthumb.php with the following code:

$file_cmd = "file -ib  \"$file\"";
exec ($file_cmd, $exec_output);
$mime_type =  $exec_output[0];

That’s it! The only other thing you have to make sure to do to get your images to resize and show up properly is to put the absolute path to the images without your domain. So, in my case, I have an image whose full path is:

http://breathittfbla.com/wp-content/uploads/2009/07/foreman.jpg

To make it work, the value for the Image custom field has to be set to:

/wp-content/uploads/2009/07/foreman.jpg

After changing those lines of code and then putting the right file path in the Custom Field, Arthemia is resizing and displaying images in Headlines and Featured Stories without issue.  I hope this helps somebody!

Scroll to Top