Archive for March, 2008

oEmbed, or what I did instead of reading for class

Friday, March 28th, 2008

Like I said, I was writing a wordpress plugin. I wanted to automatically highlight code posted within <pre> tags. And no, I didn’t want <code> tags b/c those aren’t part of the native wordpress editor toolbar – the goal was to be able to embed highlighted code while just being completely lazy and staying the “Visual” tab.

This got boring really quickly, especially once I saw that someone had already done something similar, except weak and pointless. If I’m going to upload “code snippets,” why don’t I just run them through enscript while I’m at it and paste the damn output?

Anyway, then I thought “Hey, this flickr plugin I’m using kinda sucks and isn’t very good about letting me pick which size of photo I want to embed.” It’s a global setting. FAIL.

So then I thought “If Crowley’s drunken ramblings about some sort of open standard for embedding media had any actual substance, I could easily improve this.”

They did. He was talking about oEmbed.

I’m gonna cut this story short because I’m fucking burned, but here’s what I posted on Cal Henderson’s website’s discussion:

I’m messing around with oembed on flickr – not seeing a way to specify which size of the image I want to embed. I tried some combinations of changing the URL and maxwidth/maxheight settings in the request, but to no avail. I tried: www.flickr.com/services/oem… www.flickr.com/services/oem… www.flickr.com/services/oem… All three return the same thing: [ the xml output of this request ] Are we not there yet? I was thinking of making a flickr oembed wordpress plugin. It’ll still work, but will be limited to the one size. Is there a way to work this? Would it be possible to set up server side logic @flickr which actually checks the /sizes/foo part of the URL and returns the appropriate URL/size info? I haven’t thought about it long (and it’s late) but that seems to be in line with the standard – would only have to change the url GET var in the request, putting all the logic on the providers side and just spitting out the right image. Cheers. Mike.

I’m Writing a Plugin

Friday, March 28th, 2008

if the blog is broken in the next few hours, it’s because I’m testing shit.

Mustache Man, Ep 1

Friday, March 28th, 2008

How Mustache Man became Mustache Man

Brooks Brothers Sucks

Friday, March 28th, 2008

So much to write about tonight, but it is already 2:30 and I gotta get to bed. Awesome posts coming over the weekend on topics such as framework ideas, mustache art, sneaker art, furniture design, and how bad ass my pad is going to be next year.

For now, though, I leave you with this abomination. Clearly someone at Brooks Brothers in the St. Louis Galleria mall is smoking meth by the bag.

brooks brothers sucks

Project ADD

Wednesday, March 26th, 2008

Just had another “AWESOME” idea today that fits nicely with my desire to create something that can stay with an app as it grows. Once ked_core functionality is more or less finalized (sooner rather than later), I’m going to start hacking up a pecl extension that will mimic ked_core’s behavior perfectly, thus allowing the developer to simply comment out the require_once statement in index.php having installed the extension, maintaining the exact same behavior, but with less overhead, since the framework’s core will now be compiled.

As Crowley put it, that is overkill. I know. But I need to learn how to write PHP extensions :)

I realize that I’ve started more projects in the last month than I have in the last 2 years. I am going to prioritize things a little bit – I want to focus on ked_duffel (the SVN delivery system) to start out, then once that’s functional use it to update mihasya.com’s framework files, then tinker with the framework a little bit, using duffel to test it on mihasya.com.

Once I’m happy with its functionality, I’ll start compiling a pecl skeleton and trying to fill it out, making heavy use of my rollover minutes – to call Crowley with dumb C questions.

Of course, all of this is going to have to wait a little bit – I realized recently that nearly two weeks had passed without me having done any paid work. Someone has to pay for Crowley’s lapdances, so I am going to dedicate a bit more time to Yahoo! stuff in the coming couple of weeks.

Introducing “Operation Mustache”

Tuesday, March 25th, 2008

There has been too much jargony serious posting going on lately, so I’m going to dilute it a little bit with a post about Operation Mustache.

What Is It?

