Weird Issue between Smarty and Google Maps

I’m doing some work on a site that uses the google maps API (which is clean, simple and absolutely fabulous, by the way) and I have bumped into a strange problem. When I draw the page that uses the google maps api with smarty everything works fine, generally. However if I put the {debug} tag into the template (which causes smarty to give you a nice little pop-up window of all of the variables it’s working with, and some other great info) google maps stops working.

This isn’t really that shocking, since there is a bunch of javascript that gets pushed into the page by debug, what is weird, and a pretty large problem is that once I do this, google maps continues not to load, even after the {debug} tag has been removed. I haven’t really dug into what is going on to carefully yet, but its an interesting issue.

Really lame solution found after the jump

Continue reading Weird Issue between Smarty and Google Maps

Meditations on Craftsmanship

Recently I have been somewhat frustrated with some aspects of my work. (See previous post.) I have decided that in many ways I have wandered off track in my work, and I need to start writing code that I like again. By chasing after efficiency, I have allowed quality to become a second priority, and in doing so have begun to lose morale as well. I feel as if this is a very common problem in modern practical programming, and as if it’s a good thing to explore solutions to. For the last several weeks I have been searching for a book on programming that covered tools, tips and tricks for making yourself feel enthusiastic about what you’re working on, and dedicated to doing it well. So far I have not had much luck.

What I have found is a lot of books that tell me about tools for generating quality work, but ignore the emotional end of the process. One of the few bits of emotional advice that they do turn up repeatedly is that once you let some of a project start to slide into a lower level of quality, all motivation to keep the quality level up drains away in what is typically called “Broken Window Syndrome“. What they don’t talk about is how to recover from it (my own personal holy grail, since I am so often brought in to save messed up projects) or how to feel a sense of quality to start with.

Since I am feeling around in the dark, I thought I would take two blind stabs at raising my quality level. The first idea I am putting into practice is literally sitting down and meditating on quality & craftsmanship before I start to work on a project. This means 15 minutes of cross-legged, closed eye meditation, thinking about the nature of quality, (very much in the style of “Zen and the art of motorcycle maintenance“), and on my own personal visions of a true craftsman at work. This does seem to help.

The second part of this approach that I am taking, is to start a personal project and try to hold it to a very, very high standard of work. The idea behind this is to help develop the habits of quality, and help it become a familiar thing. This will probably be a cakePhp project, which I will most likely write about more here. I’m already looking into getting started with unit testing for it, but more on that later.

If anyone has any tips on emotional self management for programming, or can refer me to a book on it, that would be great as well.

Adobe AIR and digital certificate password length

I’ve received several e-mail messages over the past couple months letting me know that the desktop magic eight ball application I created for a beta version of Adobe AIR no longer worked.

Naturally, it wasn’t the highest priority on my to-do list, but I finally decided to get around to it. But I kept getting an error message: “no such file C:\air\eightball\in”
Continue reading Adobe AIR and digital certificate password length

Emacs and osX

I am a huge emacs fan, to the point of having written my own major mode for working in coldfusion when I couldn’t find one that satisfied (rather than moving to another editor) Its something that I see as part of my personality, almost like a political affiliation. I also happen to be using a mac at the moment, and my first few tries at using emacs under osX went pretty poorly, but I did work everything out, and I thought that I would write about it some to save everyone else the trouble.

First off, I initially tried just installing a standard version of emacs and using it through the terminal. As it turns out that has a lot of problems, particularly with keys being in odd spots (the meta key behaves a little oddly) and with the interaction of cutting / pasting / killing and Yanking. The next try was xEmacs under the mac X11 server. That was an instant disaster.

My third try was with aquamacs which worked decently, but I still found to have several frustrating bits of unpolished interaction. I could have lived with this indefinitely, but another emacs fan I know suggested I look at carbon emacs and wow am I glad I did. This is what emacs for mac should be.

The only major change I needed to deal with is adding (setq mac-option-modifier ‘meta) which made the damn meta key work in a way that doesn’t drive me nuts.

So for those of you on a mac, consider having a look.

