Archive for March, 2007

First off, Code Snippet 2.0 is not mine. I didn’t make it, I won’t take any credit for it. The original creator was the person who hosted a blog at http://blog.enargi.com/codesnippet/ (which no longer works and is apparently down for good; however, it is GPL.). I came across the plugin awhile ago and and I’ve decided that I couldn’t just let it be lost to the ages and I’ll let it live here as long as I’m able.

Straight from the readme.txt, Code Snippet 2.0 is is a WordPress plugin for displaying code with highlighting in blog posts. The plugin uses GeSHi syntax highlighter engine. I’ve seen others, but they’ve gone the way of the dodo and most of them didn’t have as many supported languages at Code Snippet 2.0. I also think that Code Snippet does a better job than the Code Auto-escape plugin.

Install

  • Download the plugin here.
  • Copy archive to wp-content/plugins directory
  • Extract the zip file
  • When extracted properly you should have following directory structure: /wp-content/plugins/codesnippet
  • Since I’ve not tore through the code, the plugin will probably not work if extracted/copied in diffrenet directory.
  • Enable the Plugin

Usage
The original author recommended always wrapping your code in a <pre> tag; however, I’ve found that you generally don’t need to. To use it, simply surround your code with as such and specify your language type:

[code lang="c"]
int main(int argc, char** argv) { return 0; }
[/code]

And you get this:

int main(int argc, char** argv) { return 0; }

Or you could do something like:

[code lang="php"]
<?php
echo “Hello World!”;
?>
[/code]
<?php
     echo "Hello World!";
?>

If you find a bug in it, drop a comment or an email to wyatt dot neal at gmail and I’ll try my best to fix it for you.

Also, if you have find that your language isn’t here and you write your own GeSHi hack to work with it, let me know and I’ll drop a link on this page so that people can find you. Heck, I’ll even put it in the archive so the world can share it if you want. Here’s the list of supported languages: Continue reading ‘Code Snippet 2.0’ »

CSS is pretty cool; however, I think I’m becoming addicted to using it. It appeals to me in that love hate relationship. I love that I can perfect the look of an element … but I hate that I can perfect the look of an element. I continually find myself trying to perfect way to much. For example, right now I’m getting addicted to styling the borders on buttons, inputs, and textarea elements. I really think the defaults are possibly the crappiest looking things in the world.

For the buttons, I’m really like the flat look. I’m not really sure why but I think it gives a nice simplistic look. Though I’m conflicted, because I really like the slightly raised look that changes to a inverted gradient to give it the depressed look when you click it; hence, my addiction issue. I can never really determine what I like. Now I’m sure that most user interface experts would say take the look that fits the rest of the application, but then you come to the issue of what do you decide when that’s one of the first components you’re designing. I think that even though I really like the flat look for buttons, I’m going to reserve that for more of menu types of things, not actually user input buttons.

Now, for the textarea and input stuff, I’m really liking the solid thin border. I think it really gives a good definition to the area especially considering the default is the indentation that only hits the top and left sides. While that’s good if you put the input/textarea on a different background, it’s terrible if the backgrounds match. After staring at it for about 2 hours, your eyes have a really hard time discerning where the element really is on the page … something really important when you are trying to layout the final design. So adding a little darker background that’s about 4-6 shades off from blending and that thing border I love, it really makes things look slick. Yeah, I’m addicted to that :-) .

Though, you probably don’t need to hear this from me since most anyone that would read this article would know more about what users consider appealing in a user interface. Though, I really think that the usability and designers are a little over zealous with designs needing to appeal to the lowest common brain cell. I admit that I appreciate a guided interface; however, I don’t need every interface I use to hold my hand and look like it was designed for 3rd graders. Would it really kill to have simple, clean interface that might appeal to the engineering mindset? I don’t think so, but then again, don’t trust me … I’m not a ‘certified’ usability guy :-) .

I have been scouring the Internet for two days for looking for a suitable PHP alternative to DWR(read the previous post for more information) and haven’t found a single one so I’ve hacked out my own.

I had been looking at xajax in the hopes that it would get me what I was looking for, but it didn’t. So the next one I found was SAJAX. This project appears to be less active than xajax; however, disappointment strikes again. SAJAX does not support JavaScript objects, only basic variables. While that’s all well and good, when I need to pass larger objects, that’s extremely fricken annoying!!!