David L. and I are growing mustaches. Then we’re going to do mustachey stuff with them. Partially inspired by the “McStroke” episode of Family Guy, which you can see on Hulu. I highly recommend it.

How Far Along Are You?

Not very far. We are still at the point where the rest of the facial hair has not been shaven off. Mine is also looking very watery due to my light hair color. Gonna have to Just For Men that thing. Dave’s is a week behind (he started later) but is much darker. You can see what mine looks like right now.

Actionless Views: The Quest For Perfection

Monday, March 24th, 2008

The idea here is being able to route ked_core to a static template w/o executing any action or having defined one. For example, if you want your header to just be static HTML and want that in a separate header.tpl file, there’s no reason you should have to define controller->header() just to access that.

I went through several iterations on this code (some of it is in svn, though not all – I had to start the repository over b/c I forgot to add trunk/ branches/ and tags/ :( ) so here is my approximate thought process.

Step 1: Check the .tpl exists

I should have had this check anyway, but before I did not realize the need – there needed to be an action defined for the view to be rendered anyway, so I focused on that, and that seemed to take care of itself. The following line would just throw an Exception

$reflector = new ReflectionMethod($this, $action);
which would then just be handled and displayed nicely with ked’s exception handler.

But now I really do need to actually handle this on its own, since the action might not even exist – WHAT WILLS WAE DO THARN?!

The Wrong Way:

if (ked::$smarty->template_exists($tpl)) { ...
No. That is clearly a file system operation that will be run every single time, even though we know that 99% of the time, unless the developer is a total and complete dunce, the template is there. Then there’s the additional fs read to load the template.

The Right Way:

The right way looks sort of hackish, but bear with me. Smarty is really dumb about how $smarty->display() works. It never returns anything. If it fails to load the template, it prints a warning. Can’t really check to see if it succeeded in any robust way, so this will do:

...
ob_start();
ked::$smarty->display($tpl);
$viewContent = ob_get_contents();
ob_end_clean();
if (!$this->_skipAssign) ked::$smarty->clear_all_assign();
if (strpos($viewContent, "<b>Warning</b>:  Smarty error: unable to read resource:")!==false)
  throw new kedException('The view "'.$this->_view.'" was not found')
...
I just check for the presence of the warning and throw an exception if it’s there. Now, normally, I am not a fan of throwing exceptions, but in this spot it’s ok, and I’ll explain later why. The short explanation: because we’re not catching it.

Step 2: Make _execute Not Choke On Absent Action

The Wrong Way:

This is where I originally threw an exception, but a comment by David Hall made me pause.

...
try {
  $reflector = new ReflectionMethod($this, $action);
} catch (Exception $e) {
  $this->_skipAssign = true; //tell _render to skip smarty->assign related steps for this.
  return false;
}
...
So here, we just try to create a ReflectionMethod as we normally would for the action, but if we see an exception, we just return; out of _execute and go on to _render. It’s sort of sloppy (because what if ReflectionMethod’s __construct() threw an exception for some other reason) and the real problem is this: we are creating and catching an exception in framework code. Every time an actionless view is called, this will happen. David pointed out that the exception is itself an object and can be quite heavy.

The Right Way:

This caused me to revert to my original intuition for how to do this:

...
if (!method_exists($this, $action)) {
  $this->_skipAssign = true; //tell _render to skip smarty->assign related steps for this.
  return false;
}
...
We just check if the method exists; if not, we set a variable that tells _render to forego assigning template variables that would have been set in the action had it existed and return false. (Right now, just returning would suffice, but I feel a disturbance in the force that tells me that this false value will come in handy somewhere down the line).

Step 3 (bonus): Make _render More Efficient

I alluded to this in an earlier code snippet: now that we can know for sure if an action has been executed, we can do this:

...
ob_start();
ked::$smarty->display($tpl);
$viewContent = ob_get_contents();
ob_end_clean();
if (!$this->_skipAssign) ked::$smarty->clear_all_assign();
if (strpos($viewContent, "<b>Warning</b>:  Smarty error: unable to read resource:")!==false)
  throw new kedException('The view "'.$this->_view.'" was not found');
$this->viewContent = $viewContent;
$this->_skipAssign = false; //reset this to make sure subsequent actions don't get tainted
...
We check the bool we set earlier and forego template var assignment if it’s set to true. Once again, the exception is fine because we’re not catching it, and this is meant for exceptional cases that are supposed to grind our application to a halt. Unlike the case in _execute, this wont’ be called every time there’s an actionless view – just in the case of an error.

What Did We Gain From All This?

Well, I listened to a bunch of really fucking good music on my ipod while doing this, so that’s good enough for me. But seriously, I also ordered like 6 Threadless shirts.

Also, as a side benefit, the framework now supports actionless views without any extra file system operations. It is also wise enough not to bother assigning template variables if the template is static. You also don’t have to define anything special in the controller (in fact, nothing at all is needed there) or in the template to accomplish it – just put the static .tpl file in the right folder under inc/tpl/views.

I also used the word “tainted” in the comments… which is pretty close to “taint”… which is the area between the ass and the balls. That’s a wrap on the day.

Stupid Radio

Monday, March 24th, 2008

That damn song about makin “love in da club” is stuck in my head.

As a consequence… I wanna make love in da club!

So What Happened Last Night?

Monday, March 24th, 2008

Fail, that’s what happened. A big fat sack of fail.

So as I was working on mihasya.com, I was simultaneously tinkering with ked_core – a natural thing to happen, since mihasya.com is a test for how ked_core actually does when used in practice (it kicks ass, fyi). I got the idea to permit actionless views (more on how, once again, I did that better than you later), so I got all excited and immediately hacked up the code. So now I had this code that was directly applicable to mihasya.com (a lot of the inner pages don’t do much, so don’t need a controller function defined) in the ked_core svn, but not on the site.

The problem is: now that ked just ships as a big hunk of folders with the internal files and the site’s own files mixed in, the separation gets tricky. Also, my blog/ folder (the WordPress install) had to go under mihasya.ked/www/blog, as that was what my mihasya.com folder was symlinked to… Long story short, I straight up deleted mihasya.ked. That was fine, I thought, because I still had all that code in svn…. OOOOPS. Thank goodness for database storage.

Where This Leaves an Ambitious Mother F@#$%#

Well, this is a problem I gots ta solve. It’s plagued me for years, as applications come shipped in huge tarballs that just extract like they’re kings of the world. If you want to selectively update something, you have to cp files one at a time. Fuck that.

How do I elegantly, and from within the framework, permit the developer to upgrade ked files, but not affect his own? This could be solved easily by some sort of package manager like apt or rpm, but we don’t have that luxury. Or rather, I won’t give myself that luxury. This will be solved with bash, php, and svn in the spirit of minimalistic requirements. After all, it has to work on Dreamhost :)

What I Intend To Do

This is how it’s goin down, homegirls: I am going to write a shell script which will fetch a special file from a predetermined svn location (the repository doesn’t have to be static, as I’m sure ked will have thousands of mirrors as it sweeps the market ;) ) The file will contain a listing of files which are internal to ked. It will probably just look something like this:

...
inc/controllers/internal
inc/core
inc/tpl/layouts/internal
...
The script will check the internal files on the repository for updates (including a self-update), download them to a separate copy (to avoid messing up your own .svn folders, if any are present) and copy them into your own dev tree.

One problem I’m already seeing before I even start hacking this up is that www/index.php contains configuration information that I refuse to move into a conf file (extra file read) that might get overwritten in this way, but I can probably figure out a way to handle that without quite developing a full blown package manager variable manipulation deal. Or maybe I’ll just do that. Cuz I can, son!

Stay tuned for more on this and other ked shenanigans.

MASSIVE FAIL!

Sunday, March 23rd, 2008

I accidentally deleted my wordpress folder. All plugins and uploads are temporarily gone. Lessons:

  • less mv, more cp -Rf
  • less mv, more ln -s
  • host photos on flickr. always.