Very Frustrated with mysql on the mac

So I just discovered a little bug with mysql in general, and which I am finding extra frustrating on the install I have set up on my mac. The short version of the problem is that if you have a whole lot of tables in a database the application “mysqldump” no longer works, producing

Got error: 1016: Can’t open file: ‘./<database>/<table>.frm’ (errno: 24) when using LOCK TABLES

So I followed up on this, and it seems like this is a somewhat known bug. In particular the problem is noted here: http://forums.mysql.com/read.php?28,162893,162893 along with a solution. However for some reason the mac version of mysql is not obeying the open-files-limit param, either when I pass it through the command line of mysqldump (which doesn’t recognize it as a viable option, or when it is set in the config file my.cfg and rebooted. I happen to be runing mysql version 5.0.51a

Cake CleanUpFields

Yesterday night I managed to get stuck on my cake project it two separate places, which is sort of amazing since I have only been stuck with cake once other than that on this project. (To Be fair, One of the problems is with Plesk, may it’s name be damn for a thousand years, not cake)

Anyway, I just solved the other problem thanks to the comments on this post, and I thought I would share.

When you cuse cake’s helper to pick a date/time it builds a whole lot of sub-fields. Then when cleanUpFields is called it stitches them all back together into one date time. However, it’s a little too smart for its own good, it only stitches them back together if it knows about the date-time, and it only knows about the date-time if that field is in the primary model for the controller your working with. This means that if you are using a second model , it wont fix the date-times.

The good news is that their is a work-around for that, you can simply call cleanUpFields again, with the second, or third model name as a param. (I.E. $this->cleanUpFields(‘payments’); )

What I haven’t found a work around for however, is if you want to get a date that doesn’t belong to a model at all. hopefully I will stumble on an answer as I continue with this, If I do I’ll post it in the comments.

schizophrenic code (It talks to itself)

The third part in the Introspective debugger code breakdown, Lets look at what happens when the code actually stops at a breakpoint…

