Archive

Author Archive

.NET Framework class source code viewer

Categories: Uncategorized

Microsoft publishes the .NET framework source code

Categories: Uncategorized

Stress testing functions from NUnit

NUnit may say that a function works when run once, but what happens if you the same function twice at once. You may find that a static or shared dictionary could crash when adding two identical keys from two seperate threads.

So, here is a nice function to call another function multiple times at once, and verify the output.

 

/// <summary>
/// Puts a particular method under stress by calling it multiple times at once
/// </summary>
/// <typeparam name=”T”>The type of the parameter sent to the method under test</typeparam>
/// <typeparam name=”TResult”>The type of the result from the method.</typeparam>
/// <param name=”method”>The method.</param>
/// <param name=”parameter”>The parameter to be passed to the method.</param>
/// <param name=”check”>The check.</param>
/// <param name=”load”>The number of times the method should be called at once.</param>
public static void StressTest<T, TResult>(Func<T, TResult> method, T parameter, Predicate<TResult> check, int load)
{
var lWorkers = new List<IAsyncResult>();
for (var i = 0; i < load; i++)
{
lWorkers.Add(method.BeginInvoke(parameter, null, null));
}
foreach (var result in lWorkers.Select(method.EndInvoke))
{
Assert.IsTrue(check(result));
}
}

And that puts the funk into funktion 🙂

Categories: Uncategorized

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