Skip to main content

Posts

Solid Basic Javascript Input Validation

Here is a simple yet pretty powerful and easy to use way to do validation on HTML form text boxes and text areas and similar controls. It checks to make sure required form field have *something* in them before allowing processing to continue. It’s a good simple way to add some basic validation to prevent trusted individuals from forgetting to fill out required fields. This is generally useful for internal websites where you can assume the user isn’t trying to hack the site. First we have two global JS variables that define the default and error-ed state of text boxes in question. Below I have standard controls with black borders and error-ed controls with red borders. // Assign a default border color for all form controls var defaultControlBorderColor = '#000000'; // Use a special color to highlight trouble (such as if a control doesn't validate) var notificationControlBorderColor = '#ff0000'; Below I have the primary function that does the field validation. F...

Execute a console command in PHP revised

While it seems like there are multitude of different methods to execute commands in PHP, so far the code I will go over below is my preferred method. Using the passthru() function works nicely and includes the final return code of whatever was being executed, which is generally useful to me in error checking. In processing, I also include ob_start(), ob_get_contents(), and ob_end_clean() so that I can capture the console programs output and return it the user eventually. // Execute a console command and return both the // command's success value and any output to the console it made function executeConsoleCommand($commandToExecute, &$commandConsoleOutputToAppend) { $returnValue = 0;      // Append command to output $commandConsoleOutputToAppend .= $commandToExecute . "\r\n"; // Catch console output ob_start(); // Execute the console program passthru($commandToExecute, $returnValue); // Save console output to a string variable (this s...

.NET Path.Combine() in PHP

I’m the type of person who prefers to do things in a way that I perceive as the proper or correct way. While this tends to make things take a bit longer to accomplish, I feel the result ends up being better overall. One such thing I noticed is that file and path handling in PHP was missing a function I used quite a bit when writing C# code. In C# there is a Path.Combine() function that appends two file paths together to form one complete path without having to care what the beginning character and ending character of the two paths are. I wrote up a little function in PHP to mimic what happens. // Take a path and/or a filename and combine them into one file path function filePathCombine($path1, $path2) { $completedPath = ''; // Check if path1 ends with DIRECTORY_SEPARATOR if (substr($path1, -1) !== DIRECTORY_SEPARATOR) { $completedPath = $path1 . DIRECTORY_SEPARATOR; } else { $completedPath = $path1; } // Check if path2 starts with D...

Lucid Ubuntu and GDAL Latest

I’m writing some software that relies on a feature of GDAL (Geospatial Data Abstraction Library) in a more recent version than the one Ubuntu Lucid currently has in their repository. As I write the software on my desktop, I found out pretty quickly that I was using an old version of one of the commands (more specifically ogr2ogr and the clipping functionality). Thanks to this site for the initial tip, it’s pretty easy to get the latest “unstable” release of GDAL installed without having to manually compile the program from source code yourself. If you are using Karmic or above, you can run these commands: sudo apt-get install python-software-properties sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable Or you can opt for the more involved version below: In your desktop, navigate to here: System -> Administration -> Software Sources “Other Software” tab Add these two items: deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu <codename> main deb-src htt...

Speed up Netbeans in Ubuntu Linux

Java Netbeans is a pretty decent editor for PHP code. I use Linux Ubuntu now for my primary desktop computer, so it’s quite convenient and easy to get running. One issue is that in default configuration the program is a bit slow feeling. Doing a quick search I found this page: http://performance.netbeans.org/howto/jvmswitches/ Which describes a few command line parameters that might help the IDE function faster. I’m currently running the command “/usr/bin/netbeans -J-Xverify:none -J-Xmx384m -Dsun.java2d.opengl=true” Basically, it removes one unnecessary verification check, adds 256mb of RAM to the default RAM pool the program can use, and attempt to use OpenGL to render the IDE. I am currently using closed-source video card drivers, so your mileage could very with that last parameter. You can modify your default system menu link by doing this: Right-click on the “Applications” dropdown system menu. Select the “Edit Menus” list item. Cli...

.NET MONO Which Operating System is Running?

Do you want to execute operating system specific code (exes) in the .NET/Mono framework? I’ll go over how you can do that. Below is part of a class I had written that can determine if Linux or Windows is running. Keep in mind that for the code to properly detect Mac OS, you will need to figure out the proper platform number and modify the code respectively. using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace namespace1 { public static class HostOS { /// <summary> /// An enumerator that holds a list of possible operating systems /// this code can execute on. /// </summary> public enum HostEnvironment { Windows, Linux } /// <summary> /// Determine the operating system this program is running on. /// </summary> /// <returns>The current operating system</returns> /// <rem...

Wordpress Visual Editor CRLF Quirk

Adding extra vertical space (eg. carriage return) to postings in WordPress can be a pain. While there might be a plugin to fix the issue, learned by searching around that using the code: <br class="blank" /> When in HTML mode will not be deleted by the visual mode processor. So if you flip back and forth between the two input modes, that code appears to be safe from being removed.

Securing a WordPress Blog

Please view this newer article for another method of securing the wp-admin directory from access. Here are a few tips to securing a wordpress based blog or site: Change the location of your wp-content directory. This is good for making your site’s source code less discernable as a wordpress blog. In the wp-config.php file: define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content'); define('WP_CONTENT_URL', 'http://example/wp-content'); Change “wp-content” to something else. Keep in mind that some plugins are not programmed correctly and have hard-coded links to the content directory as “wp-content”, so that could cause issues. If you notice your plugins not working, open the related source files and search for the phrase. ————————– Change the admin’s login name to something besides “admin” This can be done with something like phpMyAdmin to edit the database. The user_login varchar(60) field in the wp_users table is the value you wan...

Setting up a Source Control Server

Lately, I’ve been interested in the benefits of having a dedicated source control server. My goals for the project: 1. Have a dedicated server to store source and other files I’m working on that could benefit from source control and a secondary backup. 2. Have the server accessible through the Internet so that friends who I am working with can access our projects. 3. The server should be as low power usage as possible. 4. Attempt to make the server as secure as possible. Probably only have one port directed to it (either the http webdav or svnserve protocols on a custom port). I might also consider having ssh directed as well so I can use something like NoMachine NX Remote Access . Last weekend I ordered an “MSI Wind PC” computer to take on that role. This computer is sold as a barebones unit that doesn’t come with RAM or a hard disk. For about $220 total, I was able to get an ATOM based computer with a 750GB Western Digital hard drive and 1GB of ram. ...

Clean URLs in PHP Yii Framework

Here is a quick tip to save some trouble. The goal here is to get clean urls like http://localhost/site/test/5 or http://localhost/site/contact without having a query string variable and also not having the filename index.php show up. My configuration: EasyPHP (apache/php/mysql combo for windows) Yii PHP framework In the Yii main.php configuration file you need: 'urlManager'=&gt;array( 'urlFormat'=&gt;'path', 'showScriptName'=&gt;false,), Inside the ‘components’ array area. In the primary directory where the index.php file is you need a .htaccess files with this in it: Options +FollowSymLinks IndexIgnore */* RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] If you have problems, check your httpd.conf file for these items: <directory c:\easyphp\www> Inside that directory section, make sure the rules don’t disallow the removal of index.php or the other rewrite rule...