The first chunk of code uses some globals and the backtrace to figure out if it should actually stop or just keep going I will break this down in detail later, when I go over the breakpoint code
function idbg_tick_function(){
global $idbg_stop_flag, $idbg_id, $idbg_var_spy, $idbg_last_line, $idbg_backtrace; $idbg_backtrace = debug_backtrace();
// echo ($idbg_last_line. ” ?= ” .$idbg_backtrace[0][‘line’] .” in “.$idbg_backtrace[0][‘file’].”<Br/>” );
if($idbg_stop_flag and $idbg_last_line != $idbg_backtrace[0][‘line’] and !strpos($idbg_backtrace[0][‘file’], ‘STOP.php’))
{ //echo(“</hr> idbg_tick_function START <br/>”);
Next Up We open up a tcp server on the socket of our ID, which will always be a high port. $socket = stream_socket_server(“tcp://”.$_SERVER[“REMOTE_ADDR”].”:$idbg_id”, $errno, $errstr); if (!$socket) { echo “<h1>Debugger couldn’t open socket: $errstr ($errno)<h1/>\n”;} else { because, its what they did in the example code for opening sockets, we read using a while string.I’m pretty sure that when you open the socket your thread sleeps until there is a connection to it anyway, so this is fine.When it does get a connection, we read the first 1024 bites that got sent to it, and store them in msgIn, This is going to tell us what sort of information is being looked for while ($conn = stream_socket_accept($socket)) { $msgIn = fread($conn, 1024); echo($msgIn);

The flush call is pretty important for this, it makes sure that the version of the page that the users are looking atis up to date (and not being stashed away in the buffer)

flush();For command and control we just send back a serialized version of the backtrace, and our spied variables. Much more onvariable spying in a later post (Code in RED is from a different chunk of code, its basically the other end of the conversation)
if ($msgIn == ‘cnc’){ fwrite($conn, serialize(array(“trace”=>$idbg_backtrace,”vars” => $idbg_var_spy)));
$responce = unserialize(idbg_socket_client(“cnc”));<font color="#990000"> foreach($responce["trace"] as $key =&gt; $val){ echo("&lt;a href='".$callBackName."file&amp;idbg_open_line=".$val['line']. "&amp;idbg_open=".$val['file']."#anchor' target='infoframe'&gt;".strrchr($val['file'],"/")."&lt;/a&gt;"); echo(" Line:". $val['line'] . " Function:" . $responce["trace"][$key+1]["function"]. " &lt;a href='#' onClick=\"document.getElementById('v_$key').style.display='block'\"&gt;+&lt;/a&gt; &lt;div id='v_$key' style='display:none'&gt;&lt;pre&gt;"); print_r($responce["vars"][$responce["trace"][$key+1]["function"]]); echo("&lt;/pre&gt;&lt;/div&gt;&lt;hr/&gt;"); </font> }

If the message is step, then we return, so the program keeps running, but we don't turn off the "STOP" flags,we also update the "last line" so that we don't end up hitting the same line over and over. } else if ($msgIn == 'step'){ fclose($conn); fclose($socket); $idbg_last_line = $idbg_backtrace[0]['line']; return(TRUE);If the message is cont, then we turn off the "STOP" flags, and then we go on further } else if ($msgIn == 'cont'){ // fwrite($conn, "ACK"); fclose($conn); fclose($socket); $idbg_last_line = 0; $idbg_stop_flag = FALSE; return(TRUE);If we didn't get a command that we know about, send back a generic message, just showing that we heard them.Regardless after this we are going to close down the connection, and then the socket. We also susspended error messaging while we were in the debug code, so we will re-enable it before exiting. } else { fwrite($conn, " This is a SERVER Responce \n"); } fclose($conn); } fclose($socket); } }}//else just keep goingerror_reporting($old_error_level);

Are you proud of your code?

I know that I am consistently ashamed of my code. it is quite rare that I turn out any code which I don’t feel dissatisfied with. (I don’t think this is a reflection on my quality as a coder, I think that most of the code that I encounter is complete crap)

Other people are constantly happy with the code that produce. I wonder what the key difference in there personal outlook is, and if it ultimately makes them happier or sadder, as well as if it makes them better or worse coders and or more or less diligent. (speaking of being ashamed of things, that sentence was horrible)

It seems obvious that those who are always happy with there code would be less likely to revise it, but I’m not sure that this is true. I know that when I do have code that I feel happy about having written, I’m pretty enthused to keep working on it. To make it cleaner and better. On the other hand with most of my code I feel more like “when can I be done with this and work on something that doesn’t suck” I start to get sloppy and try to rush to the finish line, which I’m sure instills bad habits.

So I have decided that I am going to make a real effort to start trying to write code that I’m happy to come back and work on going forward from here. Of course I feel like I make myself that promise every other month.

Strange Projects on the Horizon

On Friday I was approached to work on one of the oddest and probably most ill-conceived projects I have ever encountered, and I might just take it anyway. Basically a company has a very good, very modular framework built for them in C# using .Net by a bunch of Russians who they hired remotely. I can tell by looking at the output that the code is quite modular, if it might be a little unclean. It looks like it would actually be some pretty good code to support.

They have been selling boiler plate instillations of this framework, with just some simple skinning done, and selling them hand over fist, apparently they are making a mint.

So anyway, For some reason they want to hire one of my companies, (and hence me) to do the occasional “special project” for clients who need something that is just slightly more custom than what they have. There are a few basic problems with this.
1) I don’t know C#
2) I don’t know Russian
3) I don’t think I even get access to the code base at all!

It seems that each part of the site that the framework builds can be loaded as a “section” which can easily be included on sites other than the primary site. (that is to say you can throw a little javascript or something into your own website, and have it display, say the friends list from the primary site, and it was built to have this work). For some reason they think it’s a good idea to have me build a second site, in php, that covers their additional functionality, and then have it load each of the bits of the primary site and display them. This seems bizzaro to me, but hey, I’m willing to do it because I bet I can learn something cool and they would still be paying me.

What I’m really hoping is that this is NOT actually what they expect me to do, and that there is a SOAP interface to what the Russians built.