Programming


These are exciting times. I would love to live long enough to see a practical application of some life-based computer project. I think that my first computer was a $1000 machine I bought in 1976 which used a television as a monitor and cassette tape player as a hard disk and I am astounded that I may miss a bacteria based computer. I’m not spoiled. No sir!
A team of US scientists have engineered bacteria that could solve complex mathematical problems faster than anything made from silicon.
Bacterial computers can crack mathematical problems | Science | guardian.co.uk
John Kolbert wrote a function to to get a list (array) of users by their role name. For example, he shows how to get a list of editors. I would only change the function slightly to accommodate my own programming style (and because I can't leave well enough alone).
PHP:
  1. function get_users_with_role ($role) {
  2.  
  3.     // gets all users with specified role
  4.     $wp_user_search = new WP_User_Search( '', '', $role);
  5.  
  6.     return $wp_user_search->get_results();
  7.  
  8. }

As John notes, remember this is for use in the admin panels. Thanks, John.
I have a old client who wants to add a link directory to his web pages. I have been suggesting WordPress as his basic web site CMS and I found the following WordPress Link Directory Which should make administering his web site a lot easier. The Plugin author seems very responsive to adding features and fixing bugs. I may be able to squeak by without having to hack my own version. I'll post a comment here with the url of the new directory and my success (or failure) with the Plugin.

Here's a good interview with Zack that cuts through all the B.S. found in the speculative news stories about the MBTA Subway Hacking Incident.

Having the FBI agent there made it more real. But after about a minute, I calmed down and realized that we needed to just show them that this is not a big deal, this is not a problem.

When the FBI agent walked into the room, that was a sign that you should walk out. Never explain anything to police without a lawyer present. Never!

I ran across this piece of code in a program I am updating. The original author is a great game designer, but only a fair programmer. He also seems to have very limited experience with SQL.

PHP:
  1. if ( $grab == 'Ammo' ) {
  2.     $check = mysql_query("SELECT * FROM BF WHERE owner= 'None' AND country='$fetch->location'");
  3.     $num_rows = mysql_num_rows($check);
  4.  
  5.     if ( $num_rows != 0 ) {
  6.         if ( $fetch->location == $location ) {
  7.             mysql_query("UPDATE BF SET owner='$username', profit='0' WHERE country='$fetch->location' LIMIT 1");
  8.             $this->content .= "You got the Bullet Factory!";
  9.         }
  10.     }
  11. }

When writing database applications, you need to be as good at writing queries as you are at writing code. Here's a rewrite:

(more...)

In our last exciting episode, I promised a crude flowchart and I don't want to let anyone down. You'll need to click on it to see the whole thing. Feel free to open it in another window and follow along.

As I read my previous posts it occurred to me that you may not see where I am leading with all these files. The idea I have in mind is to allow editing a particular section of the web site in just one file, but more importantly, I want to limit the changes made to that file to affect only that portion of the web site we are making changes to. As long as each section edit maintains well formed markup, that should happen in each instance.

(more...)

In our last exciting episode, I presented a very basic use for SSI. Let's take a closer look. Here's an example include directive which pulls in the contents of a file named content.html located in my www directory.

HTML:
  1. <!--#include virtual="/content.html" -->

Now that's pretty powerful if you have never seen it before, but it gets old quick. Let's add a little power using an Apache variable.

HTML:
  1. <!--#set var="content" value="/content.html" -->
  2. <!--#include virtual="$content" -->

(more...)

A CMS is great for people who don't know HTML, but what about those of us who do know HTML and CSS and all those other things?

A CMS is a great way to set up a web site for a customer. Weighing in at 15 to 20 Megabytes, they are often cheaper than forcing your customer to pay for every little update. If you have the tie to learn even a small part of their features you can serve your web site design customers well and keep their costs down.

Quite a few years ago I was working with Apache on a web site and we needed quick and dirty method of creating content for each page which used common headers, footer, menus, etc. Perhaps I was too inexperienced to know about Content Management Systems or perhaps there were just none around.

(more...)

I guess this is more a reminder to myself than useful information, but here goes.

Recently, I read up on PHP 5.x header() function. I ran across this tidbit of info.

HTTP/1.1 requires an absolute URI as argument to ยป Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.

I don't know about you, but I find RFCs incredibly boring, so I'm glad that some insomniac took the time to find this gem.

Following this standard eliminates another problem in a different language. In Perl, many people correctly use CGI.pm to perform redirects. The CGI manual gives the same advice. Use full URLs to redirect.

Here's a mini guide to redirection: (Basically, you just print the redirect out.)

(more...)
The jQuery JavaScript library offers some quick and dirty solutions to many problems. I was perusing a jQuery email list when I ran across a simple problem that a beginner JavaScript coder like me could solve. I'll simplify it a little here to focus this article. Basically, the poster wanted to add form fields to a table, but he wanted to increment a field counter in the HTML and in the id and name tags. Just to make it a little more difficult, the field numbers needed to be padded with leading zeros. Adding the table rows is trivial in jQuery and it turns out that leading zeros are pretty easy too. I like the "everything is an object" approach to JavaScript. You can extend even the built-in objects including the String object. Let's tackle that first. (more...)

Next Page »