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;
}

*/

Labels: , , , ,

Stripping out HTML tags with JavaScript

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

Labels:

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?

Labels: , ,

Monday, June 18, 2007

Classic ASP Error Handling

On Error Resume Next
'this will cause the page to continue processing when it hits an error
 
'after all scripting
If Err.number <> 0 then
    Dim msg msg = "Error Number " & Err.number & " occurred in millionDollarRequest.asp. Description: " & Err.Description & " SOURCE: " & Err.Source
    msg = msg & " IPADDRESS: " & Request.ServerVariables("REMOTE_HOST")
    sendEmailError(msg)
    Err.Clear
end if
 
'typical error message mailer
function sendEmailError(msg)
 Dim Mailer
 Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
 Mailer.RemoteHost  = "mail.XXXXXX.com"
 Mailer.Timeout = 30
 Mailer.FromName = "ERROR REPORT"
 Mailer.FromAddress = "webmaster@XXXXXXXXX.com"
 Mailer.ReplyTo = "webmaster@XXXXXXX.com"
 Mailer.AddRecipient "", "YYYYYYY@XXXXXXXXX.com"
 Mailer.Subject = "ERROR Alert"
 Mailer.BodyText = msg
  
 sendEmail = Mailer.SendMail
end function
 
 
 

Labels: ,

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'

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%'

Labels: , ,

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

Labels: ,

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)

Labels:

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.

Labels:

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.

Labels: