NUnit Test a method including Request.Cookies

If you want to run Nunit testing on some ASP.NET code, then you might have some problems if the code being tested

makes reference to Request.Cookies. Here is how I got round it:

 

/// <summary>
/// Verify that critical parts of the default page are working
/// </summary>
[TestFixture]
public class DefaultMasterTesting
{
/// <summary>
/// Checks the Some Request.Cookies dependentent method
/// </summary>
[Test]
public void CheckSomeCookieDependentMethod()
{
var master = new Default();
master.Page = new Page();
var hrReq = new HttpRequest(“”, “http://localhost&#8221;, “”);
hrReq.Cookies.Add(new HttpCookie(“Cookie”, “Cookie Value”));
var hrResp = new HttpResponse(new StringWriter());
HttpContext.Current = new HttpContext(hrReq,hrResp);
var fiRequest = typeof (Page).GetField(“_request”, BindingFlags.NonPublic | BindingFlags.Instance);
fiRequest.SetValue(master.Page,HttpContext.Current.Request);
master.SomeCookieDependentMethod();
}
}

Interesting to see that Page.Request and HttpContext.Current.Request are different !

Categories: Uncategorized

Recursively listing directories in PHP

Just a simple PHP script to list directories two level deep:

$dir = dirname(__FILE__).’/’;

// Open a known directory, and proceed to read its contents
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (filetype($dir . $file) == “dir” && $file !== “.” && $file !== “..” && $file !== “images”)
{
echo “<li>$file</li>”;
$dh2 = opendir($dir . $file);
echo “<ul>”;
while (($file2 = readdir($dh2)) !== false)
{
if ($file2 !== “.” && $file2 !== “..”)
{
echo “<li><a href=’$file/$file2′>$file2</a></li>”;
}
}
closedir($dh2);
echo “</ul>”;

}
}
closedir($dh);
}
}

I’ve used this to help index the 80 GB or so files I’ve now recovered from the GEOCITIES torrent

Which I’ve indexed from A to Z 

     Sunday, October 14, 2012 11:17 AM        <dir> 0
     Monday, October 15, 2012  3:10 PM        <dir> 1
     Sunday, October 14, 2012 11:18 AM        <dir> 2
     Sunday, October 14, 2012 11:19 AM        <dir> 3
     Sunday, October 14, 2012 11:20 AM        <dir> 4
     Sunday, October 14, 2012 11:20 AM        <dir> 6
     Sunday, October 14, 2012 11:20 AM        <dir> 8
     Sunday, October 14, 2012 11:20 AM        <dir> 9
     Monday, October 15, 2012  3:09 PM        <dir> _
     Monday, October 15, 2012  4:53 PM        <dir> a
     Monday, October 15, 2012  5:06 PM        <dir> b
     Monday, October 15, 2012  5:21 PM        <dir> c
     Sunday, October 14, 2012  3:33 PM        <dir> d
    Tuesday, October 16, 2012  3:37 AM        <dir> e
     Monday, October 15, 2012  3:54 AM        <dir> f
    Tuesday, October 16, 2012  3:48 AM        <dir> g
    Tuesday, October 16, 2012  3:50 AM        <dir> h
    Tuesday, October 16, 2012  4:35 AM        <dir> i
    Tuesday, October 16, 2012  4:54 AM        <dir> j
     Monday, October 15, 2012  5:38 AM        <dir> k
    Tuesday, October 16, 2012  5:55 AM        <dir> l
     Monday, October 15, 2012  7:40 AM        <dir> m
     Monday, October 15, 2012  7:47 AM        <dir> n
     Monday, October 15, 2012  9:36 AM        <dir> o
     Monday, October 15, 2012  9:43 AM        <dir> p
     Monday, October 15, 2012 12:20 PM        <dir> r
     Monday, October 15, 2012 12:45 PM        <dir> s
     Monday, October 15, 2012 12:52 PM        <dir> t
     Monday, October 15, 2012  2:26 PM        <dir> u
     Monday, October 15, 2012  2:30 PM        <dir> v
     Monday, October 15, 2012  2:34 PM        <dir> w
     Monday, October 15, 2012  2:34 PM        <dir> x
     Monday, October 15, 2012  2:50 PM        <dir> y
     Monday, October 15, 2012  2:59 PM        <dir> z
Categories: Uncategorized

Free FTP account

Here is a free FTP account, anyone can use it to upload anything…

  • FTP Username: free@wikiencyclopedia.net
  • Password: nniyadiloh
  • FTP Server: ftp.wikiencyclopedia.net
  • FTP Server Port: 21

FAQ:
Why?
– I’ve got ample space on this server, I’m willing to share with others.

