Work Journal 2013-jan-17

Today I am going to implement a few more features so the solution is ready for testing by the customer. Friday I hope to do some testing and even setup a bit of automated acceptance testing maybe.


Today from the interwebs: Funny little thing that plays “against” robots.txt: humans.txt files.


Some things I used to solve some specific problem

Rounding in javascript

Rounding in javascript is funny. If you just need a number as a string with a defined number of digits you can use .toFixed(). In pretty much any other case you should probably do something else like Math.round(original*100)/100 (for two decimal rounding.). Here is a bit more discussion on the topic.

Positioning a jQueryUI datepicker in relation to its textbox

By default the datepicker pop up with the left side of the caledar aligned with left side of the textbox. I needed the datepicker moved more to the left. Overriding the default jQueryUI css in my own css fixed that:

.ui-datepicker { 
  margin-left: -60px;
}

The idea come from this stackoverflow answer


Position html element in the bottom

{
    bottom: 0;
}

That’s it. Nothing more to see here. Move along.

Redirect to mobile site

Redirecting to a mobile site seems to be a problem than cannot really be solved in any obvious and/or good way. Sniffing the user agent string, just seems wrong to me. I decided to redirect based on the screen width on the client or rather the available screen width. Well, that’s not perfect, but good enough for this solution.

I ended up with a index.html with the only responsibility of redirecting either to the mobile or “normal” version of the site. It looks like this:

<!DOCTYPE html>
<html lang="da">
<head>
    <title>Bredb&aring;ndskortet - Erhvervsstyrelsen</title>
    <script type="text/javascript">
        var mobilesiteLocation = "./m.bredbaandskortet.html";
        var mainsiteLocation = "./bredbaandskortet.html";
        if (screen.availWidth <= 1050 && screen.availWidth <= 1050) { 
			document.location = mobilesiteLocation; 
			} else { 
			document.location = mainsiteLocation; }
    </script>
</head>
<body>
</body>
</html>

Mozilla Developer Network has a nice writeup on some advantages and disadvantages of agent sniffing https://developer.mozilla.org/en-US/docs/Web_Development/Mobile/Separate_sites Please let me know if you know a good solution to redirection to a mobile version of a site…


Today I also listened to the From Python Import podcast and really got excited about python Koans. Will have a look at that.


Work Journal – a diary on what I did work/programming related today.