Wednesday, October 26, 2011

google is weird...

ok I love the autocomplete function in google, but sometimes it just results in to odd of search recommendations...

example:


The fun part is that robin and I were actually researching for smurf costumes (it's bring your smurf to school day on monday...), but that the first suggestion on 'do sm...'

do smurfs have tails

I really did not see that comming

Friday, October 21, 2011

grouping dates in postgres using date_trunc

well recently I started to write some statistics functions for my miniX application and so I was woundering, how can you easily execute queries like:

give me the count of object for the last 24h grouped by hour

which should be rather simple, if you know about the functions 'date_trunc' in postgres.

So 5 minutes later some sql appeared...


"select max(object_count) as object,date_trunc('hour',created_at) as date from bbstatistic_snapshot where object_name = ? and created_at between ? and ? group by date_trunc('hour',created_at) order by date_trunc('hour',created_at)"


which works rather well and get's the job done, but the speed is a touch slow.

Results should look like:


object | date
--------+---------------------
1742 | 2011-10-13 15:00:00
1742 | 2011-10-13 16:00:00
1742 | 2011-10-13 17:00:00
1742 | 2011-10-13 18:00:00
2102 | 2011-10-13 19:00:00
2102 | 2011-10-13 20:00:00
2057 | 2011-10-13 21:00:00
1899 | 2011-10-13 22:00:00
1803 | 2011-10-13 23:00:00
1742 | 2011-10-14 00:00:00
1742 | 2011-10-14 01:00:00
1742 | 2011-10-14 02:00:00
1742 | 2011-10-14 03:00:00
1742 | 2011-10-14 04:00:00
1742 | 2011-10-14 05:00:00
1742 | 2011-10-14 06:00:00

Wednesday, October 19, 2011

reinstalling a compute node in rocks

this is actually a no brainer, but since I barely ever have todo it, here is the procedure:


  1. log onto compute node
  2. execute 
    /boot/kickstart/cluster-kickstart-pxe
  3. wait for the install to finish
that's it

Tuesday, October 11, 2011

cron - useful triggers

just a nice list of commonly used cron triggers I keep forgetting.

Cron Expression to fire the trigger every five minutes:
0 0/5 * * * ?
(e.g. 3:00:00, 3:05:00, 3:10:00

Cron Expression to fire the trigger every hour:
0 0 * * * ?

Cron Expression to fire the trigger every two Hours:
0 0 0/2 * * ?

Cron expression to fire the trigger every Four Hours:
0 0 0/4 * * ?

Cron Expression to fire the trigger every 10 Minutes 20 Seconds:
20 0/10 * * * ?
(e.g. 10:00:20, 10:10:20, 10:20:20)

Every half an hour between 1 AM to 7 AM on 20th of Every Month
0 0/30 1-7 5, 20 * ?
(e.g. 2010-07-20 1:00:00, 2010-07-20 1:30:00m 2010-07-20 2:00:00)

Cron Expression to fire the trigger on the 25th Minute from 1 AM to 5 PM on every Monday and Wednesday
0 25 1-5 ? * MON,WED

Cron Expression to fire the trigger at Noon every day
0 0 12 * * ?

Cron Expression to fire the trigger at Noon every day only in 2010
0 0 12 * * 2010

Cron Expression to fire the trigger Every 10 minutes between 9 AM to 5 PM (until 5:50) Every Day
0 0/10 9, 17 * * ?

Cron Expression to fire the trigger at 2:30 PM on the last Saturday of every month.
0 30 14 ? * 7L

Cron Expression to fire the trigger at 7:10 AM every Monday, Tuesday, Wednesday, Thursday and Friday
0 10 7 ? * MON-FRI

Cron Expression to fire the trigger at 2:10 PM and at 2:40 PM every Sunday in the month of July.
0 10,40 14 ? 7 SUN


source: cron-expression-to-fire-the-trigger-every-hour

Wednesday, August 10, 2011

groovy - a quick way to copy a list of files to the local directory

don't we love these tasks? We get a list of files to look at and they are in a directory with thousands of other files and now we need to copy them one, by one, by one and there is no clear patter, which could ease the pain of doing so.

But like always there is a simple groovy way todo this in a quicker fashion.


def values = [
1333020,
1332872,
1332428,
1332280,
1331984,
1331836,
1331688,
1331540
]

values.each{def value ->
new File("${value}.xml") << new File("/Users/****/Documents/metadata/${value}.xml").text
}


this does simplify your life once in a while to copy a quick list of text files to a different folder.

Tuesday, August 9, 2011

remote ssh forwarding

for some reason I always forget the syntax to forward a port on my server to my local system to work remotely from home on some of my webapps.

Now to not forget it again, I shall write it down on my blog, so I can just look at it...


ssh -L port:remoteServer:port remoteServer


now this let's me access the 'port' on my 'remoteServer' on my local system and work on the webapp. Now I just have to rewrite all the absolute paths to relative paths, so that I can find my css stylesheets too...

Monday, August 8, 2011

grails + jquery + checkboxes

sometimes forms based on checkboxes can be rather annoying. An example would be that this is the return of a standard html checkbox,

html defined checkboxes:

<g:checkBox name="compare" id="1"/>
<g:checkBox name="compare" id="2"/>
<g:checkBox name="compare" id="3"/>


result of the send parameters to the server:



def compareBins = {
println params
}

out:

compare:[on, on, on]


now this is rather useless, we rather would see the id of the checkbox in the result. So let's call jQuery to the rescue and see how it can save out day!



jQuery(document).ready(function() {
$('input:checkbox').each(
function() {
$(this).click(function() {

if (this.checked) {
var value = $(this).attr('id');
$(this).val(value);
}
});
}
);
});



and promptly we have the following result if all 3 boxes are selected


compare:[1,2,3]


or if 1 and 3 are selected


compare:[1,3]


so we can actually tell, which elements where checked instead of getting just 'on'