Sunday, November 23, 2008

Google Search Greasemonkey Script

This is a nice script that can convert your Google search page from this:

image

to this:

image

Features (From the developers page):

  • Allows you to select 1,2,3 and 4 columns of Google results. You can now use more of your screen space with less scrolling (based on the original concept of Two Column Google by Jeffrey Sharkey)
  • A background or border hue to your search results. Now configurable from the user dialogue with a simple color picker! glooble
  • Remove the Google "Sponsored Links". Like you need Google telling you where to buy stuff!
  • Result numbering. When looking at loads of results you can use this feature to quickly identify where you are and what relevance they may have (especially useful when we come to Auto-loading more results!)
  • Auto-load more results. Seen else where on userscripts.org. This version of the scripts code has been streamlined to allow almost seamless result fetching when you approach the bottom of the screen. Never have to load the next page by hand! (based on the Definitive Google Auto Pager by Paweł Kubisz)
  • Remove the web search dialogues from your Google pages. If you use the Google Toolbar for Firefox why waste your valuable screen space when you can hide the extraneous elements away.
  • Make external Google links open in a new window/tab. Now this is configurable in your Google preferences but not with the distinction between when your searching and when your using iGoogle. Well now you can!
  • Disable Google tracking your search results. Every time you click a link in your search results, the click gets reported back to Google for their statisticians to ponder over. If you are signed in to a Google account this click will be recorded in your search history. This function allows you to disable this reporting to Google completely or add an extra "Trackless" link to each of your search results
  • Self updating when a new version of the script is available. Using the same technology seen in my other scripts you'll always be notified of updates. This feature checks userscripts.org every 24hours for later versions of the script. Opening the preferences will force a check there and then (although there is possible caching by FF).
  • Thumbnails for each of your results. Incorporating resources from GooglePreview.com now allows you to see a thumbnail of the home page of each of your search results. If you use this feature think about helping out with the server costs and donate!
  • favicons for each of your results. Show the sites favicon if you so choose... and, of course, they actually have one !)
  • And all of this can be configured through one simple screen. Simply click on the GoogleMonkeyR link at the top right of the page and pick your preferences.
    The original idea/concept for this wonderful preferences screen came from the Rllmuk User Ignore List script written by Jonathan Buchanan (his web site). Reading his code made me stop and look at how i wrote my own code... and then think about going back to school. Hats off!

 

Install it from here

* For some reason the script registers with a specific domain name, so I had to change it manually to:

image

Saturday, November 22, 2008

CSS Box Model (W3C and IE6)

image

jQuery – working with ASP.NET controls

 

DropDownList SelectedValue:

GET:   $('#<%=DropDownList1.ClientID%>').val();
SET: $('#<%=DropDownList1.ClientID%>')
.val("value_to_set");

RadioButtonList SelectedValue:

$("input[name='<%=RadioButtonList1
.UniqueID%>']:checked").val();

Button Enable/Disable

$('#<%=Button1.ClientID%>').attr("disabled", true/false);

Label Text

GET:  $('#<%=Label1.ClientID%>').text();
SET: $('#<%=Label1.ClientID%>').text("value_to_set");

TextBox Text

GET:  $('#<%=TextBox1.ClientID%>').val();
SET: $('#<%=TextBox1.ClientID%>').val("value_to_set")

Check Visibility

if ($('#<%=Button1.ClientID%>').is(':visible'));

Friday, November 21, 2008

jQuery Data method

I got this amazing tip from an article named “5 tips for better jQuery code”.

This is a great way to associate any amount of data with any element on the page, here is a small example:

<html>
<head>
    <title>jQuery Data() method</title>
 
    <script src="scripts/jquery/jquery-1.2.6.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    
        $(document).ready(function() {
            //create meaningless list
            for(var i=0;i < 10;i++)
            {
                $("#list").append("<li>" + i + "</li>");
            }
            
            var prevSum = 0;
            
            //will show the pwr of index and sum with all previous items
            $("#list li").each(function(indx, obj)
            {
                prevSum = prevSum + indx;
                //attach data to each list item
                $(this).data("Data", {pwr: indx*indx, sum: prevSum });
                //Show it
                $(this).html($(this).html() + ": pwr=" + $(this).data("Data").pwr + ",sum=" + $(this).data("Data").sum);
                
                    
            });
 
            
        });
 
    </script>
</head>
<body>
     
    <ul id="list">
            <!--the items will be added here -->
    </ul>
 
</body>
</html>

 

Nice!

The interesting part is that the data is not shown in the source code…

jQuery Array Iteration – $.each

jQuery $.each can be used in order to iterate over an array:

$(document).ready(function() {
    var arr = [ "a", "b", "c", "d", "e" ];
    
    $.each(arr,function(index, item)
    {
        $('#list').append($( "<li>" + item + " at " + index +"</li>" ));
    });
    
});

You should have a <ul> with id=list for this code to work:

<ul id="list">
    <!--the items will be added here -->
</ul>

The result is:

image

Here is the entire code:

<html>
<head>
    <title>jQuery Array Iteration</title>
 
    <script src="scripts/jquery/jquery-1.2.6.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    
        $(document).ready(function() {
            var arr = [ "a", "b", "c", "d", "e" ];
            
            $.each(arr,function(index, item)
            {
                $('#list').append($( "<li>" + item + " at " + index +"</li>" ));
            });
            
        });
 
    </script>
</head>
<body>
     
    <ul id="list">
            <!--the items will be added here -->
    </ul>
 
</body>
</html>

Important to note that this is not the same as $(‘DOMElement’).each().

 

Source

Friday, November 14, 2008

Doing something while UpdatePanel is updated

<script type="text/javascript">
// Get the instance of PageRequestManager.
 var pageReq = Sys.WebForms.PageRequestManager
                                .getInstance();
 // Add initializeRequest and endRequest
 pageReq.add_initializeRequest(pageReq_InitializeRequest);
 pageReq.add_endRequest(pageReq_EndRequest);
 // Called when async postback begins
 function pageReq_InitializeRequest(sender, args) {
   
 }
 // Called when async postback ends
 function pageReq_EndRequest(sender, args) {
	
 }
</script>

Tuesday, November 4, 2008

SQL Server – inserting multiple rows with one statement

This is a nice trick:

INSERT INTO tblTable (rowName1, rowName2)
SELECT 'val1', 'val2'
UNION ALL
SELECT 'val3', 'val4'
UNION ALL
SELECT 'val5', 'val6'

This code will insert 3 rows into the table.