Posts filed under 'Programming General'
Blogging about programming, networking, and computers in general
Welcome to my new blog. Previously, I blogged about PHP at phpsourcery.com. As it happens, I’m doing somewhat less PHP programming now. I’ve also began to do some Ruby programming. I work with just about anything network related (Cisco Routers, Cabletron Switches, Cisco Switches, etc.) Since then, I’ve also switched from a Windows machine as my primary box to a Mac Mini… Then, I switched to an Intel iMac, just after they were introduced. So, there’s no telling what I’ll find interesting to blog about… That’s why I started the Jack of All I.T. blog.
Add comment May 2, 2007
An Important Programming Truth, re-discovered
This is mostly a tip, but it does deal directly with my FAQ project… Tonight, I re-discovered an important programming truth…
All programmers who have looked at code they wrote 6 months or more earlier know that documentation is an important thing.. I mean, I have a hard time remembering having WRITTEN code for some projects, much less remembering the specifics of how said code actually works… All serious programmers should know that good documentation is absolutely essential for all but the simplest of code.
But, the programming documentation that is perhaps the most important of all is documentation for RECURSIVE FUNCTIONS… Recursion is so powerful if used properly… In a scant few lines of code you can acomplish a lot of complex work. But recursion code is also very difficult to scan and determine what is going on. (At least, with any code that actually performs a real-world job..) I re-discovered this important programming truth tonight as I worked out a bug in my recursion code…
My recursive function consists of a grand total of 6 lines of code. After having difficulty reading this code (which I wrote only about a week ago!) I now have written seven full lines of text (consisting of 102 words total) to explain how this code works.
Of course, now that I’ve written this documentation, we all know that this will be the most bug-free portion of code in the entire project, and I won’t need to go back and look at it for years, if ever…
Add comment August 22, 2004
Image Optimization
While reviewing a site of mine, I found that I was guilty of something that I only thought everyone else was guilty of…
Non-optimized images.
There. Now you know.
Image optimization is something that I have suggested to others many times as a way to speed up their website, while conserving bandwidth at the same time. Why not kill two birds with one stone?
Well, while I was doing a bit of fiddling in my favorite image editor tonight, I discovered that I had an image on one of my sites that was not optimal in terms of size. It was a header for a page… Prior to my CSS layout, it was broken into three separate images, each about 9-10K… With CSS, I found that it would be best to have it as a single image, but it was around 40K. (I did it in a bit of hurry, though 40K seems huge in retrospect!) I messed around with various settings, looking at the final filesize and the quality of the image and finally settled on a variation that was about 20K in size. This reduction in size is enough to make a significant improvement in download speed while the image quality was only slightly lower.
The thought then crossed my mind that I should probably check some other image files, as I might be able to shave off a little more. Well, I didn’t keep an exact count, but I’m guessing that I shaved another 15-25K off of the front page of the site alone, as I was able to cut off a few hundred bytes on up to a few thousand bytes on some images.
Here are a few image optimization tips:
1. Try different formats! You may have everything on your site in GIF today, but that might not be best. In my testing, some images looked best and were most efficient in GIF format, but PNG may have an advantage with some image files. JPEG was a big favorite of mine as well. For certain types of images, JPEG is superior to GIF and PNG.
2. For GIF and PNG formats, don’t forget to lower the color depth. I found that in some cases I was able to lower the color depth down to as low as 8 colors. Simply dropping from 256 to 128 colors in many cases resulted in an almost unnoticable reduction in quality, while dropping a significant percentage of the file’s size. Depending on the imdividual image, you might be able to drop down to 64, 32, or even fewer colors.
3. For JPEG formated images, use the quality scale! Again, depending on the image you can get away with a significantly lower quality setting without significantly affecting the actual image quality. This can result in BIG size savings.
4. While some people who offer ready-to-download icons (for their products, etc) are putting out highly optimized images for others to use, not all ready-to-download images are optimized. The result? Image files that are 2-3 times larger than they need to be, if not more. So, before you use that new snazzy version of Tux you found on the web, load it into your favorite optimizer to see if it’s ready for prime time.
Add comment August 12, 2004
My Programming History
I recently realized that I hadn’t adequately explained what my programming, PHP, or web development experience level is.
I’ve been programming in various languages on multiple platforms now for about 20 years. Languages that I’ve worked with extensively (and roughly in order) include: Turbo Pascal, C, C++, Rexx, C#, and now PHP. I’ve written applications in these languages on platforms ranging from DOS, OS2, Palm OS, Solaris, and Windows.
Applications that I’ve written include a BBS Door game, a Palm Address book, an SNMP Trap-mapper, numerous Rexx utility programs, various Windows command line applications, a Windows GUI application to certify Frame Relay circuits, and (within the last 6 months) numerous small command-line PHP utilities for Solaris.
The vast majority of my PHP experience (at this point, at least) is with a Solaris system, with command-line PHP apps… Early this year I realized the power that PHP had in the form of the many extensions that are easily enabled. After explaining the advantages, my managers allowed for a trial run of PHP to see how well it worked in our environment. The ability to read and update a MS-SQL database from Solaris has proven to be a huge time-saver, not to mention the ability to easily script telnet sessions, and even perform SNMP queries directly from PHP. We have been slowly converting from Rexx to PHP for quite a few functions.
Sounds fairly impressive, right?
Now, I have very little web development experience…
1. My first web application was written in C# and it simply accepted input from a Solaris application via HTTP POSTs, populated a MS-SQL database, and displayed filtered and sortable results sets on various web pages. It has been in use for about 2 years now, so it must not be that terrible.
2. More recently I’ve written a C# app to manage an APC remote reboot switch which only has a single user.. My C# application takes a username and password from the user, determines which ports they can manage, shows the status, and lets them reboot the device(s).
3. My most recent web development project was related to MRTG. It was written in PHP and essentially restricts a customer’s view of MRTG to only the ports they are utilizing.
So, my main PHP experience thus far is writing database related command-line utility applications for Solaris. Oh, and by the way, my PHP web experience is with IIS under Windows, which throws another monkey wrench into things.
There you have it. I am by no means an expert on PHP for the web, but do have a good bit of PHP experience with unusual uses of PHP, and I hope to be able to share some of those experiences with you here, as well as share in the building-up of my web-related skills.
Add comment July 23, 2004
Sample Spec sheet
Here’s a rough draft of a the first spec sheet I wrote up for an CMS long ago:
1. Security
a. Must have a secure authentication method for authors/admins
(Would have not mentioned this on the Spec sheet, but I've never done it before)
b. Need to have author/admin access levels
c. Possibly be able to limit authors to writing in certain categories
2. Category Support
a. at least 3 levels deep (sub-categories)
b. A method to allow one article to fit into multiple categories
c. Online category management by admin (not just via direct DB manipulation)
3. Article Management
a. Article List page should have options to
i. List all articles
ii. Search text of articles for keywords, Category, or Status
iii. Edit/Delete article
b. Articles should have these DB fields:
i. ID, Status (visible, hidden), AuthorID, Date, Title, Summary, Content, Deleted, AllowComments, and Featured fields.
c. Should use an embedded WYSIWIG editor
d. Should allow uploading of images
e. Should parse text of article for information pertaining to the placement of uploaded images
f. Should allow for multi-page articles via embedded page breaks
4. Template system
a. Should be CSS based (another thing I need to learn better!)
b. Need to do more research on templating methods....
5. Semi-Static HTML pages
a. Since the content of the site will only be updated when new articles and news are added, the site should be pure HTML for presentation to the user, at least in the article pages. This allows for much higher volumes of traffic to the site with minimal server load.
Add comment July 19, 2004
Application Design
When writing an application from scratch, the very first thing you need is a plan. You need detailed design specifications. After all, it’s hard to write a piece of software if you don’t know everything that you want it to do.
My first step in this process is to closely examine the existing market. Start with the Open Source projects out there, but you also need to look at commercial applications. These are usually more polished and have more features that professionals want, not just the geeky features we tech-types want. For some of these commercial systems you might only be able to get screenshots. And that’s fine, as all we are doing is design work at this stage anyhow. Once you’ve worked your way through a few open-source projects, you can probably figure out how a commercial package works simply by looking at screen shots.
Oh, and do not give up on a feature at this stage just because you can’t see how to implement it. Put it down anyhow, and research how it’s done once you are further along in the design process.
Once you’ve gotten your general spec list down, think about it.. Give it a few days and think a bit on it each day. Your spec list shouldn’t be something that you write down in 30 minutes and then start programming. It should be a well thought-out document, and it should be as specific as possible.
The reason that you should get this as set-in-stone as possible before moving forward is simple. It is much easier to code a project as a whole, with all pieces accounted for from the begining than it is to come back later and try to add pieces in. It is inevitable that you will want to do that, but the fewer “add-ins” you have of this nature, the better.
Add comment July 18, 2004
HTML for the World Wide Web, 5th Edition
Elizabeth Castro’s “HTML for the World Wide Web” is a book that needs to be on the bookshelf of anyone wishing to become a web developer. In fact, if you already know HTML fairly well, this book will do a good job serving you as a reference. It’s 480 pages packed with easy to understand language, example HTML code, and screenshots.
Aside from the complexities of HTML, the 5th edition also deals with XHTML and CSS, but you are not likely to become an expert on CSS from the content of this book. This book really shines in the way it teaches you how to use HTML. If you want to learn CSS, get a book dedicated to it, as much more could be written on it than is in this text.
Personally, I mostly use this book as a reference. Whenever I need to figure out how to do something that I’m unsure of in HTML (or when something isn’t working the way I would expect), I simply look it up in the index and get to work. The author uses clear, consise, and fairly short explanations on how to get the job done. You definately won’t get bored with any theory… Every page is in two column format. The outermost column is explanation text, while the innermost column contains segments of HTML demonstrating the current topic, and a screenshot showing the results of the HTML. Many pages also contain Tips, sometimes mentioning browser incompatibilities, or related topics with references to other pages in the book.
I’ve been using various editions of this book for the last few years and it hasn’t disappointed me when I’ve had questions about any HTML issues. Get it… You’ll be glad you did.
Add comment July 16, 2004
PrimalScript 3.1 Review
PrimalScript by Sapien is an editor that I’ve used for a few years now. Initially, I used it mainly to write REXX programs, where the intelligent help capabilities were mostly wasted. When I picked up PHP, however, the intelligent capabilities were more helpful…
The first feature you’ll notice about PrimalScript is the color highlighting… All keywords are highlighted in blue, comments are in green, quoted text is in red, as are functions…
The interesting thing about the built-in functions, though, is that PrimalScript will pop up intellisense after you’ve finished typing in a function name.. For example, type in “preg_replace” in Primal and hit the opening parenthesis and a box pops up below your blinking cursor to tell you what variables it is expecting for that function. Unfortunately, this functionality is only for the core built-in functions of PHP, and it doesn’t do anything to figure out what function you are trying to use, so if you don’t know how to spell it, Primal won’t be of much assistance. Notably, functions you write in your scripts will not have this intelligent help.
Another very nice feature about Primal is the “FTP Open” command. This allows you to open up a file on a remote FTP server. You can then edit the file and save it back to the FTP server, as easily as if it were right on your local drive.
If you write PHP apps with lots of functions, Primal has a function finder dropdown that will certainly help you quickly jump around in your code to the spots you are intersted in.
PrimalScript sports a Tabbed interface, allowing you to open multiple files easily, and switch back and forth between them. Very intuitive.
One feature that has saved me lots of time and frustration is the “Find in Files” feature. This lets you specify a directory to search in and what to search for, and Primal will open each file that it finds your search string in. Once they are all open, you can do a “Search and Replace” to affect them all at once, easily.
PrimalScript does have a “Project” menu for grouping files together into a project… Honestly, though, I’ve not really used this feature in the years of using this product. It also includes a Spell Checker and a WMI wizard (to help you make those complex WMI queries).
I would be misleading you if I stated that PrimalScript is written specifically for PHP programmers. It’s not. Instead, it is a general purpose scripting tool that can be used with lots of languages (ASP, ASP.NET, C#, Java, Perl, PHP, VB.NET, over 35 altogether). If you are looking for a great general purpose editor that has a good bit of intelligence built-in, PrimalScript is a good choice. It is priced at $149, but if you are a script jockey that manages scripts in many different languages, it’s right up your alley.
Add comment July 14, 2004