Saturday, May 8, 2010

Snail mail spam - enough is enough!

Posted by Picasa


Really!


This isn't mine, mine's larger :P But can't hold much more.

That reminds me the need to request or make no-spam label for mine. Again. Relying on opt-out list only doesn't seem to work.

Friday, February 6, 2009

Counting lines in your files

Recently, a friend of mine wanted show everyone the size of various websites on servers he admins.


So he tried...

But the numbers started to come out a bit funny.

First 336M, then 123M.
That's size of PHP source code.

No way, the sites are too small for that, and... wait, 123M of PHP code? Show me such code tree :P
For example, 500 A4 pages full of text is under 2M (plaintext). So that's 336 * 250 = 84000 pages.
So, in this case, the 123M is highly doubtful.

That came from:
du -h --max-depth=1 --exclude=*\.svn

It turned out that it isn't really only a PHP code. There was also something else. And after all, it's better to include things we want to count, not exclude things we don't want (amd pray that exclude list is complete).

Then he got count of lines like 131407 and 316800 and asked if the following command line is ok:

export total=0; for c in `find . -name '*.php' | xargs wc -l | grep -Ev "total$" | awk '{ print $1 }'`; do total=$( echo "$total + $c" | bc); echo $total; done

Well, I thought that it might even work (like you might be able turn screw with pliers), but there are surely better ways.

So I went to FreeBSD shell (csh) and after testing a while (I'm bit rusty on that - it turned out that two or three years away from daily coding and fiddling with FreeBSD makes you forget a lot), I came out with that:

find . -name '*.php' | xargs wc -l

Or, if you have very large number of files and you need to execute wc more than one time, you need:

echo `find . -name '*.php' | xargs wc -l | grep 'total$' | awk '{print $1}'` | sed 's| |+|g' | bc

FreeBSD's xargs defaults to 5000 arguments per command. You can increase that, but eventually the argument list gets too long and you get error. So keep it reasonably small.

Friend was suprised that this code gives exactly same result as his one. You see, it IS possible to turn screws with pliers, but it's better to have a screwdriver. So you can work properly and don't ruin you job.

I'm pretty obsessive about source code quality and large command line (or shell script) is pretty much same thing. I recenty found a some article that's actually about Perl, but has one very good quote in it:

"some developers have adopted the style of writing their code as compact and "elegantly" as they can. The results can sometimes be programs that look more like dialup line noise than supportable code."

Well, it might be harder to write "dialup line noise" (@%/,$) in, for example, C, but it's surely possible to write unreadable code there too. And when code is unreadable, it can be insecure too. So shame on you, programmer, if you write code like that!

No really, is it so hard to add more whitespace? Put "{" and "}" on individual lines? Using meaningful function and variable names. Even file names... Add comments if/where you can.


Damn... This started as tip about shell and ended with coding styles.

Anyway, friend got finally some sane byte counts too (with wc -c): 4.2M and 11M.

Saturday, December 6, 2008

Portable nuclear power plant for construction sites

Posted by Picasa


No, really, what on earth do they hide there? :)

Thursday, November 20, 2008

My IPTV traffic

I have IPTV from Elion.

Here are it's statistics:
Posted by Picasa


Quite impressive traffic, almost-almost 1TB.
The funny thing is, that it's based on multicast, so the upstream is so small (40MB).

Thursday, August 28, 2008

Total length of videos on the internet

Recently I became very curious about how much video material there are publicly available on the internet.

So, I took few numbers out of Google Video search.
After adding up all those minutes, it became obvious that I may not live long enough to watch all of them :P
In fact, it will take much-much longer...

So here are calculations:

113000000 * 3.59 minutes = 771.310869 years
75300000 * 4 minutes = 572.679355 years
9990000 * 21 minutes = 398.879156 years

771.310869 years + 572.679355 years + 398.879156 years = 1742.86938 years


So the final answer is that there are currently at least 1742 years of video available to watch.
And that's always counting.


BTW, if we're talking about increasing numbers, Gmail is 7074 MB now.

Sunday, August 3, 2008

Finding and pinging default gateway in FreeBSD

For IPv4:
netstat -nr -f inet | grep ^default | awk '{print $2}' | xargs ping

For IPv6:
netstat -nr -f inet6 | grep ^default | awk '{print $2}' | xargs ping6

Little hedgehog

Posted by Picasa