On SQL in PHP

Wednesday May 15th, 2013

There is no right or wrong way[1], but no matter what there is no *pretty* way to do SQL inside of a PHP application. I have been having a personal debate with myself all week about how to make SQL statements nicer in an application without going to a huge DBAL package like Doctrine.

[1] – There are actually plenty of wrong ways to write SQL. For example, “SELECT * FROM table WHERE id={$_GET['id']};”

Continue to full post…

Using braces to mark code blocks that are not literal language blocks

Monday March 18th, 2013

Did you know you can use braces to mark blocks of code for no reason other than to mark blocks of code? I have for quite a while but failed to ever find a reason as to why I would want to. Take this code sample for example:

The braces around the logic on how to do the search make it visually seem like code that is grouped together. And, you know, it is. The code folding feature in your editor is going to see this and allow you to collapse it if you want. It also creates a natural reason to want to indent those lines creating more visual cues to the relationship of those lines of code.

As far as I know this has no benefits to the actual execution, so it would be purely for aesthetics. I would say use sparingly, but is totally still a good thing to know.

Extending an Iterator to use an Iterator to make your code a little cleaner

Monday March 11th, 2013

image-iter

One of the nice things about iterators is the ability to shove them into other iterators, allowing you to wrap their functionality in other functionality to return a more precise result set. Take for example the idea that we want to read a directory to list only the images inside of it. There are two main ways to do this, via opendir / readdir functions and via FilesystemIterator objects.

Iterator Iterator Iterator…

Removing Thunderbird’s stupid tab/toolbar shadow

Friday February 15th, 2013

tbird-shadow1

Honestly, not sure why they (as in Mozilla) added this shadow but it looks bad and they should feel bad. It has been bothering me for quite some time now. On Windows 7 it was… annoying but on Windows 8 it just looks terrible, as it even conflicts with the window controls making them stick out instead of blend in with the window border. No other programs do this, so I assume it was just yet another attempt to give their UI design people something to do. Thankfully, it is removable via the userChrome.css.

Use userChrome.css to make Thunderbird look better…

Some lulz with set_exception_handler and app shutdown

Saturday February 9th, 2013

I have a class which handles page templating and is designed such that if it is destructed and has not yet rendered, it will render the current page out as is. The idea is that more often than not an instance of this will be managed by the framework automatically and on script end it will render the page out automatically without having to explicitly call a shutdown function.

On top of that, I recently added uncaught exception handling via set_exception_handler so that if any exceptions were uncaught the framework could render them inside a nice error template (and log them) like most other frameworks do. However, there was a problem with this that I have yet to perfect a solution for.

The problem is that when the PHP app ends, the exception handlers are released before the objects still active are destroyed, ergo exceptions thrown by the template class (like, theme not found) were not being handled and logged by my nice error template. This required me to restructure how the framework runs via events and routing in order to ensure that the exceptions thrown at shutdown were handled. Instead of allowing the script end to do the proper cleanup I had to add a shutdown function for the framework itself that the router automatically handles.

Continue to full post…

Testing PHP’s is_callable function against method accessibility

Thursday January 31st, 2013

Working on a class I had an instance where I was wanting to trigger a method in an object if the method existed. As I hit save with my property_exists code I realized that what if the method for some reason was defined as private? This utility would not be able to call it from a public scope. This lead me to pondering if is_callable was able to determine if things were callable taking into account scopes or not. Nobody really seemed to know… and the PHP manual was… unclear.

Continue to full post…

Permission denied (publickey) issues with Git on Windows

Wednesday January 30th, 2013

So the other day I installed Github for Windows and then after deciding I did not like it, I stole the copy of Git that it comes with and started using that from the command line. After working fine for several days, all the sudden I started getting this permission denied because of the publickey stuff.

Eventually I figured out that it was because I rebooted, which lead me to believe it was either ssh-agent not running or a missing variable. I personally hate ssh-agent, I find the very idea of it stupid. Nobody needs that thing sitting in RAM. It does not matter anyway, because when I tried running the copy Github for Windows came with, that did not change anything.

Continue to full post…

Fixed backgrounds on the bad that is all mobile browsers

Thursday December 6th, 2012

If the title didn’t give it away, first a rant. In fact this entire post is going to be full of rant. BUT it is also going to be full of things that might make you less pissed off yourself the day you need to do this crap.

Browsers work under two principles, viewports and documents. A document or page, is just what it sounds, the content of a website from the top to the bottom regardless of how long or short the page is. But what about a viewport? Well, I define a viewport as “a port in which you view shit”. For example your computer screen is a viewport which physically limits what you can see because eventually things scroll off the end. Browser windows are viewports. When the page is too long, it offers scrolling so that the content that is physically inaccessible by the viewport can be brought into view.

I want to know who was responsible for the retarded idea that mobile browsers should have no concept of  PROPER viewports (you will see in my demos why mobile browsers are half-assed). The damned things still have physical limits! The reason we consider viewports in web design is for anchoring objects to what you can see, not to what you cannot see. Take for example Tumblr’s button in the top right hand of the screen that lets you jump back up to the top of the page. That button works because it is bound to the viewport, not the document.

If you look at this blog on a Tablet or Phone, chances are the background image is positioned stupid and bad. That because until now I have never bothered to try and come up with any reasonable solution. Lets take a look at a project I was working on that forced me to solve this.

Continue to full post…

Train Conductors: Never installed yet Tweeting without permission.

Friday November 9th, 2012

I have been having problems with an application I have never seen, heard of, or yet alone even installed making Tweets on my behalf without my permission. Starting to get a bit upset. I really want Twitter to listen and revoke their API keys.

This is the second time I have had magic tweets added for me saying I scored 0 points in this retarded train app.

The two links in that are screenshots of the rogue tweet and the list of authorized applications, which has no train apps listed.

Basic camera design flaw Apple has never figured out – the lens cover

Wednesday October 17th, 2012

The Problem

Like any device the iPhones have had their pros and cons. But there is only 1 thing about the entire series of devices that has actually pissed me off to no end: the fact that the camera lens cover is flush with the back of the phone.

If you recall when the iPhone 4 came out and there was all that antenna drama about how people said the phone would not work without a cover, and if you recall that both Steve Jobs and I both went out of our way to call bullshit on that. The way we did that was, neither him or I ever put covers or bumpers on our phones… because we did not need them! Oh how foolish we were.

Continue to full post…

Twitter

 
Coderwall