Thursday, June 28, 2007

Continuous Marquee or Scroller


// Deluxe Scroller
// Author: Howard Covitz
// Date: May 4, 2007
// All rights reserved, yada yada yada
function startScroller(dn_newsID,scrollWindowHeight,scrollWindowWidth,scrollListHeight,scrollInterval,debug)
{

// Set defaults
if (!dn_newsID){
dn_newsID = 'articleScroller' ;
}
if (!scrollWindowHeight){
scrollWindowHeight = 200 ;
}
if (!scrollWindowWidth){
scrollWindowWidth = 350;
}
if (!scrollListHeight){
scrollListHeight = 900;
}
if (!scrollInterval){
scrollInterval = 30;
}
if (!debug){
debug= false;
}


var n=document.getElementById(dn_newsID);
if(!n){return;}
n.style.height= scrollWindowHeight + 'px'; //sets window height

var c=n.getElementsByTagName('div')[0]; // carOne
var d=n.getElementsByTagName('div')[1]; // carTwo



c.innerHTML = d.innerHTML;
c.style.width= (scrollWindowWidth - 30) + 'px'; //sets data list width, should be less than window width.
d.style.width= (scrollWindowWidth - 30) + 'px'; //sets data list width, should be less than window width.
// var scrollListHeight = c.offsetHeight;
if(debug){
alert(c.offsetHeight);
}
if (c.offsetHeight == 0){ //will hopefully only happen in IE if nested down far
var strContent = c.innerHTML;
//determine character count: strip out HTML tags first
strContent = strContent.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">"; });
strContent = strContent.replace(/<\/?[^>]+(>|$)/g, "");
var contentLen = strContent.length;
//following optimized for stylesheet listed later
var charsPerLine = 60;
var lineHeight = 15;
var numItems = 8;
var sepLineHeight = 20;
var buffer = 20;
scrollListHeight = Math.round(((contentLen/charsPerLine) * lineHeight) + (numItems * sepLineHeight) + buffer);

}
else{
scrollListHeight = c.offsetHeight + 15; //pad for firefox????
}

c.scrollInterval = scrollInterval;
c.scrollListHeight= scrollListHeight;
c.scrollWindowHeight = scrollWindowHeight;
if(scrollWindowHeight > scrollListHeight){
//c.dn_startpos= scrollListHeight; // Should be presumed height of data list or window height, whichever is smaller
}
c.dn_scrollpos = c.scrollWindowHeight;

d.scrollInterval = scrollInterval;
d.dn_endpos= scrollListHeight * -2; //double check this logic...maybe this is no longer used below
d.dn_startpos = scrollWindowHeight;//since it is relative positioned, it will line up right after carOne
d.dn_scrollpos = d.dn_startpos;

c.myinterval = setInterval('scrollDOMnews("' + dn_newsID + '")',c.scrollInterval);

c.onmouseover=function(){clearInterval(c.myinterval);}
c.onmouseout=function(){c.myinterval =setInterval('scrollDOMnews("' + dn_newsID + '")',c.scrollInterval);}
d.onmouseover=function(){clearInterval(c.myinterval);}
d.onmouseout=function(){c.myinterval =setInterval('scrollDOMnews("' + dn_newsID + '")',c.scrollInterval);}

}

function scrollDOMnews(dn_newsID)
{
var c=document.getElementById(dn_newsID).getElementsByTagName('div')[0];
c.style.top=c.dn_scrollpos+'px';
if(c.dn_scrollpos== Math.round((c.scrollListHeight * -1))){ //ie -700
c.dn_scrollpos=c.scrollListHeight; //directly below car two
}
c.dn_scrollpos--;
scrollDOMnews2(dn_newsID);
}
function scrollDOMnews2(dn_newsID)
{
var c=document.getElementById(dn_newsID).getElementsByTagName('div')[1];
c.style.top=c.dn_scrollpos+'px';
if(c.dn_scrollpos==Math.round(c.dn_endpos)){
c.dn_scrollpos= 0;
}
c.dn_scrollpos--;
}


/* stop scroller when window is closed */
window.onunload=function()
{
// this will have to be a nice to have:
//clearInterval(dn_interval);
}


