Skip to content

Instantly share code, notes, and snippets.

View sholsinger's full-sized avatar

Steve Holsinger sholsinger

View GitHub Profile
@sholsinger
sholsinger / SQL Parser Error (Text AND Category)
Created October 18, 2010 15:47
Parser tells me: Incorrect syntax near the keyword 'ORDER' -- which one?
DECLARE @str VARCHAR(255);
SELECT @str = LOWER(?);
SELECT * (
SELECT TOP 8 * FROM [oca_search_model]
WHERE [osm_isactive] = 1
AND LOWER([osm_category]) = LOWER(?)
AND (
LOWER([osm_keywords]) LIKE '%'+@str+'%'
OR LOWER([osm_description]) LIKE '%'+@str+'%'
OR LOWER([osm_name]) LIKE @str+'%'
@sholsinger
sholsinger / Array.indexOf.js
Created February 9, 2011 22:59
Detect existence of Mozilla's indexOf Array extension and implement if not available.
if(Array.prototype.indexOf === undefined)
{
Array.prototype.indexOf = function(val)
{
for (var i = 0; i < this.length; i++)
{
if(this[i] == val)
return i;
}
return -1;
@sholsinger
sholsinger / JSON.stringify.js
Created February 15, 2011 22:10
Apparently the standard is stringify() // Who decided that?!
if(JSON.hasOwnProperty('encode') && !JSON.hasOwnProperty('stringify')){
JSON.stringify = JSON.encode;
}
@sholsinger
sholsinger / proj_request_report.js
Created February 17, 2011 16:11
A quick and dirty report of the unique input names on my page.
var report = {
run: function ()
{
return $("form :input[name!='']").filter(this.isUniqueField);
},
isUniqueField: function (index)
{
if(report.elementNameCache.indexOf(this.name) < 0) {
@sholsinger
sholsinger / GetTableDefinitionADO.asp
Created March 9, 2011 16:54
Some functions to aid in "describing" a SQL table that you don't have direct SQL access to via COM ADO library.
<%
Function GetTableDefinition( table_name, conn, id, idfield )
dim rs, fld, rec
dim where: where = ""
If IsNumeric(id) And id > 0 and idfield <> "" Then
where = " WHERE " & idfield & " = " & id
End If
@sholsinger
sholsinger / gist:901874
Created April 4, 2011 16:00
VBScript Tools for measuring the length of an array and appending values to a Dynamic array
' appends the second argument to the first if the first is an array.
' MUST be a dynamic array! Returns new array.
' Usage:
' Dim myArray()
' myArray = ArrayAppend(myArray, "foo")
Function ArrayAppend( a, o )
On Error Resume Next
Err.Clear()
dim tn, i
i = 0
@sholsinger
sholsinger / BusinessDayAdd.vbs
Created April 15, 2011 15:20
Visual Basic Script for doing "working day" arithmetic. Use this function to add or subtract business days from a VBScript date object.
Function BusinessDayAdd(delta, dt)
dim weeks, days, day
weeks = Fix(delta/5)
days = delta Mod 5
day = DatePart("w",dt)
If (day = 7) And days > -1 Then
If days = 0 Then
days = days - 2
@sholsinger
sholsinger / addBusinessDays.js
Created April 18, 2011 21:58
A JavaScript module to extend the Date prototype to provide an easy method for adding to or subtracting from a Date instance in business days.
if(Number.prototype.mod === undefined)
{
Number.prototype.mod = function(n) {
return ((this%n)+n)%n;
}
}
if(Date.prototype.addBusinessDays === undefined)
{
Date.prototype.addBusinessDays = function(dd) {
var weeks = (dd >= 0) ? Math.floor(dd/5): Math.ceil(dd/5);
@sholsinger
sholsinger / inArray.vbs
Created April 26, 2011 20:52
VBScript tool for checking if a value is in an array.
' returns the index of obj in array. obj can be anything. Returns -1 if not found.
Function inArray(arr, obj)
On Error Resume Next
Dim x: x = -1
If isArray(arr) Then
For i = 0 To UBound(arr)
If arr(i) = obj Then
x = i
Exit For
@sholsinger
sholsinger / toKey.js
Created May 2, 2011 16:18
JavaScript method to convert a string into a reasonable "key" string.
if(String.prototype.toKey === undefined)
{
String.prototype.toKey = function(){
var s = this.toLowerCase();
s = s.replace(/^[0-9_-]+|[^a-z0-9_\s-]|(\s.\s){1,}|[\s]{2,}|[_\s-]+$/ig, '');
s = s.replace(/[\-\s_]+/ig,"_");
return s;
}
}