Friday, August 10, 2007

Notes from Peepcode tutorial on Prototype.js

Notes from Peepcode tutorial on Prototype.js
ver 1.5.1

$H()
$A()

for Hash Object and Array Objects

var smedly = {ape:'brown',frog:'green'}
smedly.ape


var smedly = $H({ape:'brown',frog:'green'})
smedly.keys()

$A isn't really needed...
var asmedly = ['ape','frog','toad']
asmedly.first()

Element.hide('smedly')

$('smedly').hide()

$('smedly').show()

$$('boldTextCSSclass').invoke('hide')

$$('a').invoke('hide')

Anonymous Functions:

$$('a').each(takesAFunction)

$$('a').each(function(element){element.hide()})

Other selector syntaxes (generally uses CSS):
$$('a,p') selects both a's and p's
$$('div p') selects all p's in a div
$$('img') selects all images
$$('img[alt=mephisto-badge]') selects all images with 'mephisto-badge' as alt parm
--------------------------------------------------------

Modules
This is pure JavaScript. Create modules using Hashes.

var myHash = {mykey:myvalue, mykey2:myvalue2}

Now just put function in for the key:value pairs:

var HandyFunctions = {hideLinks: function(){}, showLinks: function(){}}
var HandyFunctions = {
hideLinks: function(){
$$('a').invoke('hide');
},
showLinks: function(){
$$('a').invoke('show')
}
};

Note: when you call these functions, even though they are Hash keys, make sure to put parentheses at end:
HandyFunction.hideLinks()

Classes
Note: see Yahoo video for painfully in-depth exploration of JavaScript classes.
Prototype makes it simpler. Just use Class.create() !!
They are similar to the Module concept above, but with some added functionality:
initialize,
parameters that can be passed to functions,
and you can use "this" keyword.

var Butter = Class.create()
Butter.prototype = {mykey:myvalue}

Butter.prototype = {
initialize: function(brand) {
this.brand = brand;
this.melted = false;
},
melt: function(){
this.melted = true;
}
}

var parkay = new Butter('Parkay');

Extend

addMethods

See Quirksmode for list of cross-browser behaviors (onmousever, onclick, etc)

JavaScript Hash

var animalColors = {'ape':'black', 'pig':'pink', 'frog':'green'}
 
alert(animalColors['ape'])
 
alert(animalColors.ape)
 
 

Monday, August 6, 2007

Too Many Stored Procedures

Is there such a thing as Too Many Stored Procedures?
Jeff Atwood at Coding Horror makes some great points that reflect my own thoughts over at:
http://www.codinghorror.com/blog/archives/000117.html

I think SQL Server's Object Explorer needs to have a built-in mechanism for managing the thousands of stored procedures that occupy a database, instead of trusting that a sensible naming convention will be used.  In my experience, eventually any naming convention breaks down after time, as new developers and technologies arrive.

Linked to in Atwood's post is this by Frans Bouma, who seems to be the main promoter of cautionary use of Stored Procedures: http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx

Thursday, August 2, 2007

Quick ASP Log

Handy for debugging errors:
 
 
function writeLog(msg)
 
 Dim fso
 Dim logfile
 Dim logFileName
 Dim strLog 
 logFileName  = Server.MapPath("logfile.txt")
 Set fso = Server.CreateObject("Scripting.FileSystemObject")
 Set logfile = FSO.OpenTextFile(logFileName, 8, True)
 logfile.writeline now() & ":" & msg
 set fso = nothing
 set logfile = nothing
 
end function

Wednesday, August 1, 2007

Most Common Validators for ASP.NET


<asp:requiredfieldvalidator id="reqResendWaitDays" Runat="server" ErrorMessage="Required Field" ControlToValidate="txtResendWaitDays"
Display="Dynamic">
</asp:requiredfieldvalidator>

<asp:CompareValidator id="comResendWaitDays" Runat="server" ErrorMessage="Must be numeric" ControlToValidate="txtResendWaitDays"
type="Integer" operator="DataTypeCheck">
</asp:CompareValidator>