Is it private?
– Nope, anyone can access it, delete your files that you uploaded, rename them, download them, whatever

Can I access this over a browser?
http://www.wikiencyclopedia.net/free is the root.

Can you help me install WordPress / Joomla / Whatever?
– Nope.

Can I upload dodgy stuff?
– It will be deleted, and your IP blocked, all uploads are moderated.

Want to try it out now, you can use http://ftp.apixml.net

Categories: Uncategorized

Unlimited webspace hosting

Here are another 35 websites I’ve rescued from the Geocities torrent. The next recovery looks huge … 65 GB of sites, which

    Friday, October 12, 2012 11:21 PM        <dir> 0
     Friday, October 12, 2012 11:22 PM        <dir> 1
     Friday, October 12, 2012 11:24 PM        <dir> 2
     Friday, October 12, 2012 11:24 PM        <dir> 3
     Friday, October 12, 2012 11:26 PM        <dir> 4
   Saturday, October 13, 2012  6:17 AM        <dir> _
   Saturday, October 13, 2012  7:18 AM        <dir> a
   Saturday, October 13, 2012  1:25 AM        <dir> b
   Saturday, October 13, 2012  7:21 AM        <dir> c
   Saturday, October 13, 2012  1:41 AM        <dir> d
   Saturday, October 13, 2012  7:36 AM        <dir> e
   Saturday, October 13, 2012  7:43 AM        <dir> f
   Saturday, October 13, 2012  2:38 AM        <dir> g
   Saturday, October 13, 2012  2:41 AM        <dir> h
   Saturday, October 13, 2012  8:05 AM        <dir> i
   Saturday, October 13, 2012  3:40 AM        <dir> j
   Saturday, October 13, 2012  3:41 AM        <dir> k
   Saturday, October 13, 2012  4:36 AM        <dir> l
   Saturday, October 13, 2012  4:43 AM        <dir> m
   Saturday, October 13, 2012  4:45 AM        <dir> n
   Saturday, October 13, 2012  6:05 AM        <dir> o
   Saturday, October 13, 2012  6:07 AM        <dir> t
   Saturday, October 13, 2012  6:07 AM        <dir> v
   Saturday, October 13, 2012  6:08 AM        <dir> x
   Saturday, October 13, 2012  6:09 AM        <dir> z
Categories: Uncategorized

Iterating HTMLSelectElement options in C# And VB.NET

If you want to list all the values of options in a HTML drop down list, from a webbrowser control in VB.NET or C#, here’s how to do it:

Dim hoeDest As HTMLOptionElement
For iDest = 0 To hseDestinations.options.length – 1
hoeDest = hseDestinations.options.item(iDest)
tbOutput.Text += hoeDest.value
Next iDest

Or in C#

for (var iDest = 0; iDest <= destinationSelect.Children.Count – 1; iDest++)
{
var hoeDest = (HTMLOptionElement)destinationSelect.Children[iDest].DomElement;
tbOutput.Text += hoeDep.value;
}

 

Categories: Uncategorized

Another 183 sites rescued from the demise of geocities

     Friday, October 12, 2012  2:27 PM        <dir> _
     Sunday, October 14, 2012  8:16 AM        <dir> a
     Monday, October 15, 2012  2:59 PM        <dir> b
    Tuesday, October 16, 2012  6:04 AM        <dir> c
   Saturday, October 13, 2012  6:09 AM        <dir> f
     Friday, October 12, 2012 11:13 PM        <dir> g
     Friday, October 12, 2012 10:47 PM        <dir> h
     Friday, October 12, 2012 10:22 PM        <dir> i
     Friday, October 12, 2012 10:07 PM        <dir> j
     Friday, October 12, 2012  9:51 PM        <dir> k
     Friday, October 12, 2012  9:39 PM        <dir> l
     Friday, October 12, 2012  9:24 PM        <dir> m
     Friday, October 12, 2012  9:12 PM        <dir> n
     Friday, October 12, 2012  8:42 PM        <dir> o
     Friday, October 12, 2012  8:21 PM        <dir> p
     Friday, October 12, 2012  7:56 PM        <dir> q
     Friday, October 12, 2012  7:20 PM        <dir> r
     Friday, October 12, 2012  7:01 PM        <dir> s
     Friday, October 12, 2012  6:54 PM        <dir> t
     Friday, October 12, 2012  6:24 PM        <dir> u
     Friday, October 12, 2012  5:41 PM        <dir> v
     Friday, October 12, 2012  4:55 PM        <dir> w
     Friday, October 12, 2012  4:19 PM        <dir> x
     Friday, October 12, 2012  3:32 PM        <dir> y
     Friday, October 12, 2012  2:46 PM        <dir> z
Categories: Uncategorized