But wait … a glimmer of hope on the horizon … Sanjer promises to combine SAJAX and JSON. Only one major problem, it’s not actively maintained and it’s based on the 0.10 version of SAJAX which had some serialization bugs.

So to end the frustration for me and anyone else on the Internet who would ever want to do something this stupid (it apparently has to be stupid since no one else is willing to pull this off), I present my solution to the problem … hacking SAJAX. Before I delve into what changed, I’m going to give you the files so you can just run with it in the event that you aren’t interested in that crap. This zip includes everything you need to pull this off: Crockford’s json.js from http://www.json.org/, hacked up version of Sajax.php from me, and a simple index.php file that gives a super simple example of how it works. Oh yeah, since this is all based on GPL/Open source code, my derivation falls under the same licensing and comes with absolutely no warranty. Now, on to the other stuff that most people don’t really care about.

Fortunately, the people who wrote the SAJAX framework did a really good job a keeping a very nice code separation. All that had to happen to tweak this was:

  • JSON Encode the arguments before they are passed to the proxied PHP code
  • Create a new argument array of decoded JSON objects
  • Pass in the new argument array
  • JSON Encode the function result

Now I know that I could put this encode and decode inside every PHP function; however, I’m lazy and I don’t want to do that, especially if it’s a framework and it should do it for me. Here’s a snip-it of changes I made to the file:

:119
//parse out the args array
$newArgArray = array();
$arraySize = sizeof($args);
for($i = 0; $i < $arraySize; $i++) {
        //decode the JSON object
        $tmpArg = json_decode($args[$i]);
        array_push($newArgArray, $tmpArg);
}

$result = call_user_func_array($func_name, $newArgArray);
//encode the result in to JSON
$retString = json_encode($result);
//echo "var res = " . trim(sajax_get_js_repr($result)) . "; res;";
echo "var res = " . $retString . "; res;"

:215
for (i = 0; i < args.length-1; i++) {
        //uri += "&rsargs[]=" + escape(args[i]);
        uri += "&rsargs[]=" + escape(args[i].toJSONString());
}

:227
for (i = 0; i < args.length-1; i++) {
        //post_data = post_data + "&rsargs[]=" + escape(args[i]);
        post_data = post_data + "&rsargs[]=" + escape(args[i].toJSONString());
}

Well, that’s it. Really fricken hard, eh? Yeah, didn’t think so. I’m sure that this version will work for most uses; however, if you do find a bug, feel free to leave a comment or send it to me at wyatt neal on my GMail account and I’ll do my best to help you out. Hopefully this will inspire someone else with more time to come up with a better PHP framework that is a lot closer to the coolness you get from DWR.

If you have one that does what DWR does, drop a comment and let me know. SAJAX, PAJAX, and XAJAX don’t count because I’ve looked at them and I know they don’t provide the same level of use. The only one that comes close is PAJAX but it fails because it does synchronous instead of asynchronous calls by default (what where you thinking people?!?).

So at HTG, we build web applications. Hosted web apps to be precise. For one of our big ones, we choose to go the route of DWR. If you don’t know what DWR is, it’s basically a way of getting a nice JavaScript interface to a back end Java server. That’s all well and good; however, only 2 of our 3 developers liked the idea of going with Java. The third has what can only be described as reverent animosity towards Java … especially after some classes we took in the Engineering college :-) .

Anyway, I think the best part of DWR is that you get this JavaScript, or files, that give you objects that have functions equivalent to your exposed Java interfaces on the server. The beauty of this is that you can just make calls to something like this in the JavaScript:

<script type=’text/javascript’
src=’/project/remoteSecurityManager.js’> </script>
<script>
if (remoteSecurityManager.loginUser(‘username’, ‘password’)) {

} else {

}
</script>

Now of course, that code is completely bogus and won’t work for crap (bonus points if you can see why it would never work); however, it’s really nice because it gives you a way to have some people hammer on the server-side and some people work on the UI side without needing to really jump bank and forth from server to client. Well, Java’s all well and good; however, if you remember from earlier, we have one person that “hates” Java. So putting on the pseudo PM hat, I started looking around for some other ways to get that same sort of functionality in PHP … low and behold, such a thing does exist. It’s called xajax and it seems like it gets me the same sort of thing that DWR does. I’ve not read a ton on it, but I’m going to delve into it a little more and let you know what I think.