Archive for June, 2010

Http status 417: expectation failed

An interesting problem I found when calling a web service was this error:

Http status 417: expectation failed

Reading posts on the net said this could be a proxy problem, but I wasn’t using a proxy, so this wasn’t it. The solution appeared
as this little gem:

ServicePointManager.Expect100Continue = false;


I guess the server must have responded with a HTTP 100, which was not expected by the client, or vice versa. The Webservice
itself appeared to be hosted on a platform.

Categories: Uncategorized

Cannot assign requested address: make_sock: could not bind to address

I spotted that my Apache server was not working this morning, so I went to restart it via Putty

root@vps ~ # /etc/init.d/apache2 restart
Forcing reload of web server (apache2)…httpd (no pid file) not running
(99)Cannot assign requested address: make_sock: could not bind to address
no listening sockets available, shutting down
Unable to open logs
You have mail in /var/mail/root


I was aware that my host were chaning IP addresses, for some time, and this was the old IP address that the server was trying to bind to.
So, I found that by editing /etc/apache2/ports.conf and removing the old IP addresses, then restarting apache again, the server
was back up again.

Categories: Uncategorized

Embed ASP.NET or JSP in a WordPress Blog

Tonight, I got my WordPress IFrame-less plugin / widget listed on WordPress extend. It’s a simple plugin that allows non-PHP
content to be fectched and displayed on a wordpress blog.

It’s page is at

With a demo at

Categories: Uncategorized

How bugs are actually fixed

Short version:
   I created a new IIS Application with the newsletter
folder, created a new app pool for it, and ran it as "Local System",
Then set the Connection string to "Initial Catalog=db;Data
Source=localhostSQLExpress;Integrated Security=SSPI;"

Actual events:
    – Feck, why’s visual studio opening, what the
hell’s UID?, never seen that, copy-and-paste from random website,
refresh, not
working, create application, feck, crashed again, create
application pool, not working, Oh feck, yellow page, F5 F5 F5 F5,
feck, check other sites, still up, phew, What the hell is IWAM_PLESK,
wtf!!, Google it, oh, must check email… ok, click
SQL logins, click
users, where the feck is IWAM_plesk not appearing, ah, wrong button,
add, grant, grant, click click click, refresh
F5, feck, not working, I’ll put the priviliges up on the new app pool.
"Service Unavailable" feck feck feck, iisreset, F5 F5 F5, feck,
back up. Set to Administrator, typo, "Adminstrtor", idiot, change back.
Back into SQL server, ah, it’s called SQLExpress, change connection
string. It works hurray…
Categories: Uncategorized

Using OnClientClick with Chrome causes server side submit to fail.

If you embed an page as an IFrame in a page, where the submit button jumps out of that frame, i.e. in the case of a search form, then you could end up using code like this:

 <asp:Button id="btnSearch" runat="server" Text="Search" onclick="btnSearch_Click" OnClientClick="javascript:pageSubmit()" />

<script language="javascript">
    function pageSubmit() {
        var SearchForm = document.forms[0]; = ‘_top’;

However, btnSearch_click doesn’t fire when running under google Chrome …

This is a bit of a hack that I’ve used to get round this:

protected void Page_Load(object sender, EventArgs e)
            if (Page.IsPostBack && string.IsNullOrEmpty(Request.Form["__EVENTTARGET"]))
                    btnSearch_Click(sender, e);

No marks for elegance, but it seems to work in Chrome, IE and Firefox.


Categories: Uncategorized

Genetic algorithims in C#

Genetic algorithms are basically where random operations are applied to solve problems, and the ‘fittest’ of these random collections bias the generation of the next collection of random operations.

The beauty of this, is that there is no need to understand the underlying problem, just throw lots of computing power at it, until the solution is approximated.

This is the same way that nature uses to solve problems, where random organic mutations discover the best, or at least a suitable, creature for any hospitable environment. However, that doesn’t need to be the basis for computer algorithms.

For example, let’s take a set (x) of 5 (n) numbers [1,2,3,4,5], what comes next? 6?, yes, pretty obvious, but how would a computer solve that?  x[n-1]+1, is the solution if you understand the sequence, but if you didn’t….

Let’s say our objects can be x[1],x[2]…x[n], and the whole numbers 1 to n, then we have 5 basic operations, +, -, /, *, %, and we put our operation complexity (c) to 3, for instance.

Pick c random operations, between the range of 1 to n*2, followed by c-1 random operations in the range 1 to 5, this gives us a "bytecode" sequence of
which gives
x[5] % x[4] / 10  =  0.1

Nowehere near 6, but lets say we kept randomly doing that until we got the number 6. From this we then create a "population" of similar algorithms, by just
tweaking one digit of the byte code up or down, or replacing an operation.

Then the logic goes, we change the sequence [2,3,4,5,6] with the next number being 7, and the closest of the "population" goes on to create the next generation.

What I’ve described above is akin to Asexual reproduction in nature, where the genetic code of any organism is inherited from one parent only. This is only used for simple organisms in nature, and it is more normal for genetic code to be inherited from two parents.

To apply this analogy to the code, it would mean that the two closest operations, i.e. resulting in 6.03 and 5.98 in the first generation would have their byte-code merged, either by averaging, or substitution.

To extend this analogy beyond nature, it would be quite possible, to take the top 3 fittest operations, and merge them, resulting in trisexual reproduction, although evidence could only be garnered from experimentation at this point, it would stand to reason that if 2 parent genetic inheritance is more effective than single parent inheritance at creating advanced life, perhaps the same can be applied to genetic algorithms?

Categories: Uncategorized

Timing SQL statements

Often, when comparing two SQL statements for speed, you end up relying on the counter in the bottom left counter of SQL Management studio,
but if you’re trying to shave milliseconds off a query that takes under a second than the result "00:00:00" doesn’t give you anything to go on.

So; instead, if you declare a @timeStart as a datetime, run your query, then get a datediff in milliseconds against the current time, then you get something more meaningful.

declare @timeStart as datetime
set @timeStart = getdate()
select count(*) from foo
select datediff(ms,@timestart,getdate())

In the above code block "select count(*) from foo" is the query I want to test.

Categories: Uncategorized

‘Not a real geek Goodbye my friends’ – Skyscanner’s Geek of the Week

SkyScanner’s Geek of the week had this puzzle:

 here’s a message for anyone fluent in

import re
re.sub("(?si)z", " ",
re.sub("(?si)[^abdefgiklmnorstyz]", "", """NcoHjptXzuQvaJqPzu

Couldn’t help myself with the challenge:

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.sub("(?si)z", " ", re.sub("(?si)[^abdefgiklmnorstyz]", "", """NcoHjptXzuQ
… rCeUhxaClHpqzJgWupeheCPxkczWXhGJoUvpocdHQubVyWjpecjzHpmXuyQvzH
… wfPcrXuijepHnqVdjs"""))
‘Not a real geek Goodbye my friends’

Categories: Uncategorized
%d bloggers like this: