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")

Getting index value of new record created

In your T-SQL stored procedure, after you insert the new record into a table that has an auto-incrementing index, use the following:

SELECT NEWID = SCOPE_IDENTITY()
OR (if using pre 2000 sql server)
select returnval = @@identity

You can retrieve the value in the following way:
set rs = con.Execute(strSql)
yournewID = rs(0)


*UPDATE 2017*

up vote1026down voteaccepted
  • @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes. You need to be careful here, since it's across scopes. You could get a value from a trigger, instead of your current statement.
  • SCOPE_IDENTITY() returns the last identity value generated for any table in the current session and the current scope. Generally what you want to use.
  • IDENT_CURRENT('tableName') returns the last identity value generated for a specific table in any session and any scope. This lets you specify which table you want the value from, in case the two above aren't quite what you need (very rare). Also, as @Guy Starbuck mentioned, "You could use this if you want to get the current IDENTITY value for a table that you have not inserted a record into."
  • The OUTPUT clause of the INSERT statement will let you access every row that was inserted via that statement. Since it's scoped to the specific statement, it's more straightforward than the other functions above. However, it's a little more verbose (you'll need to insert into a table variable/temp table and then query that) and it gives results even in an error scenario where the statement is rolled back. That said, if your query uses a parallel execution plan, this is the only guaranteed method for getting the identity (short of turning off parallelism). However, it is executed before triggers and cannot be used to return trigger-generated values.

Friday, June 8, 2007

Recent Projects

My manager is really impressed with a documentation tool I created in C#. The mechanics of it were no big deal (aside from getting ASP.NET to behave). But I did have to get real crafty in getting at and creating the data. Used a whole grab bag of tricks to mine it. Sometimes regular expressions, sometimes Textpad features, sometimes just Excel.





Sketchpad for Blogs

I've been wanting to transfer my vast notebook of programming notes, gathered from about 7 years of work, to a blog. Problem is, I intersperse my text with sketches or doodles that server as important memory tags. I know there have been online sketching apps around for years (usually done in Flash), where you can even save the stuff online. So it would seem an easy leap to make that part of a blog. But I've been looking around for about a week and nobody seems to have done this.


This exercise also made me realize how little we've come in truly integrating sketching and word processing, regardless of online or not. It should be a lot simpler now for users of MS Word to add a sketch, but it is poorly integrated.

http://www.zefrank.com/scribbler/
http://www.sketchswap.com/
http://www.cumulatelabs.com/cumulatedraw/
http://www.benettonplay.com/toys/flipbook/flipbook_maker.php

Perhaps due to some synchronicity, though, I did just find this new post, which is tantalizingly close to what I'm talking about.
Julie Lerman Blog - Embedding Silverlight Annotation in my dasblog post

(which references http://silverlight.net/Samples/1.1/Scribbler/run/default.html)
Note that it dovetails with another fascination of mine: the demise of Flash.

Progressive Enhancement

I'm currently digesting an article on Progressive Enhancement as a an alternative approach to web design, as opposed to Graceful Degradation. It turns out I've been a natural P.E. adopter and just never knew it.