Programming Languages
WordPress – Sharing A Base Class Amongst Plugins
Introduction The new series of MoneyPress plugins that is coming out in the next month is going to be based on a common foundation. This allows us to maintain consistency, share new features across the product line, and provide an improved quality product that gets out to the consumer. However, during the migration to this new shared platform we uncovered some problem areas deep within the bowels of WordPress. Yes, even with the recently released 3.0 version. However we don't blame this on WordPress. Far from it. WordPress is a well engineered application, it's only fault is being tied into archaic versions of PHP... which means anything prior to PHP 5.3 when namespaces were finally introduced. There is a reason many languages have had namespaces for years, but that is a discussion for another post. One of the more nagging problems was ...
More PHP Woes
I’ve been screwing around with the error response codes for CafePress and finally reached a dead end. My only choice if I want to support 4.3 (as the required version for WordPress 2.9.2) is to use this wonderful gem that Eric & Chris shared with me last night: $result = @file_get_contents($url); That hides all warnings & returns false into the $result variable. Why does file-get_contents() return an error? Because CafePress, rightfully so, returns a header with a 400 code saying “bad request”. The fact of the matter is my request is bad, I’ve input an invalid section ID, just as a client might to by accident. Rather than barf all over their web pages I’d prefer to catch the error gracefully, tell them about it, and move on. The problem is that file_get_contents will NOT fetch the content of ...
Using Common Sense With Perl
Since I was recently doing Perl work on the Boomerang project, I figured it would be a good time to finally try out common::sense, a CPAN module that, according to the documentation, will save a tree _and_ a kitten when you use it. I like trees and cats, so Hell, why not try it then? Long standing advice in the Perl world has been to use warnings and use strict in your code. However, the style of modern Perl has changed in such a way that it conflicts with those two things. It is common these days to write something along the line of @{ $var->[0] } but with ‘use strict’ enabled, you’re not going to get away with it. You would instead have to write it as @{ defined $var->[0] ? $var->[0] : [] } No thanks. That ...
Perl Regular Expression \K Trick
Regular expressions are a frequently useful tool in our profession, and Perl is probably the most advanced arena for testing your ability to wield regexes. That’s because Perl has the most feature-rich regular expressions out there (that I know of anyways). There’s always some new trick to learn about Perl regexes. Case in point: \K. Let’s say you want to replace the end of every line that begins with ‘Parent Commit:’, where that string is followed by whitespace and a forty-character hash. You want to replace the hash. But you have to hold on to the beginning of the string. Here’s one way to go about it: s/^Parent Commit:\s+[0-9a-f]{40}$/Parent Commit: $new_hash/gi This works, but repeating ‘Parent Commit’ is duplication we would like to avoid. s/^(Parent Commit:)\s+[0-9a-f]{40}$/$1 $new_hash/gi Here we capture the beginning of the string so that we can use insert ...
HTTP Errors When Uploading/Connecting in WordPress
Having problems browsing themes, uploading plug-ins, or doing just about anything that "talks" to the outside world via Wordpress? We have had a development server buried deep in our network behind several routers and firewalls that had a similar problem. Whenever we'd log into the dashboard we'd get various timeout error messages on each of the news sections. We'd not get our automatic update messages whenever there was a plugin update or a Wordpress update (3.0 is coming soon!). Well it turns out that we needed to fix 2 things to help speed up the network connection. Fix #1 - DNS Resolution We run this particular development box on Linux. That meant updating our /etc/resolv.conf file to talk directly to the DNS servers. If you use DHCP configuration or go through a router this file is often ...
array_key_exists() versus isset()
Everyone here has the good habit of testing for the existence of keys in a hash before accessing them, since otherwise logs can quickly fill up with notices. There are two ways to make this check: 1. array_key_exists() 2. isset() You should prefer to use isset(), as it is significantly faster. Here is a test and the results I got on my computer: for ($i = 0; $i < 1000000; $i++) { if (array_key_exists('not_here', $foo) && $foo['not_here'] === 'nomnom') { echo "Not here\n"; } } This took 20.5 seconds to run. for ($i = 0; $i < 1000000; $i++) { if (isset($foo['not_here']) && $foo['not_here'] === 'nomnom') { ...
Logistics & Inventory Management with Alutiiq
Alutiiq recently award Cyber Sprocket a 1-year teaming agreement, making this our 4th year of working with Alutiiq on developing, supporting, & maintaining their military logistics & inventory management application. We are very excited to be working with Alutiiq for another year. The upcoming year will bring some exciting new possibilities for follow on projects that augment the system already in place. We're looking forward to being part of the design & development team and supporting our clients and our country both at home and abroad. Technical Overview Services Provided Web Application Programming Database Design Database Maintenance System Architecture Network Support Platform Details ASP.Net / VB.net IIS MS-SQL HTML Javascript CSS
Device Interfaces with Simma Software
Simma Software needed solutions QUICK and Cyber Sprocket rose to the occasion. In one of our fastest turnarounds from new-client to completed solution, Cyber Sprocket was able to work with an expert in the field of CAN and J1939 software. If you are unfamiliar with those terms from a technical standpoint, we are certain you are familiar with the devices that run on those standards - vehicles of all shapes and sizes. While Cyber Sprocket Labs had a small role, it was a great experience for us. We learned a lot of new things in just 48 hours and even got to play with some new toys that Simma Software sent us while working on their software updates. Our C# experts go to work and knocked out some system upgrades with time to spare. Quite a feat considering the 48 hour turnaround ...
Consumer Web Apps with Abundatrade
When Abundatrade decided to take their project to the next level they chose Cyber Sprocket Labs to help them get there. They brought their existing website to us and asked us to help. They were looking for a more fluid, more enjoyable web experience for their users. They needed an updated easy-to-use web calculator & they needed it fast. Cyber Sprocket did the job quickly & did it right. More than a year after that first quick "help us fix our site" project we are still helping them push their technology further. We are now not only helping them slowly morph their consumer services into something bigger & better, we are also helping them run their operations more efficiently by integrating the web technologies with their daily operations & services that run the business. The main part of the consumer interface is a product valuation calculator. Using ...
Anonymous Functions With Names?
I discovered an odd thing about JavaScript last night. As you know, one way to add methods to an object is to assign anonymous functions to property names. For example: var foo = { woo: function (鯣) { print(鯣); } }; Strictly speaking, our function has no name. We just happen to assign it to a property which we can use to call the function. Contrast that to the ‘normal’ way of defining functions: function woo(色魚) { print(色魚); } But here’s the weird thing, we can combine these two styles. var foo = { woo: function specialHiddenName(鯣) { print(鯣); } }; We get no error for this. Interestingly, I could not find a way to call the function using specialHiddenName. So ...
Messing With Namespaces and Anonymous Functions
PHP 5.3 has been available for a while now. But since it will likely be a while before I see it on most servers, I didn’t rush to get 5.3 and mess around with it. It’s not like I’ll be using the new features any time soon. But I’m using the beta version of Ubuntu 10.04 and it comes with PHP 5.3. So since I have it now, I figured it was a good time to familarize myself with the new changes. Humorously, I forgot to update my local copy of the PHP documentation. So I thought about how the two main new things I wanted to try out were namespaces and anonymous functions, and then put together a test script by taking guesses at the syntax, based on error output from PHP. Here’s what I came up with:
Tab Completion for Custom Commands
A lot of commands in Emacs take input from the minibuffer, the little one-line area at the bottom of the editor. When you are writing your own commands you will often make use of the same facility. In this article I want to show you one way of doing that which will provide tab completion for your custom functions. I’m going to use a simple example out of my own dot Emacs file. This is the function that was in my last email, my function for opening org-mode log files. I keep one org-mode file for each project, in a log directory, split up by year. So I wanted a simple command I could bind to a key that would let me type in a project name and open the file. So I have this: (defun open-project-log-file (project) "Opens a ...
Pitfalls With Optional Arguments
Let’s talk about a couple of problems we can run into when writing functions that have optional arguments. First there is the matter of how we should declare such functions to begin with. If our function can take any number of arguments then it is easiest to use the ‘arguments’ array inside of the code. This array[1] is always available inside of our functions, so if we have an unknown number of parameters we can loop through it to get all of them. function Σ() { var total = 0; Array.forEach( arguments, function (n) { total += n; }, this ); ...
Holy Hell, Properties!
I was studying the code for Mozilla’s Venkman program and discovered that the Mozilla platform supports properties for Javascript objects. Now when I say properties I mean in the sense of Python, C#, Visual Basic, and so forth; members of a class whose getters and setters are called transparently. That is, when we write code like print( user.access ); user.access = “Admin”; it gets translated into print( user.getAccess() ); user.setAccess(“Admin”); We can actually do this in Javascript on Mozilla's platform! The way it works is by calling __defineGetter__() and __defineSetter__() on the prototypes of our classes. The each take two arguments: the name of the property as a string, and a function implementing the getter or setter behavior. Here is an example. var userLevelmap = [ "None", "Standard", "Premium", "Admin" ]; function User() { this._access = ...
Scoping in Javascript With ‘Let’
In my post yesterday about multiple-values I used the keyword ‘let’ in some of the examples. This is another feature of the Mozilla Javascript platform. I assume it is named after ‘let’ from Lisp, because it performs the same task: letting you bind values in block scope. As you know, the scope of variables in Javascript is the entire function in which they appear. So take a trivial function like this. function foo() { var f = 10; print(f); { var f = 20; print(f); } print(f); } When we call the function the output will be 10 20 20 Our rebinding of ‘f’ inside the inner block changes ‘f’ on the outside. ...

