Firing an onchange event from a HTMLSelectElement
Javascript redirect after images have loaded
This is a handy piece of javascript that can be used to execute a redirect only after all images have loaded on a page, up to a maximum of 10 seconds. I put in this maximum threshold, to account for the possibility of a bad link on the page, or a user with images turned off on their browser.
waitForImages();
var imageLoadTimeout = 10; // max 10 seconds;
var timeWaited = 0;
function waitForImages()
{
var AllLoaded=true;
if (timeWaited>imageLoadTimeout)
{
// redirect after 10 seconds, regardless of whether images are loaded.
ImagesLoaded();
return;
}
for(i=0;i<document.images.length;i++)
{
var image = document.images[i];
if (!image.complete && image.name != "brokenImage" )
{
AllLoaded=false;
break;
}
}
if (AllLoaded)
{
ImagesLoaded();
}
else
{
timeWaited += 0.5;
setTimeout(‘waitForImages()’,500);
}
}
function ImagesLoaded()
{
RedirectPage();
}
Useful c# function – remove duplicates
public
ArrayList RemoveDups(ArrayList items){
ArrayList noDups =
new ArrayList(); foreach(string strItem in items){
if (!noDups.Contains(strItem.Trim())){
noDups.Add(strItem.Trim());
}
}
noDups.Sort();
return noDups;}
Handy!
del.icio.us auto-post
private
void SubmitDelicious(string url,string description,string username,string password,string tags){
#region
postdata /*POST /login HTTP/1.1
Host: secure.del.icio.us
user_name=nora344
password=lokiju
jump=no
url=http%3A%2F%2Fwww.envoyez.com
login=log+in
GET /nora344?url=http%3A%2F%2Fwww.envoyez.com
jump=no
POST /nora344?636480 HTTP/1.1
Host: del.icio.us
url=http%3A%2F%2Fwww.envoyez.com
oldurl=http%3A%2F%2Fwww.envoyez.com
description=envoyez+sms
notes=
tags=
jump=no
key=6c7b3c42b196c8e3ebc90130317786eb
*/
#endregion
// step 1. login string strUrl = "https://secure.del.icio.us/login"; string strPostdata = "user_name=" + username + "&";strPostdata += "password=" + password + "&";
strPostdata += "jump=no&";
strPostdata += "url=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "login=log+in&";
HTTPRequest hrWeb =
new HTTPRequest();hrWeb.blnExpect100Continue =
false; string html = hrWeb.Request(strUrl,"POST",strPostdata); // at this point, we may need to transfer cookies from secure.delicious to delicious?CookieCollection ckCol = hrWeb.RequestCookies.GetCookies(
new Uri("https://secure.del.icio.us"));
Cookie ckAccept =
new Cookie("_accept_s_cookies","1","/",".icio.us");Cookie ckInstall =
new Cookie("_ext_install_redir","1","/",".icio.us");Cookie ckRegister =
new Cookie("_register_id","1248967165","/",".icio.us"); // _register_id?Cookie ckUser =
new Cookie("_user",ckCol["_user"].Value,"/",".icio.us");Cookie ckBM =
new Cookie("_bm_url",HttpUtility.UrlEncode(url),"/",".icio.us"); // BX=4ehl0pt2i6vse&b=3&s=dr – already sethrWeb.RequestCookies.Add(ckAccept);
hrWeb.RequestCookies.Add(ckInstall);
hrWeb.RequestCookies.Add(ckRegister);
hrWeb.RequestCookies.Add(ckUser);
hrWeb.RequestCookies.Add(ckBM);
// step 2. redirectstrUrl = "http://del.icio.us/";
strUrl += username;
strUrl += "?url=" + HttpUtility.UrlEncode(url) + "&jump=no";
html = hrWeb.Request(strUrl);
if (html.IndexOf("in order to save an item, you have to log in")!=-1){
return;}
string strIDRegex = @"action…w+?(?<ID>d+)"; string strID = Regex.Match(html,strIDRegex).Groups["ID"].Value; string strKeyRegex = @"key..value..(?<KEY>w+)"; string strKey = Regex.Match(html,strKeyRegex).Groups["KEY"].Value; // step 3. poststrUrl = "http://del.icio.us/" + username + "?" + strID;
strPostdata = "url=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "oldurl=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "description=" + HttpUtility.UrlEncode(description) + "&";
strPostdata += "notes=&";
strPostdata += "tags=" + HttpUtility.UrlEncode(tags) + "&";
strPostdata += "jump=no&";
strPostdata += "key=" + strKey;
html = hrWeb.Request(strUrl,"POST",strPostdata);
}
Java Midlet for .NET web services
Visitor Tracker in ASP.NET
ON RecentVisitors
FOR INSERT
AS
BEGIN
— note this will track hits not unique visitors.
select @VisitorsToday = count(*) from RecentVisitors
where dateDiff(day,Date,getdate())=0
and websiteId=@websiteID
delete from AggregatedVisitors where
websiteID = @websiteID
and
Datediff(day,date,getDate())=0
values (@VisitorsToday,@websiteID)
delete from recentVisitors where dateDiff(day,Date,getdate())>1
END
<script language="javascript">
var WebsiteID = 1;
var Tracker = window.document.images["Tracker"];
Tracker.src = "default.aspx?WebsiteId=" + WebsiteID + "&Referrer=" + escape(document.referrer);
</script>
{
string strReferrer = Request.QueryString["Referrer"].ToString();
int intWebsiteID = Convert.ToInt32(Request.QueryString["WebsiteID"]);
string strSQL = "insert into RecentVisitors (IP,Referrer,websiteId) values (";
strSQL += "’" + Request.ServerVariables["REMOTE_ADDR"] + "’,";
strSQL += "’" + strReferrer.Replace("’","”") + "’,";
strSQL += intWebsiteID + ")";
base.ExecuteNonQuery(strSQL);
Session["FirstTime"]=false;
}
Bitmap bmpCanvas = new Bitmap(1,1);
Response.ContentType = "image/gif";
bmpCanvas.Save(Response.OutputStream,ImageFormat.Gif);
ExcecuteNonQuery is a function I wrote to run a statement against the database, and is outside the scope of this blog.
Then, to view this data in a meaningful way, I created a page with two dataGrids, dgRecentVisitors and dgAggregatedVisitors, which used the following SQL to display their results:
select top 20 rv.id,referrer,date from recentvisitors rv
join websites w on w.id = rv.websiteid
where charindex(w.websiteaddress,rv.referrer)=0
order by date desc
and
select * from aggregatedVisitors order by date desc.
and, that suffices for a tracker for my purposes, and I have access to the raw data, should I need to run queries to work out sales conversion rates etc. The only downfall is that it does not correctly measure visitors rather than hits, but that’s work for another day.
Njoy.
Reconnecting ADSL programatically
http://192.168.1.2/doc/loginout.htm?
WINDWEB_URL = %2Fdoc%2Floginout.htm&
simple_ppp_username = xxxx&
simple_ppp_pwd = xxxx&
wanAdapterSelection = 0&
wan_encapsulation = 0&
wan_VPI = 0&
wan_VCI = 38&
PPP_connection_number = 1&
New_PPP_Action = 0
VPN option greyed out in Windows XP
Parser Error Message: Access is denied
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Web.UI.CompilationConfiguration.LoadAssemblies(Hashtable original)
[ConfigurationException]: Access is denied: ‘erc’. (c:winntmicrosoft.netframeworkv1.1.4322Configmachine.config line 258)
at System.Web.UI.CompilationConfiguration.LoadAssemblies(Hashtable original)
at System.Web.UI.TemplateParser.AppendConfigAssemblies()
at System.Web.UI.TemplateParser.PrepareParse()
at System.Web.UI.TemplateParser.Parse()
at System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()
at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWithNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at System.Web.UI.ApplicationFileParser.GetCompiledApplicationType(String inputFile, HttpContext context, ApplicationFileParser& parser)
at System.Web.HttpApplicationFactory.CompileApplication(HttpContext context)
at System.Web.HttpApplicationFactory.Init(HttpContext context)
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)