cooking, programming and everyday life xrado

Sunday, August 28, 2011

wmon - web server monitor

wmon or web monitor for Linux servers is tool I made about 3 years ago. The idea was to get a better picture of web server load. That's how it looked back in 2008.

A few lines of PHP and bash commands and chart made with GD library. Turned out to be quite useful. I gave it also to some friends and the totally forgot about it. Then one day a friend mention me, what about wmon, its very cool tool, are you planing any updates. I've been quite happy to hear it and that gave me some momentum to actually push it further.

I've found a nice charting tool dygraphs, that draws canvas charts and also have zooming in some other cool features. Dygraph relay gave mi some good options to add additional features, like top processes and services status changes for any pointed time on chart. I've also added easy way to include external wmon in to one report. Thats how you can monitor all servers from one location.

Turned out pretty good and probably useful for others, so i decide it to sell it on Hopefully it will buy me some beer :). If you are interested you can get it and try it here. Thanks!

Wednesday, October 27, 2010

nkbm bank@net prijava si ne zapomni gesla

Pred kratkim je NKBM prenovila spetno banko in od takrat si prijava ne zapomni več logina. Sigurno je bolj varno vsakič vpisat geslo, a če uporabljaš računalnik samo ti, pride prav če lahko ta korak preskočiš. Žal je nova verzija to onemogočila. Login forma ima sedaj autocomplete=off in zraven tega se še login izvede z ajax klicom. Ker gesla ne vem na pamet in mi je zelo tečno vsakič ga gledat in vpisovat, sem se odločil da naredim JS bookmarklet, ki se bo logiral namesto mene. 

	var runthis = function() {
		new Request({
			url: '', 
			method: 'post', 
			data: { action:'login', user: 'USERNAME', pass: 'PASSWORD' },
			onSuccess: function() {
				location.href = '';

	if(!location.href.match('/')) location.href = '';
	else if (!window.MooTools) {
		var mo = document.createElement('script');
		mo.type = 'text/javascript';
		mo.src = '';
	} else {

Zgoraj je formatirana koda bookmarkleta. Sledi link ki vsebuje to isto kodo, ki ga preprosto primeš in neseš v bookmark vrstico >> bank@net <<. Kar moraš še narediti je da urediš ta bookmark in v linku zamenjaš USERNAME in PASSWORD s svojim. Če se ne nahajaš na nkbm strani je potrebno bookmarklet klikniti dvakrat. Prvič preusmeri na nkbm, drugič logira. Testirano v FF in Chrome. Previdno z gesli...

Če ima kdo kakšno boljšo rešitev ...naj pove.

Thursday, February 18, 2010

Extract emails

I was doing research on possible customers and end up with the long list of names, contacts and emails. While i was thinking about how i'm gonna assemble the mailing, i came a cross the thought i'll have to collect them again and copy / paste each email to compose form. Ehhh. Then i got the idea how to pass this annoying task. A few lines of javascript and regex and i got a script that collects emails, remove duplicates, get them lower case and separated by commas. Perfect!
		var emails = [];
		$('text').get('value').replace(/(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?))|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?)/ig, function(match){
			match = match.toLowerCase();
			if(emails.indexOf(match) != -1) emails.push(match);
		$('text').set('value',emails.join(', '));
DEMO  ...paste the text containing emails and press format button.

Thursday, February 19, 2009

Dynamic select boxes

These days i was working on a project, where i needed dynamically loading select boxes. I first tried mootools native methods like removing and injecting new option elements in to select element. That worked just fine in FF, but as you expect in IE did not. IE's select box stood unchanged. I remember while ago i have to re-inject the whole select box to see the changes in IE.

According to DOM, there is a better way. HTMLSelectElement support add and remove method that work in all major browsers. So i have implemented three basic methods for mootools Element class.
	removeAllOptions: function() {
		if(this.get('tag')!='select') return this;
		for(var i=this.options.length-1;i>=0;i--) this.remove(i);
		return this;

	addOption: function(text,value) {
		if(this.get('tag')!='select') return this;
		var optn = new Element('option');
		if(text) optn.text = text;
		if(value) optn.value = value;
		return this;

	removeOption: function(prop,value){
		if(this.get('tag')!='select') return this;
		for(var i=this.options.length-1;i>=0;i--) {
			if (prop=='selected' && this.options[i].selected) this.remove(i);
			if (prop=='value' && this.options[i].value==value) this.remove(i);
			if (prop=='text' && this.options[i].text==value) this.remove(i);
			if (prop=='index' && i==value) this.remove(i);
		return this;
Methods hopefully already explaining their self.

// remove all options or empty select box

// add options, one after another

// removing options 
happy selecting ;)

Wednesday, January 21, 2009

Simple combining of multiple javascript and css files

I've already wrote about "firefox only includes styles form .css files" and I found out that isn't quite true. Actually firefox doesn't care about the css file extension, but only relay on header Content-Type: text/css. If you as usual have .css file, apache will take care of right content-type, otherwise you will have to take care about it.
header('Content-Type: text/css');
I came across this when i was writing this script:
## combine.php

// Define path prefix
$prefix = realpath('.');

if(!empty($_GET['js'])) {
	header('Content-Type: application/x-javascript');
	$data = Array('path'=>$prefix.'/template/js/','files'=>$_GET['js'],'ext'=>'.js');
} elseif(!empty($_GET['css'])) {
	header('Content-Type: text/css');
	$data = Array('path'=>$prefix.'/template/styles/','files'=>$_GET['css'],'ext'=>'.css');
} else exit();

foreach(explode(',',$data['files']) as $file) {
	if($file && file_exists($data['path'].$file.$data['ext'])) readfile($data['path'].$file.$data['ext']);
Simple few lines of code, but already do the trick. That will minimise number of server requests and benefit in faster page loading.

Defining the path and file extension is important, otherwise you may expose some other scripts source or even worse, some system files.

Usage in page head
<link rel="stylesheet" type="text/css" href="combine.php?css=style,forms" />
<script type="text/javascript" src="combine.php?js=mootools,validate,fx"></script>
Hope you like it, otherwise If you want more advanced solution try minify.

pages:  1   2