NVARCHAR(4000) & NTEXT vs NVARCHAR(MAX)

What is the difference between NVARCHAR(4000), NTEXT and NVARCHAR(MAX)?

First consider this SQL script:

 

declare @BigData ntext
set @BigData = N’0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-1K-
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-2K-
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-3K-
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-4K-‘

select @BigData

If @BigData is declared as NVARCHAR(4000), then the select statement will truncate at 4K bytes. You can’t declare as NVARCHAR(8000) as it will give the error:

Msg 2717, Level 16, State 2, Line 1
The size (8000) given to the parameter ‘@BigData’ exceeds the maximum allowed (4000).

@BigData cannot be declared as NTEXT, since it gives the error:

Msg 2739, Level 16, State 1, Line 1
The text, ntext, and image data types are invalid for local variables.

but, as NVARCHAR(MAX) then the data is not truncated!

 

Categories: Uncategorized

How to loop for a specified time in C#

Say that you wanted to do something for one minute, as often as possible; then this bit of code is quite a nice way of doing it;

It would be called like:

foreach(var i in TimeLoop(TimeSpan.FromSeconds(30))

{ // Do something }

 

/// <summary>
/// A Loop that continues for a given time
/// </summary>
/// <param name=”duration”></param>
/// <returns></returns>
private static IEnumerable TimeLoop(TimeSpan duration)
{
var dtStart = DateTime.Now;
for (; ; )
{
yield return null;
System.Threading.Thread.Sleep(100);
var tsElapsed = DateTime.Now – dtStart;
if (tsElapsed > duration)
{
yield break;
}
}
}

Categories: Uncategorized

Saving Geocities

I downloaded the Geocities torrent, but it only gets to 23.7% complete, so, stopping it there, I unzipped whatever zips I could, finding only “geocities.archiveteam.torrent\ARCHIVES\geocities-unmangled\www.geocities.com” to be the only directory with a few sites that could be salvaged.

After that, I processed all the html files, removing absolute links, then uploaded them to my server. It’s only 104 websites, or 340 Mb out of the 1 Tb download, so it’s less than a 3,000th of the size of geocities, but whenever a 100% seed for that torrent comes online, then I can finish the download.

 

 Saturday, October 13, 2012 12:17 PM        <dir> 0
   Saturday, October 13, 2012 12:25 PM        <dir> 1
   Saturday, October 13, 2012 12:25 PM        <dir> 2
   Saturday, October 13, 2012 12:25 PM        <dir> 3
   Saturday, October 13, 2012 12:26 PM        <dir> 4
   Saturday, October 13, 2012 12:28 PM        <dir> 5
   Saturday, October 13, 2012 12:28 PM        <dir> 7
   Saturday, October 13, 2012 12:28 PM        <dir> 8
   Saturday, October 13, 2012 12:28 PM        <dir> 9
     Sunday, October 14, 2012  8:29 AM        <dir> _
     Sunday, October 14, 2012  8:40 AM        <dir> a
     Sunday, October 14, 2012  8:52 AM        <dir> c
     Sunday, October 14, 2012  9:18 AM        <dir> d
   Saturday, October 13, 2012  2:55 PM        <dir> e
     Sunday, October 14, 2012  9:37 AM        <dir> f
     Sunday, October 14, 2012  9:40 AM        <dir> g
     Sunday, October 14, 2012  9:56 AM        <dir> h
     Sunday, October 14, 2012 10:22 AM        <dir> i
   Saturday, October 13, 2012  5:26 PM        <dir> j
   Saturday, October 13, 2012  6:02 PM        <dir> k
   Saturday, October 13, 2012  6:03 PM        <dir> L
   Saturday, October 13, 2012  8:16 PM        <dir> m
     Sunday, October 14, 2012  1:11 AM        <dir> n
     Sunday, October 14, 2012  1:18 AM        <dir> o
     Sunday, October 14, 2012  1:47 AM        <dir> p
     Sunday, October 14, 2012  2:12 AM        <dir> q
     Sunday, October 14, 2012  4:06 AM        <dir> r
     Sunday, October 14, 2012  5:22 AM        <dir> s
     Sunday, October 14, 2012  5:51 AM        <dir> t
     Sunday, October 14, 2012  6:37 AM        <dir> u
     Sunday, October 14, 2012  7:05 AM        <dir> v
     Sunday, October 14, 2012  7:05 AM        <dir> W
     Sunday, October 14, 2012  7:14 AM        <dir> x
     Sunday, October 14, 2012  7:37 AM        <dir> y
     Sunday, October 14, 2012  8:16 AM        <dir> z
Categories: Uncategorized

Unable to telnet to port 25 remotely (Windows SMTP)

Categories: Uncategorized