December 30th, 2009

NetBeans 6.8 and Macros

Well, I have been playing with the new release of NetBeans and I must say, I Like It!
It has a lot of useful features that I am really enjoying and find very useful fro productive development.
2 main items being the Macro Recording and the Snippet Palette.

The macros I had a bit of difficulty finding documentation on keywords, which seems to be a common issue.
So here is what I have found out, all shortcut keywords are fair game. List_Of_Shortcuts , at least anything like this adjust-caret-top is for sure.

The keyword Action is usable, eg “caret-forward”.
So say you wanted to end a string with a shortcut to place a semi colon ; at the end of the line.
Here is the macro I use
caret-forward ";" and I set it to a shortcut of Ctrl + ;

So when you have say

echo 'This{Ctrl + ;}'

right after the s in This you hit Ctrl + ; and it will jump over the last quote mark and add a semicolon

Let’s do something a little more sophisticated like a comment block for a $variable.
Here’s your code

$my_var = '';

Now you want a decent comment block for that var, here is the Macro

"/**" insert-break "@var " word-match-next insert-break "@return " word-match-next insert-break

All you need to do is use your Set Shortcut for that Macro on the line before the variable and it will make a comment block that looks like this.

/**
 * @var $my_var
 * @return $my_var
 * 
 */
$my_var = '';

So with this Macro feature you can create all sorts of speedy shortcuts.

As for the Snippet Palette, well just highlight the code and drag & drop it in the category you want and name it. That simple.

December 11th, 2009

Benchmark Your Themes

I have been getting deeper into development with Word Press, mostly styling but none the less working in Word Press because the fact of the mater is that there is a market for it. The point of this post is this, building a dynamic site can get quite heave very quickly, especially in WP. If you add a bunch of plug-ins which are loaded dynamically then add a custom theme that you maybe even paid a premium price for, your database queries can go through the roof.

For instance, WP has like 9 queries on an empty page with no plug-ins, that’s a lot already. Now add one of the themes out there with a couple rows of featured posts blocks. One thing that I noticed looking through some of these fancy themes is that they are running a ton of queries to get these featured posts.

Add 3 rows of 3 and a couple plug-ins and you are well over 50 queries.
Now have 100 visitors at a given moment on that page, that is a minimum of 5000 database calls in that moment.
You had better have an excellent host!

I’ve also seen this with dynamic Ajax scroll-er plug-ins.
3 posts to grab content from in one category and its 7-9 queries. Something is not right there, guys.
You should be able to grab that content in 2 queries, 1 if the database structure was descent (but that’s a whole different game).

For you out there with front pages like this, do yourself a favor, especially if you have had issues in the past.
See how many queries are loading and how long it takes, it’s simple to do.

In your theme’s footer.php template before the closing

</body>

Add

Select All
1
<?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds.

Now your pages will show you how many queries there are for each page.
You can determine what to do from there.

As a further note on the subject, you can have a featured content page and have a bunch of blocks and not have it take a bunch of database queries.
Stay Tuned and I might tell how :)

December 11th, 2009

jQuery Ajax loading image

Well I noticed lack of instruction on using a loading image when you load something via Ajax.
So I am going to show you how, using jQuery.
First thing is you will need a loading image similar to this

If you do not have one there is an excellent site to generate all popular Ajax loading animate gifs in any color HERE.
The way it is loaded is like this,

Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
$(document).ready(function(){
    //Click function for the item you are loading
    $("#id_to_click").click(function(){
         //Stuff to do when clicked
         //Add your animated loading image before you load the content
         $("#content_id_to_load").empty().html('<img src="image_path/loading.gif" alt="" />');
 
         $("#content_id_to_load").load("new_page.html", function () {
		//Some more stuff to happen here when your Ajax item is loaded
 
         });
    });
});

I’m sure there are 101 ways to do this, so here is 102 :) .

December 5th, 2009

Tis the Season

I figured I would install a script for snow to get in the mood. But then I decided it would be worth my time to check for a WP plug-in first.
Well, Here you are WP Let it snow.

December 1st, 2009

XHTML valid target

This version uses jQuery which I use on a lot of projects.
The simplest use without downloading anything is this.
Before your closing head tag,

</head>

Add

Select All
1
2
3
4
5
6
7
8
9
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
$(document).ready(function(){
	//new window method for external links
	$('a.external').click(function(){
		window.open(this.href);
 
		return false;
	});
});

To make a link open in a new tab, just add class=”external” to the link.
Example

Select All
1
<a class="external" href="http://your_url.com/">Link</a>

New links with that class will now open in a new browser window or tab and be XHTML strict compliant.
Example link

Page 9 of 9« First...56789