April 2012 Entries

jQuery - Does a DOM element exist or not

Goal:
How to find out if a DOM element exists using jQuery:

Solution:
There are many ways to skim a cat, but I find the easiest way is to do:

$("#theItem")[0]

So you can do an IF-THEN-ELSE:

if(!$("#theItem"))[0]{
    //it is undefined and does not exist
}

Why or why not to pad an index with fill fator on sql server

Goal:Using sql server's fill factor to pad an index with free space seems like a great idea if you have high fragmentation on an index or you think you have a very high write to read ratio, or simply a write intensive table.The problem:So you go an add lets say a 70% fill factor and suddenly your reads slow down. Why is that?! I just improved performance by adding free space to the leaf pages of the index.You assumed that since the index has to be updated frequently due to inserts or updates that ......

Prevent copying images from web page - read-only images

Problem:You have images on your web site that you want to protect from being copied and used. In essence you want to make them "read-only" so to speak.Solution:Add the HTML code by wrapping your image with it.<span oncontextmenu="return false" ondragstart="return false"><img id="your image"/></span>This is not 100% fool proof, am not going to explain why as that would make this post useless :-) ......

SQL Server - index usage/utilization stats

Goal:Find out what indexes are being used, if at all, and if the stats on seeks, scans and lookups on the indexes:index-seek (preferred)index-scan (worst)index-lookupSolution... this scrip against your databaseSELECTo.name AS object_name,i.name AS NameOfIndex,i.type_desc as IsItClustered,u.user_seeks as IndexSeeks, u.user_scans as IndexScans,u.user_lookups as IndexLookups, u.user_updates as HowManyUpdates,o.typeFROMsy... iJOINsys.objects o ON i.object_id = o.object_idLEFT JOINsys.dm_db_index_usage_s... ......