You need to get out on your whale, into the big scary ocean, and start learning and creating again.
Monday, July 2, 2012
You selfish pig!
You are on a plane on the aisle seat. At the window is guy in a business suit. Quiet and seemingly very annoyed. You don't like him. In the middle, a proverbial little old lady is sitting. In contrast to the guy in the window, she seems rather chirpy. In the middle of the flight she starts talking to the both of you: "Fellows... you know what? My husband was in the steel business and he died last year, leaving me with a fortune. I'm bored and I want some fun. I'll tell you what. I'll give $100,000.00 and if you can decide how to split it, you can have it. If not, you both get nothing."
For the first time in the flight the guy at the window seems interested. "My name is Dick. What's the catch?" he says. "Ok Dick", the lady continues. "You can decide how the money should be split and if the handsome fellow next to me agrees, you can have the money, okay?". "Sure!", Dick says. "I'll take $99,000.00 and the guy in the aisle can have the other $1,000.00"
So what do you do? Can you feel Richard Dawkins' selfish gene stirring in your loins? Logically, you should always accept, because you have nothing to lose. Right?Strangely, the majority of people starts declining at around 60% (i.e. 60% for the proposer and 40% for the decider).
I was wondering what a computer will do with this... I set up the experiment as follows: A hundred thousand agents playing the game in a tournament fashion. Pick two random agents, let them play, repeat (they play one game, one the decider, the other the proposer). Each agent evolves two values. One value (the "proposition") is the value it will propose and the "decision-threshold", which is the minimum it will accept. Therefore, for a [0.9, 0.6] pair, the agent will propose 90% of the money for itself and will only accept a minimum cut of 40%, when it has to decide. I allowed this to evolve (population size of 100,000). After several generations, quadrillions of games, the most successful agent was as follows:
P:0.73 D:0.85
This means, proposing a 73%-27% split and declining any selfish agent that wants more then 85% was optimal. Hell, this was not at all expected! I repeated the experiment several times, each time with similar results. The decision-threshold was always slightly higher, but the proposition threshold seemed to be fairly stable at around 0.7-0.9. How come? Can computers really be selfish too?
EDIT: After further experimentation, I found that the TOTAL money distributed amongst individuals tend to increase (i.e. the group improves as a whole) - and rather quickly as well.
If I initialise all agents to the most narsistic value of (P,D)=(1,0), which means I want all the money and if you don't propose I get everything, I say no. The total money made by each generation changes as follows (generation; total money):
After which it stabilises. This is completely emergent as I never test the total money made by the population.
Thursday, June 28, 2012
Djikstra's algorithm in node / javascript
So tonight I had to implement Djikstra's algorithm to do some very simple pathfinding in an experimental thing I'm working on, so seeing as nothing has happened in June I decided I'll post the code.
Perhaps someone finds it useful some day, perhaps someone wants to discuss it or improve it. The code is very rough as I needed it *now*. Probably some bugs in there as well. I'm gonna start to use it now so I'll update the code as I find them :) I started of all functional but very quickly reverted back to old habits as the impending deadline loomed :)
Anyway, so it was fun writing some proper algorithm code again after how many years of businessy stuff :)
Djikstra in JS:Thursday, May 17, 2012
cannedhttp - Testing HTTP based webservices in Java
So, recently I've again been writing webservices using HTTP as the transport in Java, and after getting used to node.js land where it is so, so easy to test these kinds of webservices, I was longing for the same kind of compact, self-contained testing. So, I came up with cannedhttp, a small self-contained 'canned' webservice testing tool to help with testing webservices.
The idea is very simple, most requests, especially in unit-testing scenarios, always need to return the same content. So, why can't this just be done with static webservers? Well, the problem with using static webservers for this is that you need to be able to set the HTTP response code, the HTTP headers (such as Content-type) and so forth, and also the different HTTP verbs such as POST, PUT, DELETE. Normally, static webservers only support GET.
So canned-http takes a very simple approach to this problem - your file structure is your web service endpoints. All files have an HTTP verb as the suffix - such as .GET, .POST, .PUT etc. All files also have a very simple file structure allowing you to specify http response code, headers, and content.
In addition to this, it also gives you a very basic router API to add handlers to intercept requests, allowing you to check whether your code is actually sending the correct requests through. It also allows you to customise the response - giving you the ability to start doing some real testing around your webservice calls, while not being reliant on an external webserver at all. It also gives you predictability - seeing as at it's basic form, cannedhttp always returns the same content for the same request.
Here is a sample canned file, showing how you could do a SOAP response for example:
Placing this file in a subdirectory as /one/two/soap.GET, will allow you to test a SOAP webservice at /one/two/SOAP
Here is some code showing the basic router API:
So, there it is. Hopefully this can be of use to some of you. I know it's been helping me the past week or so. It really has sped up the development of webservice code for me - some of the stuff I haven't even tested against a "real" webservice - I've just followed the spec documents and used the examples in those and made sure I could parse them, right there in my unit tests.
Cisco VPN client with certificates only
I hope it will also help someone else in the future. It is definitely going to help me when I have to do it again.
Wednesday, May 9, 2012
Disqus - revisit
Right, so it's been a while since we last discussed, Disqus (see what I did there).
Original post: Disqus is pissing me off
And let me save you from any sort of suspense you may have regarding whether my feelings have changed: they have not. That is why my vote is to: drop it. As soon as possible.
As highlighted in that post, there are issues surrounding administering Whaleventures / Disqus while logged into your own, personal Disqus/Google accounts. There are issues where the thing marks innocent comments as spam. It forces the revealing of firstnames and lastnames, and our resident incognito users don't like that. Then you've got the issue where you can't embed links. Oh, don't forget the issue with code formatting. It seems you need to be a Disqus formatting guru to get it to preserve whitespace.
I have exported our comments as of this moment (2012-05-09 19:50), and they provide you with a nice XML file. The content of the XML file looks straightforward enough. If we get consensus, I will figure out a way to re-import our old comments back into whatever new system we choose, even if I have to generate each of you your own customized python script or whatever with your comments in it.
So, who's with me? Are we gonna drop Disqus?
Tuesday, May 8, 2012
Code weirdness
<boolean-expression> ? <statement> : <statement>;
See if you can spot it. The idea is as follows. If the number is a round number (i.e. 4.0 or 8.0) then the number should be displayed without the trailing .0. However, if it is not, the fractional part should display. Here's the test class containing three tests... Which test(s) fails and why?
Friday, May 4, 2012
Find the bug - part 3 (Windows edition)
I have come across a strangeness with Java on Windows with regards to file handling, i.e. the following code:
The code works fine on Linux, but on Windows it complains that the "from" file cannot be deleted, when the file is supposed to be moved using the Google Guava Files.move(File from, File to) method. There is a very subtle thing one has to do to get it to work on Windows. What is it?
Post your answers in the comments and then I will let you know after a while :)
