Friday 31 July 2015

GNU Find does not return results in order

for example, I had: find $CURRENT_BACKUP_DIR -name $1_*.gz | tail -n+8 | xargs -n1 rm to keep the last 7 days backup only.

However, it did not work, as find does not return the results in order.

For me, using sort fixed the problem: find $CURRENT_BACKUP_DIR -name $1_*.gz | sort | tail -n+8 | xargs -n1 rm

Friday 24 January 2014

css :nth-child pseudo class

example

<div id="holder">
<h2>Heading</h2>
<div class="item">This is even</div>
<div class="item">This is odd</div>
</div>
.item:nth-child(even) {
   background-color:yellow;
}
result

Heading

this is even
this is odd
why?
:nth-child relates to all children of the parent element, not just those with class ".item", so this is saying every ".item" that is an even child of it's parent.
If you're using class selectors, easiest solution is to create a wrapper for the elements that you're targeting, as nth-of-type only works with elements selectors.

Monday 3 October 2011

Functional Fun with Python

Built in currying:

>>> from functools import  partial 
>>> binary = partial (int, base=2)
>>> binary('000001')
1
>>> binary('000011')
3
>>> binary('001011')
11

Wednesday 2 June 2010

The state information is invalid for this page and might be corrupted

This is a nice gotcha for load balanced ASP.NET sites:
If you have a dynamically compiled ASP.NET website, and you put objects from a dynamic part into the ViewState, you'll be in for a NASTY surprise when you move to a load-balanced scenario.
Basically, you'll occasionally get exceptions with the message "The state information is invalid for this page and might be corrupted" as the compiled types on the different servers are different.
Either:
  • Move the types you put into ViewState into a compiled assembly (dll for old-schoolers ), or,
  • Only use primitive types (int, byte, string, char, etc) in the ViewState. Enums do not count as primitive types.

Friday 15 January 2010

Another reason to use log4net rather than rolling your own logging framework

Exception during StringFormat: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Served {0} coupons out of {1} for {3}{296366, 100, Campaign{id#891e4cb2-da21-456b-bb5e-38cfbf9a90db}}

Wednesday 16 December 2009

Google Visualisations API

I set up an example of using the Google Visualisations API at
http://swampstaging.co.uk/uk_singles_chart.html

The process for generating this was:
Scrape code from website (ruby+hpricot)
Process code for google's datatable (ruby)

It was a neat way to learn stuff about ruby. programming without a modern IDE is a PITA. i'd forgotten how great resharper+visual studio is. mostly resharper.

Monday 5 October 2009

jQuery code to cycle background colors


<script type="text/javascript">
//<![CDATA[
$(function() {
$body = $(document.body);
var colours = ["#007777", "#777700", "#777777", "#770077"];
var currentColour = 0;
var fade = function() {
$body.animate({ backgroundColor: colours[currentColour % colours.length]}, 127000, fade);
currentColour++;
};
fade();
});
//]]>
<script>