/*
EXPECTED FORMAT OF HTML

<div class="marquee" id="articleScroller" style="overflow:hidden;postion:relative;">
<div style="position:relative;"></div>
<div style="position:relative;">
{CONTENT GOES HERE -- just don't use DIV tags}
</div>
</div>
USAGE:
startScroller("articleScroller",200,350,30);
startScroller("articleScroller2",200,350,30);

In IE, optimized for following styles:
.marquee{
padding:0px;
margin:0px;
}
.marquee ul{
margin:0px;
padding:0px;
}
.marquee li{
padding-bottom:3px;
margin:0px;
}
.marquee li a:link, .marquee li a:visited {
font: 11px Arial, Verdana, sans-serif;
text-decoration:underline;
font-weight:bold;
}
.marquee li a:hover, .marquee li a:active {
font: 11px Arial, Verdana, sans-serif;
text-decoration: none;
font-weight:bold;
}
.marquee p{
padding:0px;
margin:0px;
}

*/

Stripping out HTML tags with JavaScript

strContent = strContent.replace(/&(ltgt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">"; });
strContent = strContent.replace(/<\/?[^>]+(>$)/g, "");

Monday, June 25, 2007

A quick aside on web culture

I recently started checking out the notorious MySpace and Facebook some more. About a year ago I checked them out just to make sure I was up on the latest Big Thing in my industry (since I am a web programmer, after all). I think at that time you had to have a valid University e-mail, so luckily I had my Brown alumni one. But then recently I read this Facebook for Fiftysomethings at one of my daily reads (Slate.com, I regularly check out the Human Nature column, not to mention the political stuff), which motivated me to the extent that, if Emily Yoffe could do it, so could I (though in retrospect she does seem so naive). Especially in the past month, I've been trying to be more active about "participating", and as will be no surprise to those familiar with both sites, Facebook was more to my taste. Well, on the heels of that realization, I read this today:MySpace, Facebook mirror class divisions in US society.
This just confirms my own observations.

Also, isn't "Social Networking" redundant?

Monday, June 18, 2007

Classic ASP Error Handling

This summary is not available. Please click here to view the post.

Friday, June 15, 2007

T-SQL Searching through the schema

For SQL Server 2005:


Some examples:
select * from sys.objects
select * from sys.sql_modules <-- Stored Procedures and Views
select * from sys.columns
select * from sys.triggers


Searching the text of all stored procedures:
select o.name from sys.sql_modules m
inner join sys.objects o
on m.object_id = o.object_id
where m.definition like '%string you are looking for%'

Searching for tables that contain the column (field) you want:
select a.name
from sys.objects a
inner join sys.columns b
on a.object_id = b.object_id
where b.name='column name you are looking for'

Another way:

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_DEFINITION LIKE '%foobar%'
    AND ROUTINE_TYPE='PROCEDURE'


For SQL Server 2000:


Searching the text of all stored procedures:
select object_name(id)
from syscomments
where objectproperty(id,'IsProcedure') = 1
and [text] like '%string you are looking for%'



To search across multiple DATABASES for a particular TABLE:


sp_MSforeachdb 'SELECT "?" AS DB, * FROM [?].sys.tables WHERE name like ''%tablenameyouarelookingfor%'''


or if that undocumented proc is not avail, try this:

DECLARE @SQL NVARCHAR(max)
SET @SQL = stuff((
            SELECT '
UNION
SELECT ' + quotename(NAME'''') + ' as Db_Name, Name collate SQL_Latin1_General_CP1_CI_AS as Table_Name
FROM ' + quotename(NAME) + '.sys.tables WHERE NAME LIKE ''%'' + @TableName + ''%'''
            FROM sys.databases
            ORDER BY NAME
            FOR XML PATH('')
                ,type
            ).value('.''nvarchar(max)'), 1, 8, '')
--PRINT @SQL;
EXECUTE sp_executeSQL @SQL
    ,N'@TableName varchar(30)'
    ,@TableName = 'items'



To find out the dates of last modified and created for Stored Procs
SELECT name, create_date, modify_date 
FROM sys.objects
WHERE type = 'P'
ORDER BY modify_date DESC

Wednesday, June 13, 2007

Stylesheet based on existence of Javascript

To help deal with those with Javascript disabled on their browsers:

<noscript>
<LINK REL="stylesheet" href="nojavascript.css">
</noscript>
<script language="JavaScript">
<!--
if (document.images){
document.write("<link rel='stylesheet' href='javascript.css'>");
}
//-->
</script>

This is helpful when using CSS properties like "display:none" and
"display:block" with JavaScript to hide Divs.

Tuesday, June 12, 2007

Reqular Expressions and SQL

FIND: ^\(.+\)$
REPLACE: \0 = formToSql("\0")