Indy!!
from indiana import jones import whip import ruins cave = new Ruins() trap = indiana.steal( cave.treasure ) indiana.escape( trap )
ImportError: Snakes? I hate snakes!
Far Too Sweet To Be Sour
from indiana import jones import whip import ruins cave = new Ruins() trap = indiana.steal( cave.treasure ) indiana.escape( trap )
ImportError: Snakes? I hate snakes!
One of my favorite features of C# is Partial Classes. For the uninitiated, it is a way of defining a class in two separate locations. Very useful when you have code generation utilities such as LINQ.
Unfortunately, PHP has no such feature (though if anyone's listening it would be a great feature to add to the PHP6 feature list), however thanks to the magic of __call($method, $args), __get($key), and __set($key, $value) overload functions as well as passing by reference (aah the good ol' &) we can imitate partial classes.
The idea behind this partial class hack is to instance a copy of the partial class in question and have our magic functions forward any undefined requests to the partial class.
The partial class (probably with the naming convention Partial_CLASSNAME) will contain a reference to the main class and also have magic functions forwarding undefined requests to the main class. The reason why we have our magic functions in the partial class is so that any internal references can still be made (methods in Partial_CLASSNAME must have access to the methods and members in CLASSNAME).
The constructor in the main class will automatically seek out the partial class (and additional coding can be done to seek out more than 1 partial class as well as do some integrity checking) so that the programmer does not have to intervene to form the 'full class'.
At the risk of being marked as blog-spam, I got some pretty funny spam messages in my junk folder recently:
Annoyed by fiasco in bed? Light up now! Leave tiresome experience behind! nice escape is attainable! Flood of feelings is just a few clicks away!
Had enough of problem in bed? Cheer up now! Leave harrassing experience behind! urgent rescue is almoust there! Wow emotions is just minutes away!
Bored about trouble in bed? Liven up now! Leave tedious experience behind! quick help is within reach! Awesome bedtime is just a blink away!
Feeling uneasy about problem in bed? Cheer up now! Leave unnecessary experience behind! emergency is almoust there! Perfect date is just minutes away!
Frustrated disaster in bed? Perk up now! Leave odd experience behind! your magic remedy is available! Emotional breakthrough is just inches away!
Bored about problems in bed? Liven up now! Leave monotonous experience behind! your salvation is accessable! Unforgettable sensation is just inches away!
Disappointed at troubles in bed? Get up now! Leave worrying experience behind! helping uplift is within reach! Emotional breakthrough is just a few steps away!
It's a fun game trying to figure out what each message is peddling. Is it mortgage refinancing, watches, or penis enlargement pills? It's like a mystery!
My copy of Pro PHP: Patterns, Frameworks, Testing and More by Kevin McArthur has already been worth the money I spent on it.
In our, albeit slow, upgrade to more modern development practices (code version and unit testing being the last elements on my list), I was particularly fearful of code versioning namely concerning issues of automating a build process to export a copy of the repository to our shared development server, or just have a local server installed for everyone one.
However Chapter 8 has pointed me to two programs that I sincerely regret not having heard of until now: Phing and Xinc.
Phing is a build system written in PHP that works extremely well with PHP and PHPUnit. You can configure your own build targets, for example like "get" (SVN update essentially), "test" (run PHPUnit or any other unit testing), "try" (copy to a development server), and "deploy" (copy to your live server).
Xinc is a continuous integration server. Essentially, it monitors an SVN repo and performs a user defined action (usually running a phing buildscript) on any changes to the repo. Which is awesome because its solves the issue of updating the dev server. Having Xinc run a > phing try on SVN updates is exactly what we need! I'm even having delusions of grandeur of having it monitor tags for doing live deployments as well.
Don't take my word as gospel, I haven't actually installed and tested these systems out, but when I do you can rest assured I will be writing about it.
(This is the sequal to my previous post, Database Normalization And Design: A Primer)
Continue reading ‘Database Normalization and Design: Part II’ »
I am by no means a database expert, such titles are best left to people like Peter Zaitsev and Vadim Tkachenko, however one of my co workers has been asking me for some help on how I come about my database designs, particularly issues concerning normal form.
Whlie I could spend several posts going over the intricacies of 1st, 2nd, 3rd, and 4th normal form as well as "The key, the whole key, and nothing but the key so help me Codd" Boyce-Codd normal form, however reality dictates that time spent strictly to these academic levels is either time wasted (projects with due dates unfortunately cannot spend forever on the database design) or pointless as being reasonably intelligent will bring you very close, if not within 3rd normal form.
If you're really interested, Wikipedia provides a great resource to get started learning the more academic aspects.
I'm going to assume that you have done a bit of database work and at least understand the concept of a join.
The one of the goals of database normalization is to reduce the repetition of information and thereby reduce the complexity of an update of said information. If the same string is in the database N times, we should abstract it so that if we need to update said string due to a typo or anything else, we need to only change but one location.
Continue reading ‘Database Normalization And Design: A Primer’ »
In my previous article (Microsoft Access and PHP), I discussed getting mdbtools setup and dynamically interacting with a instance of mdb-sql. Well it turns out somewhere in the pipeline (probably mdb-tools), we're either not getting an EOF or reading an EOF right and as such I can read lines from the program's STDOUT stream, but as soon as I hit the end of the output my script hangs indefinitely waiting for something and all my attempts at detecting an EOF failed. Sorry to disappoint.
On lighter news, my coworker got the greatest error ever:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
Turns out according to these guys it's Hebrew and refers to the double colon (::) operator.
Right...
Microsoft products can really be a big wrench in the finely oiled machine that is your development environment. While Microsoft does offer some excellent products and development tools, when you work from an open source context, these great tools become great hazards and headaches.
Case in point, access databases. Take as a recent example, a client that gets its data from a third party. That data comes in a Access (.mdb) format, probably convenient for the producing company as well as the assumption that chances are very likely that the person receiving the data will be able to read it (due to the widespread availability of Microsoft Office).
Importing said .mdb in PHP is not so nice or convenient, that is if you aren't running your server on Windows (which chances are you aren't). In Windows you merely need to either create an ADO object (or use ADODB), or use COM to communicate with a local install of Microsoft Office to trigger an export. In Linux, neither of those choices are even available. However we thankfully have some good command line utilities, for example: MDB Tools. (Tip: Check out a copy from CVS if 0.5 is segfaulting on your database)
In addition to some unixODBC drivers, it provides some very nice command line utilities like mdb-tables (which prints the tables in a .mdb file), mdb-schema (which prints the schema for all or a specific table), mdb-export (which produces a CSV output of a specific table in the .mdb), and mdb-sql (which provides a subset of SQL interface to the .mdb file). All of these tools come together to form a very nice tool set to import a .mdb file.
Fun things however, as I was working on my import script (I was just using simple exec() commands and getting full output and parsing from there), I decided to play around with stream programming and provide an interface to mdb-sql using proc_open() to make the import less memory intensive. I ran into some snags using fgets() on the STDIN stream and when I solve those I'll post my code and a tutorial.
I was helping a coworker the other day with some object oriented design issues in PHP and thought it would be great to share with the general PHP community as the general PHP community seems to lack in good OOP skills.
The task, which will be detailed later when we release it, boiled down to having a collection of files we needed to perform an operation on. Sometimes the entire collection, sometimes just a subgroup. Currently the system will only support 1 kind of file however in the very near future a new file will be added. My coworker tackled it well but a few problems that I helped him out with. Namely he made a few common mistakes in the design that most PHP developers make, namely being inconsistent with naming/etc. and not utilizing Interfaces and argument type-hinting to enforce good design, as well as putting logic in the wrong classes.
One of the few pitfalls that did happened was placing the render() function in the collection class. While this would not be a problem for a single type, when extending the system to handle n node types we come across unnecessary complexity issues in adding to the render() function, as well as making it nigh-impossible to keep the original includes intact (so as to make upgrades work without the hassle of merging code).
Matt Kohut posted on the Lenovo corporate blogs a very good sign of industry Linux support.
According to Kohut, Lenovo will be expanding its Linux offerings not just by expanding their preloaded selection, but by porting the ThinkVantage software (their "Craplet but Not Craplet" driver/application suite) to Linux.
Normally all I see as far as far as industry Linux support goes is just installing Linux on a few machines, but not really expanding Linux itself (through drivers and software). I have high hopes (which will probably be dashed like they always are) for Lenovo's offerings as they intend to port their drivers and management software.
In a perfect world I would like to see open sourced applications centrally distributed by Lenovo for multiple distributions (they currently will only preload SLED). In a perfect world I see modularized drivers that would allow more savvy users to install a hard disk shock driver but write their own OS integrated interface, or a user would install Lenovo's interface.
I also see much potential for their port of their presentation mode software. Currently dual monitors in Linux is a bit of a bitch to deal with, and I can potentially see them develop an application that would be usable on other laptops for quickly setting the monitor out port to be an 800x600 desktop that Open Office or Totem would send their full screen output to. While from a business standpoint this is not so much of a smart move (a competitive advantage via exclusivity is lost), the Linux crowd tends to handsomely reward supportive companies that make moves like this with free press, referrals, and making their next purchase through these somewhat philosophically aligned companies. Given the Linux user is the guy 10+ people go to for hardware purchasing advice, the sheer scale of 100 techies telling 1000 people to buy Lenovo machines because of how impressed they are with their support of Linux can't hurt at all. One need only look at the gPC and how Walmart could not keep enough in stock.
Since the ThinkVantage software appears to be written in .NET 2.0 (the update utility requires .NET 2.0, so I think thats a reasonable assumption), maintaining ports should not be entirely difficult thanks to the inroads the Mono project has made. I would love to see care made to make native feeling ports of the software rather than just dumping the same interface their Windows counterparts use (e.g. splash screens are usually frowned upon in Linux software, especially with system utilities). Since SLED is now GNOME based, I'm really hoping that their team decided to go for GTK+ and sticking to Gnome HIG for their interface, however given that QT is more easily portable, I fear a nasty looking QT setup (Disclaimer: I dislike QT from a visual standpoint. It's a good toolkit but makes for an inconsistent, unpolished interface).
One fear I do have is seeing Lenovo attempting to reinvent the wheel with their suite. There are many things that Linux already does well that do not need yet another third party application attempting to perform from scratch. One in particular is the network-manager applet that installs with Gnome most of the time. I find it to be an extremely easy to use wireless and network configuration utility, especially when you expand it with VPN plugins.
However I can see Lenovo stretching itself too thing trying to do a 1:1 port of the ENTIRE suite when they are better off ensuring packages like network-manager and power-manager from the gnome desktop or their KDE equivalents are installed and focusing their time on missing features, like easy fingerprint setup (perhaps contributing to the gnome keyring manager by allowing it to authenticate through PAM, allowing for finger swipes to unlock the keyring), hard disk shock protection (completely lacking on this aspect), presentation manager, and setting up and providing quick interfaces to all the special keys and shortcut buttons (namely the ThinkVantage and forward/back buttons do not work out of box). The could also spend their time contributing wifi drivers (or contributing to existing drivers) to fix some issues like the wifi light not working, as well as working with the major distributions to eventually work in the fixes they create to allow Suspend to RAM and Suspend to Disk to operate without dying.
As a final request and hope, please make sure you not only provide binary packages, but APT/YUM repositories as well for keeping the applications up to date (the update software can easily be reduced in complexity by using built in package management software).
All and all, my hat is off to Lenovo for taking the extra step in their Linux support by (potentially) supporting the community, not just installing a distribution and calling it a day.