cooking, programming and everyday life xrado

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.

Monday, October 04, 2010

fix geany

Is geany corrupting your files?  Since I upgraded Ubuntu to Maverick RC, I had problems saving files over gvfs. I even made me switch to gEdit. But not for long. gEdit have so stupid keyboard shortcut and you can't to anything about it. So I was forced to look for further solution and finally got it on geany sourceforge bug tracker. Enabling use_safe_file_saving in geany settings file (.config/geany/geany.conf ) to "true" fixes the issue. Still don't know if this is a gvfs or geany issue, but at least geany is working again. Geany is still the best programming IDE I came across.

Saturday, October 02, 2010

portfolio re-design

I finally managed to put together new re-design of my online portfolio On the site is virtually nothing new except for the new style, I just made a few substantive changes and prepared the base for the English version (hope soon). This does not mean that I'm doing nothing, but I have many things in work or unfinished, so they can not be published yet. Thanks to Valter C. for his time. I owe you now :P

Saturday, August 28, 2010

xrado goes dual head

:) funny title. Yes I got equiped with two new 24" led monitors. You probably know, that two (or more) monitor increase productivity, but I haven't seen it on my own until recently. So I decided to replace my old 21,5" Samsung LCD. It's much more space to work now, less windows switching and loosing focus. I decide to pay a few bucks more to get LED LCD. They are tinner, lighter and most important, both together consume less power then my previous monitor. It's not a big thing but I have one minus for HD resolution. Monitors just got too wide while losing on their height. I don't like that so much, but as I said it's not a big thing.  ...anyway lately I'm stuck with a lot of work. Hope those two will help me gain some productivity.  

Wednesday, July 14, 2010

php slow log

A few days ago a friend called me, asking me how could he find the slowest PHP scripts on its server? ..and didn't think of anything. Of course there are tools like xdebug, but they are only useful in development. If you have a server with hundred websites and you are trying to find out what it taking the most of your cpu time, you will probably need something like mysql slow query log. 

I remembered that php.ini has auto_prepend_file and auto_append_file setting, and that can help me wrap every php request with the timer. I made two simple scripts that wont add much extra overhead. It works exactly as mysql slow log. You just set up the SLOW_LOG_TIME and SLOW_LOG_FILE destination. All php requests that take more than SLOW_LOG_TIME will be logged. 


auto_prepend_file = "/path_to/before.php"
auto_append_file = "/path_to/after.php"




// Settings
define('SLOW_LOG_TIME', 0.5); // (sec)
define('SLOW_LOG_FILE', '/tmp/php_slow.log');

// Logging
define('SLOW_LOG_END', microtime(TRUE));
if ($time > SLOW_LOG_TIME)
	$log = date('Y-m-d H:i:s')."\t".round($time,3)."\t".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']."\n";
	file_put_contents(SLOW_LOG_FILE, $log, FILE_APPEND);
sample output with SLOW_LOG_TIME set to 0.1 sec ( on my home server P4 Celeron 2Ghz, 1Gb Ram )
2010-07-08 23:15:19	0.178
2010-07-08 23:16:32	0.115
2010-07-08 23:16:34	0.13
2010-07-08 23:16:38	0.121

Actually this wont tell you which are the slowest script, but you'll get the list of PHP requests that take the most processing time. That will give you the clue where to start looking.

Final notes:

  • do not set SLOW_LOG_TIME too low, otherwise your log will be screaming, your server too, depending on number of requests you get
  • check syntax in before.php and after.php, any error can break all your sites
  • remove auto_prepend_file and auto_append_file whey you are done, otherwise logs can go big and you don't need extra disk load

It will be nice to see your timings before and after the optimization.

pages:  1   2