9
Jun

webTRAM update

   Posted by: admin   in ASP, JavaScript, PHP, Software Development, webTRAM

webTRAM is well on it’s way to being complete and stable product. Since I first posted about it, I redesigned and rewrote it, ading features and flexibility and performance. The code and demo have ben updated. The full working demo is included in the code so it will be pretty easy to get started.

 I have a few things I’ll be fixing and adding to it before I leave it alone for a while but all constructive and civil comments are welcome.

 http://SuddenDevelopment.com/?page_id=7

31
May

Free, large scale GEO IP mapping.

   Posted by: admin   in MSSQL, MySQL, Software Development

There is a site that has an open source database of IP ranges to geographic info called hostip.info. They alow you to download the database in several different formats. I chose MySQL. However, I don’t care much for the way that they structured the database because it’s divided into 255 tables that each represent the first octet of an IP. So I moved them all into a single table.

Here is some PHP code to generate the SQL script for combining all of the tables and dropping the old ones. I will also included the resulting file.

<?php
for ($i = 0; $i <= 255; $i++)
{
  $query = "Insert into ip4_all(a,b,c,country,city,cron) Select ".$i.", b, c, country, city, cron From ip4_".$i.";";
  $HTMLOutput = $HTMLOutput . $query . "<br><br>";
}
for ($i = 0; $i <= 255; $i++)
{
  $query = "Drop Table ip4_".$i.";";
  $HTMLOutput = $HTMLOutput . $query . "<br><br>";
}
echo $HTMLOutput;
?>
 

There are also daily updates to the database which would need to be obtained using scripts and then converted into this new data structure.

Powered by ScribeFire.

29
May

webTRAM demo updated.

   Posted by: admin   in ASP, JavaScript, PHP, Software Development, webTRAM

demo link:  http://anthong.com/webTRAM/demo/

the demo has been upgraded significantly to inlude all of the latest features with some ways to demonstrate them.

Powered by ScribeFire.

17
May

Percent to RGB in Javascript

   Posted by: admin   in JavaScript, Software Development

This is a small function I wrote today to take a value from 0-100 and return a color code in rgb(000,000,000) format. I use it to populate CSS values to color code elements based on a percent value. It could be used in mapping, charting, and grid views. Th colors points in the gradient are:

  • 0 = blue
  • 25 = green
  • 50 = yellow
  • 75 = orange
  • 100 = red
function percent2Color(intPercent)

{

 var intRed=0;intGreen=0;intBlue=0if (intPercent > 0 &amp;&amp; intPercent < 26)

 {

     intRed = 0;

     intGreen = (intPercent * 10.2);

     intBlue = 255(intPercent * 10.2);

 }

 if (intPercent > 25 &amp;&amp; intPercent < 51)

 {

     intPercent -= 25;

     intRed = (intPercent * 10.2);

     intGreen = 255;

     intBlue = 0;

 }

 if (intPercent > 50 &amp;&amp; intPercent < 101)

 {

     intPercent -= 50;

     intRed = 255;

     intGreen = 255(intPercent * 5.1);

     intBlue = 0;

 }

 intColorSum = intRed + intGreen + intBlue;

 (intColorSum > 380)? strFontColor = ‘#000000′: strFontColor = ‘#FFFFFF’;

 //alert(‘rgb(‘+Math.round(intRed)+’,'+Math.round(intGreen)+’,'+Math.round(intBlue)+’)');

 return ‘rgb(‘+Math.round(intRed)+‘,’+Math.round(intGreen)+‘,’+Math.round(intBlue)+‘);’;

}

Microsoft has a tool that should be in every DBA’s toolbox. Even if you aren’t running MSSQL on a Windows server it’s very handy to run on your windows desktop to get info out of flat files very quickly.

This can be used as a great alternative to DTS because you can insert the records into the DB that you want instead of inserting all records and then filtering.

http://www.logparser.com/

This is a utility that allows you to run a SQL query against a directory of flat files in various formats as if they were in a database. Most of the functions you can think of which are in SQL and are not in many other command line tools for parseing flat files are availabel such as Distinct, group by, order by, count, max, min, avg, etc. There are 3 main parts to it: the input format, the query and the output format. There are many different input formats, I most commonly use IISLog directories as an input, and it automically knows how to recognize it. One awesome thing is that it keeps track of which files it’s been through so it can be setup to only process deltas.

The Queries use a limitied set of SQL syntax.

The outputs can display on the screen, another file, or direct into a database.

here’s an example of a logparser query that will give you a count of how many hits occured on a file in a specified timeframe from all of the IISLogs:
Logparser -i:IISW3C "Select count(*) from f:\IISlogs\*.log where cs-uri-stem like '%%PAGEYOUARELOOKINGFOR'and TO_TIME(time) BETWEEN TIMESTAMP('15:45:48', 'hh:mm:ss') AND TIMESTAMP('21:03:48', 'hh:mm:ss')"

