Tudor Barbu's blog

Ramblings about software development

10 Dec

NERD_Tree & Ack

Posted by Tudor. Tags: , ,

I started using ack some time ago and I can say it’s much better than grep. Faster, more intuitive, much, much faster :) And I wanted to integrated with my vim environment. I use NERD_Tree and I couldn’t find any suitable module that will add ack functionality to it, so I decided to write my own. So, voila, my first vim plugin.

Installation:

Install NERD_Tree first. Then download this module to ~/.vim/plugin/ or the appropriate location on your system and…you’re done.

Install ack (see details at betterthangrep.com ). Depending on your operating system, you need to type something like “sudo apt-get install ack-grep“, “brew install ack” or other. Most of the installers will add ack to your $PATH, so NERD_Tree_Ack.vim won’t require additional configuration. If you’re weird and don’t want to add ack to your $PATH, just add the following line to your .vimrc file:

let g:path_to_search_app = "/full/path/to/ack"

Using it

Open NERD_Tree and point it to your project folder, by typing :NERDtree /path/to/project or by using bookmarks. Place the cursor on a folder and type the letter m. In the menu that will pop up you will have the option “(s)earch directory”. Select it by pressing s and type your pattern. If your search will yield results, you will see a window in the lower part of your screen, with all the results. Navigate with the keys and press to jump to a result. The file will be opened in the last working window.

Don’t forget to rate it if you like it :)

13 Jul

Limit a script’s execution time

Posted by Tudor. Tags: ,

Sometimes you might want to limit a script’s maximum execution time, so that if it’s not done in X seconds, you’ll discard any results you’ve got so far and move on. And if you’re lazy and don’t want to implement threading and semaphores and so on, or you just need a quick way to achieve this limitation and you’re okay with killing the script after a certain number of seconds – note that you will lose any unsaved data when you kill the program – then this Perl one liner might just do the trick for you:

perl -e '$s = shift; $SIG{ALRM} = sub { print STDERR "Timeout!\n"; kill INT => $p }; exec(@ARGV) unless $p = fork; alarm $s; waitpid $p, 0' {max. execution time in seconds} {/path/to/script}

Don’t try to read it…just go with it ;) It works and that all that matters.

08 Feb

Perl vs PHP

Posted by Tudor. Tags: , , , ,

I’ve read this article that debates the differences between perl and PHP in a childish way – sort of like the kindergarten debates on whether Batman can kick Spiderman’s ass. Since I haven’t ever coded a single line in perl, I can prove to the world that I’m a mature person that doesn’t plunge into “my operator in better than yours” debates, because if I would have any perl experience, I would be right there in the middle of it ;) .

They may be right on some of the statements they make, but when they claim that a career in perl in better than one in PHP they’re wrong. Dead wrong. PHP has a bright future ahead it whereas PERL does not. Because, in the end, arguments such as “perl has better naming conventions” don’t matter. In a world where nearly all programmers have access to speedy O2 broadband packages or other reliable internet connections, both systems can be (and usually are) widely in use on a number of hugely popular sites. Decisions on what technologies should be used, especially on large projects where loads of money are involved, aren’t taken by geeks in dark rooms over a game of AD&D, but by CEOs over a game of golf or in really expensive restaurants.

If you go on Zend‘s website, you find things like improve productivity, maximize IT investments. This is music to a manager’s ears. CEOs like pie charts more than they like pie. If you go on perl’s website, what do you see? Well, perl 5, perl 6, CPAN ratings, Annotated CPAN, mailing lists. Why do you think that there are so many products being developed on Microsoft technologies? Do you think C# in better than perl or PHP? Or that ASP (not ASP.NET, the original ASP) was better? No, this is just Microsoft’s image at work.

PHP is quite big on its own, but compared to perl, it’s huge. PHP in on Oracle’s site. PHP is on Adobe’s site. Wikipedia is built on PHP, WordPress is built in PHP and the examples go on and on. Perl is not even in the debate, it’s seen as an esoteric language used by CLI geeks. I doubt (I haven’t checked so feel free to prove me wrong) that there is a single project with a budget over 200.000 euros being developed on perl.

These factors aren’t exactly “programming related”, so why are they so important in the day by day life of the average programmer? Well, they create jobs, pay money, give you the ability to pay the rent, buy a car, go on vacation and so on. If you come across a career decision between perl and PHP, don’t waste time wandering if perl’s naming standard is better than php’s or which language has less string comparison functions. But instead ask yourself, which technology will allow you to find a better job? Look on a local jobbing site and see how many PHP are available and compare that number to the number of perl jobs available – if any.

…just my 2 cents.