Archive

Archive for the ‘Uncategorized’ Category

Moving from MsSQL to MySQL

I’ve decided to start moving some data from my MsSQL database to a MySQL one. Why?, because I’d like my MsSQL database to be used for my main websites, and the MySQL one used for less important ones. Those where the data is bulky but the performance isn’t so important. – Since my MySQL db is nowhere near my webserver.

Anyway, I was surprised how easy it was to migrate,

This is the code I use for MsSQL:

public DataSet ExecuteDataSet(string sql)
{
DataSet ds = new DataSet();
try
{

OleDbConnection DSN = new OleDbConnection(connectionString);
DSN.Open();
OleDbCommand Database = new OleDbCommand(sql,DSN);
OleDbDataAdapter Adapter = new OleDbDataAdapter(Database);
Adapter.Fill(ds,”sql”);
DSN.Close();
}
catch(Exception ex)
{
logError(ex,sql);
}
return ds;
}

Just replace OleDb with MySql and you get

public DataSet ExecuteMySqlDataSet(string sql)
{
DataSet ds = new DataSet();
try
{

MySqlConnection DSN = new MySqlConnection(MySqlConnectionString);
DSN.Open();
MySqlCommand Database = new MySqlCommand(sql, DSN);
MySqlDataAdapter Adapter = new MySqlDataAdapter(Database);
Adapter.Fill(ds, “sql”);
DSN.Close();
}
catch (Exception ex)
{
logError(ex, sql);
}
return ds;
}

And then include using MySql.Data.MySqlClient;

A few tweaks to the SQL, so instead of select top 10 * … it’s select * … limit 10, instead of order by newid() it’s order by rand(), and the table names are case sensitive.

I hit some wierd bug where it didn’t recognise column names with umlauts, but I just worked around that instead of fixing it. – Anyway, here’s the end-result: http://www.listofbanks.info/GermanBanks.aspx

Categories: Uncategorized

How to make a Geo-Aware website?

I’ve made a page that locates your closest bank branch using a Geo-aware webpage see

http://www.listofbanks.info/FindBank.aspx

Once you share your location with the page, using the prompt provided, it makes an AJAX call with your longitude and latitude to another page which returns the top 10 banks in our database ordered by distance. The system will only work in europe, so americans may see their nearest bank in spain!.

The JavaScript I used was as follows:

if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(success_callback, error_callback, { enableHighAccuracy: true });
}
else {
window.document.getElementById(“response”).innerHTML = “Failed.”;
}

function success_callback(p) {
var oXHR = new XMLHttpRequest();
var strUrl = “FindBankAjax.aspx?”;
strUrl += “Latitude=” + p.coords.latitude.toFixed(2);
strUrl += “&Longitude=” + p.coords.longitude.toFixed(2);
oXHR.open(“get”, strUrl, false);
oXHR.send(null);
window.document.getElementById(“response”).innerHTML = oXHR.responseText;
}

function error_callback(p) {
window.document.getElementById(“Failed due to ” + p.code)

}

 

 

Categories: Uncategorized

Free MySQL database

Here’s a free MySQL database that anyone can use:

 

Database: wikienc1_free

Username: wikienc1_free

Password: 00036IT

Host: 184.154.116.162

FAQ:

1. Is this really free?

Yup. But I’d appreciate a backlink from your website!

2. Is it private?

Nope.

3. Won’t someone just delete my data

They could, but please don’t delete other people’s data.

4. Can’t you set up an account just for me?

Pay me and I will 🙂

5. Will you help install WordPress / Joomla / whatever ?

Nope.

6. Will the username or password change.

They could, bookmark this page, it will always be updated with the latest password

 

Categories: Uncategorized

Code syntax highlighter for C#

Categories: Uncategorized

.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