Saturday 27 August 2011

Cannot find given config file in Kohana 2.3.4

Yes, I know that line 2.x of Kohana is no longer supported, but I had to change server of some old script. This software was written in Kohana framework (version 2.3.4). In normal situation this should took less than one hour. The domain, FTP and database was ready, so my task was to import data to new database on new server and to put script on it. Easy? Yes, of course. But life is sometims harder than expected.

I don't know why until today why Kohana was returning this strange, misterious error in logs. This error was "Cannot find given config file in core/Kohana.php on 16xx line" (I don't remember exactly number). It was strange for me and I spent about one hour to resolve this issue. The problem was "hooks" parameter in "application/config/config.php" file. It was enabled (TRUE) but in script there were no hooks, not even a directory for it... The solution is to disable this option (set it to FALSE). Please don't ask me why Kohana was not returning this error on old server and stopped work on another one... The strangest think is that Kohana was not helping to resolve this problem at all - misterious error suggested to search problem in config files (check if they are all on new server and sizes are correct).

Wednesday 24 August 2011

Recursive count lines number in large programming projects.

To count lines number from for example all *.java files in directory there is simple solution with "wc" command.

wc -l *.java

If you need to count lines number of large project with subdirectories etc. you can use
combination of "wc" and "find" command:

wc -l `find . -name \*.java -print`

To many arguments for mv / cp.

If you have to copy large number of files from one directory to another from console level (for example trough ssh) and you see message like "Too many arguments to proceed" there are few solutions. The best in my opinion is these using "find" command.

find . -iname "*.EXT" -exec cp {} -l /DST_PATH/ \;
Where EXT is extension of files you want to copy. If you want to copy all files set it to "*" . DST_PATH is destination path where you want to copy files.

You have to call this command from source path, so af first change your current directory to source by "cd" command.

If you want to copy all files from current directory but not from subdirectories here is solution with -maxdepth parameter.

find . -maxdepth 1 -iname "*.EXT" -exec cp {} -l /DST_PATH/ \;

 Good luck :)