December 2007


After a bit of work it is now possible to use sql to parse json using javascript!. I introduce to you version 0.1 of JsonSQL. Given a javascript object you can write a simple select statement to filter, order and limit the object:

jsonsql.query("select title,url from json.channel.items
where (category=='javascript' || category=='vista')
order by title,category asc limit 3",json);

Give it a shot. It would be nice to expand this a little more with a few aggregate functions (distinct, count, etc..).

Many may not know(I just recently learned) about using regular expressions within SQL statements. Instead of using substring functions and such, we can create a clean little regular expression(Oracle):

SELECT zip FROM zipcode WHERE REGEXP_LIKE(zip, '[^[:digit:]]’)

Keep in mind however that just like SQL syntax varies for each database(MySQL, Oracle, Postgres, etc.) so does the regular expression techniques. The following are a couple links to help you get started.

Unfortunately a little research shows SQLite does not natively support this. It sounds like dangerous waters to begin with, but if you know you won’t be switching database engines often the benefits can be rewarding!

For all of you ColdFusion programmers out there you know what I’m talking about,.. that cfdump. When in doubt this nice little function will dump out any variable in a readable layout. Well there is also such a tool for javascript thanks to Net Grow! Although it has been around for some time now, we tend to forget about it.

Javascript Dump

I’ve been playing with JSON a bit lately and it seems there’s not a lot of options for searching JSON such as the way xpath can search XML. Since there aren’t any slick libraries out there I have been thinking on possibilities of creating such. Would it be slick to have an sql-like syntax parse and search json? You could then do something like so:

select name,age from people where age > 20 order by name limit 5

After thinking it through its basically a nice regex to parse out the query, then just pass the arguments to a function to parse it. Being one who interacts with sql on a regular basis this seems quite appealing, especially if you have an html table to sort or there are a million other possibilites! I havn’t done this but I have played with the regular expression to do such. Also the same principle could apply to XML, but it would be rather pointless with xpath.

A couple things I would like to share. While I’m not having a change of heart I would like to say I’ve reevaluated my perspective towards Microsoft. Lately I’ve tried to reorganize my work flow to adapt to my “environment”. At my desk sites a Vista machine and an Ubuntu machine..

Since I’ve started doing all of my programming on Ubuntu lately I’ve been much more pleased with Vista. Before I had nothing but problems with various issues from dual monitors, ide issues, to blue screens. I believe most issues were due to intense usage which most user’s aren’t apt to do. The last couple months I’ve stuck with internet browsing, instant messaging, and itunes on Vista and couldn’t be happier as far as an everyday email checking computer. As far as heavy duty programming, database work, and never ending for loops its not quite up to par just yet.

Ubuntu Fiesty has been very pleasing as well too however, especially since most of my computing needs for programming are well suited for it, where as my leisure computing is well suited for Vista with iTunes and Office. The two together seem to balance each other out very nicely, Which brings up an interesting topic from a post I read a the other day that not following web standards may actually help…

IE has long been going their own direction while other web browsers are sticking to standards. Well I love standards as much as the next guy, especially while doing CSS and Javascript, but had it not been for someone breaking the ice much of the client side capabilities would not be available today. As bad as we all like to jump on a bandwagon you have to understand sometimes that someone being bold and different is how we have evolved through the web, as programmers, as designers, as companies, and as humans.

At the same time I can’t say I’m uninstalling Firefox from my computer, its still my browser of choice, but I would like to see more people come to an understanding that just because something is different doesn’t mean we have to hate it, we should respect it and keep our eye on it. It could be on to something! Believe it or not I do have a lot of respect for many Microsoft products, and some of them I would probably prefer over any other product(SQLServer anyone?) although due to the financial situation we are blessed to have the others among us.

I was waiting on the day when jQuery would have a plotting plugin. Wait no longer! Flot is now on the scene. With the easy jQuery syntax I’m sure it will win the hearts of plotting programmers everywhere:

$.plot($("#placeholder"), data, options);

Now I just need to find somewhere to use it!

Not sure if many people have discovered that you can actually submit forms with a blank action attribute. What this will do is submit to the same page(url variables and all). This is very useful if you’re a copy paste coder or need the flexibility of renaming files and not screwing up the action attribute. It appears to work great with Firefox, IE6-7, Safari, and Opera. W3 does state that the action attribute is required, but does not say the attribute can’t be blank(W3 on Forms). My html has also been passing validation testing so I take that as fair game! For those unclear here is what I mean:

<form action="" method="post">
....
<button type="submit" name="submitbtn"
value="1>Submit</button>
</form>

So see, sometimes slackness can actually help out!

Nearly every website these days have columns. Since we have grown out of the old table days and into this new era of CSS we tend to over think certain things like how to create two columns side by side which can vary in height, but still appear to be the same height. The solution is so simple its rediculous. We start out with a left column and a right column(could be three columns.. this will work just as easily, but I’ll keep it simple), two div’s floating side by side via float:right; or float:left;. Next we add a left border to the right column, which is the same width and color as the left:

border-left: solid 150px #aaaaaa;

This will shove your right column out of line, but no worries, step three we slide it right back into place. With a negative left margin on the right column we can literally slide the right column back up under the left column:

margin-left: -150px;

So basically we added two lines of code to the independent columns, now it never matters which one is taller, they fill in for each other. A simple Example.