I found a lot of links that told me how to do popup blockers, most of them produced errors when you ran them but still worked at a basic level. Then I was given a requirement to dynamically detect popups everytime one is blocked, instead of just once when the page is loaded. This too k a more intelligent and universal solution.

What I came up with was a script that attaches the popup blocking detection to the onclick action of every link that has a target that starts with an underscore. This way you could simply include the script at the beginning of any file and it will deal with all of the links that meet this crietria.

Enjoy

//attaches the popup blocking function to all links that have a target starting with an underscore
function setUpAnchors()
{
var Anchors = document.getElementsByTagName(‘a’);<code>for (i = 0; i < Anchors.length; i++)
{
AnchorTarget = Anchors[i].target;

if (AnchorTarget.substr(0,1) == ‘_’)
{
Anchors[i].onclick = DetectPopupBlock;
}
}
}

//function to check if popups are blocked and take action if they are
function DetectPopupBlock()
{
var mine = window.open(,,‘width=1,height=1,left=0,top=0,scrollbars=no’);

if(mine)
{
var popUpsBlocked = false
mine.close()
}
else
 {
  //THIS IS WHERE YOU PUT YOUR ACTION IF POPUPS ARE BLOCKED.
  var popUpsBlocked = true   alert(‘Popups are blocked’)
 }
}
</code>

4
Apr

Announcing webTRAM!

   Posted by: admin   in ASP, JavaScript, PHP, Software Development, webTRAM

I am proud to announce my first Open Source product, webTRAM. I have never seen this set of features in an open source product before or else I would have used it and not developed my own. Now that I have developed it I will never stop improving it. I believe this product will be useful in many projects / jobs I work in the future and I hope it can be the same for others.

 This product is intended to record as much as possible from user actions, record it to a database, and display it in an analytical or visual format for decision making.

webTRAM will blow away the usefullness of web server logs and every product that relies on them exclusively.

 This was built with the need of tracking web2.0 / AJAX / DHTML sites. Web server logs won’t tell you how many times a user slid an element back and forth, or dragged a window, or used any of the other fancy javascripts you have in your site. WebTRAM will record these actions and many others, like when they right click to copy text, or double click to select a word.

 Yes, this is a little overboard. I have found that an abundance of information is better than a lack of it. This processing does not impact server resources on tracking and recording significantly. The only overhead that is noticed is in the storage space that builds up and running reports against all of that stored data. Both of these can be addressed by managing your data and filtering queries.

 What I have made available so far is very minimal. I am using it curently in a production environment, but I have a lot of work to do to make this a product people can just use without modifying. I will call that milestone 1.0.

After 1.0 I have a lot of significant features to add, just look at the todo list of the main page.

If you haven’t already found the page in the “Pages” list here it is:

http://eclecticdevelopers.com/?page_id=7

20
Feb

Dynamic ASP includes

   Posted by: admin   in ASP, Software Development

If you are still using classic ASP… you will be familiar with the include statement. that looks liek this:

<!–#include file=”PagetoInclude.asp”–>

but if you try to use a variable instead of a string for the filename it will not work. This is because the includes are processed before the ASP.

here is a quick work around that uses vbscript to stream the file into the page, which will mimic the include statement but get around the limitation mentioned.

In order to use the function, pass in the filepath and the output will be returned to a vairable. From there you can process it further or output it.

This is the function:

‘Function to Include
Function DynamicInclude(strAbsoluteFilePath)
                Const ForReading = 1, ForWriting = 2, ForAppending = 3
                Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
                Dim Filename
                Filename = strAbsoluteFilePath ‘ file to read
                ‘ Create a filesystem object
                Dim objIncludeFSO
                set objIncludeFSO = server.createObject("Scripting.FileSystemObject")
                ‘ Map the logical path to the physical system path
                Dim strstrFilepath, streamOutput, Line
                strFilepath = Filename
                if objIncludeFSO.FileExists(strFilepath) Then
                                ‘ Get a handle to the file
                                Dim file
                                set file = objIncludeFSO.GetFile(strFilepath)
                                ‘ Open the file
                                Dim TextStream
                                Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
                                ‘ Read the file line by line
                                Do While Not TextStream.AtEndOfStream
                                                Line = TextStream.readline
                                                ‘ Do something with "Line"
                                                Line = Line &amp; vbCRLF
                                                streamOutput = streamOutput &amp; Line
                                Loop
                                Set TextStream = nothing
                                DynamicInclude = streamOutput
                Else
                                DynamicInclude = "File not found."
                End If
                Set objIncludeFSO = nothing
End Function

‘Here is an example of using the function
strAbsolutePath = "c:Inetpubwwwrootincludeme.htm"
htmlOutput = DynamicInclude(strAbsoluteFilePath)
response.write htmlOutput

Enjoy.

Page 3 of 3«123