rulururu

post PCMan - A FileManager having Tabs

June 18th, 2008

Filed under: Linux, Software — Kai @ 3:40 pm

One of the greatest mysteries to me is why most file managers don’t have tabs - it makes performing tasks so much simpler.
I’ve found a lightweight file manager for Debian called PCMan that gives you most of the functionality from Nautilus, but also has tabs. To install this file manager, you can either use the built-in Add/Remove applications dialog or use the command line.

Install it with apt-get:

apt-get pcmanfm

Once it’s installed, you can find it under System Tools \ PCMan File Manager.

PCMan

The current version is 0.3.5.10, which was released on February 14th 2008.
Its web reference is pcmanfm.sourceforge.net, which indeed looks a bit weird.

post Comma Operator

June 17th, 2008

Filed under: C++ — Kai @ 10:23 am

A colleague of mine reported an error in the program flow. The line that was wrong looked like this (variable and class names are modified):

if(pCurrent->m_Array[r]->Match(((CMyClass*)this)->m_ptrAttr[i])), (CMyClass*)this)

We soon noticed that the number of braces in that statement is wrong. The ) before the comma closes the statement wrongly. Just a mistake you make when writing statement without paying attention.

Fix simply looked like this:

if(pCurrent->m_Array[r]->Match(((CMyClass*)this)->m_ptrAttr[i]), (CMyClass*)this)

The strange thing about it is that the compiler didn’t even throw a warning that we used a comma in that if statement. The comma operator seemed to be valid usage in C++ if statements.

I quickly looked it up and found out that the binary comma operator is almost only ever used for its side effects, as all it does is to ignore the value on its left and return the value on its right so.

that means

if( 0 , 1 )

always returns true because just the right side is considered.

I at first thought “Huh - that’s useless, what nonsense!” - but then I kept on reading what’s its second usage:

Its common usages is to sneak extra initialisation into a for’s loop init-expr e.g.:-

for ( i=0, j=0; ...

init-expr is an example of an expression whose value is not used, its only the side effect (initialisation) that matters.

Although this is definitely worse coding style you can use commas for the side effect if you want to. ;)

post Pipe Viewer

June 16th, 2008

Filed under: Linux, Software — Kai @ 8:12 pm

Today I found a really nice program for long-running console commands: pv, aka “Pipe Viewer“.
If you’ve ever strung together a long command with pipes, run it, questioned why it’s taking so long, maybe open another terminal to run top… pv is the answer to that question.

It’s very similar to tee, except instead of sending a copy of the data to a file, it displays one or more progress meters on the screen so you can see the flow of data through your piped commands.

It can be easily installed via apt or downloaded on the official website as RPM.

The usage is very simple. If you like to compress a file and show the progress visually you can do it this way:

pv big.iso | gzip > big.iso.gz
50.3MB 0:00:05 [11.6MB/s] [=====>                ] 33% ETA 0:00:09

In the manual you can find some more, also very complex examples such as this more complicated example using numeric output to feed into the dialog program for a full-screen progress display:

pv file | nc -w 1 somewhere.com 3000
(tar cf - . \
| pv -n -s ‘du -sb . | awk ’{print }’‘ \
| gzip -9 > out.tgz) 2>&1 \
| dialog --gauge ’Progress’ 7 70

You should mention that the program is aborted if a numeric option, such as -L, has a non-numeric value.

post Yahoo Google become Partner for Advertising Deal

June 13th, 2008

Filed under: Uncategorized — Kai @ 8:10 am

It’s going into the next round - war of position in the world wide web.
The actors are well-known Microsoft, groundbreaking Google and the one that’s the reason for the struggle - Yahoo.

Yahoo Inc. is edging closer and closer to completely outsourcing its search advertising to Google Inc. This comes following a test run of the Google ad system, which both companies stated was very positive.

A deal between Yahoo and Google could give Yahoo a lot more leverage in terms of an asking price from Microsoft. The partnership could boost Yahoo’s revenue by $500 million a year.

Currently, the bid from Microsoft stands at $42 billion, but Yahoo believes the company is worth more.

The announcement comes on the same day that Yahoo’s future is once again called into question. Earlier today, activist investor Carl Icahn confirmed his intention to replace Yahoo’s board of directors in an effort to consummate the sale of the company to Microsoft.

Throughout the three dramatic months of resisting against Microsoft’s bid, Yahoo came forward with a series of announcements of new products, partnerships and developer initiatives. Today’s opening of the developer platform, after three weeks of a very limited preview, is the company’s first major announcement since Microsoft pulled its acquisition bid off the table.

Amit Kumar, Yahoo’s director of product management for search, said that SearchMonkey is at the center of the Yahoo Life initiative, where the portal is opening its doors to the developer community to recast itself as the crossroads of the social Web.

“Search engines so far haven’t taken full advantage of the fact that there’s all this structured data,” Kumar told InternetNews.com. “This is the beginning of the next generation of search.”

Finally we can wonder if Google, Yahoo are going to be the next dinosaurs.

Former posts that refer to that topic:

post Send your name to the moon

June 11th, 2008

Filed under: Internet, Nonsense — Kai @ 1:28 am

NASA is inviting people to send their names to the moon on-board their Lunar Reconnaissance Orbiter (LRO), which is due to launch later this year. Go to this page before June 27th 2008, submit your name and you are done.
The database with the names will be placed on a microchip that will be integrated onto the spacecraft.

LRO

As an added bonus, you can get a lovely certificate to show their name will be carried to the moon on a chip on-board the LRO.

I have really no idea what the point of this is. But I think it’s a bit of fun and thought I’d share it. By the way, do not fill out your name if your are worried about they may steal your identity. ;)

post Too circuitous for a Macro?

June 5th, 2008

Filed under: C++, Nonsense — Kai @ 5:43 pm

Let’s imagine you need a make some letter’s uppercase. I would usually use the build in CString function or too make it very simple something like this:

string toupper(const string& str)
{
   string s = str;
   int len = s.length();
 
   for(int i = 0; i < len; i++)
       if( s[i] >= 'a' && s[i] <= 'z' )
           s[i] -= 32;
 
   return s;
}

or if I wanted to stuck more to C-style:

for ( int a = 0; a < strlen ( mystring ); a++ )
   if ( mystring [ a ] >= 'a' && mystring [ a ] <= 'z' )
       mystring [ a ] &= 0xdf;

Some people prefer using macros for short operations.
The advantage of a macro is that it can be type-neutral (this can also be a disadvantage, of course), and it’s inlined directly into the code, so there isn’t any function call overhead. (Note that in C++, it’s possible to get around both of these issues with templated functions and the inline keyword.)

In C++, you should generally avoid macros when possible. You won’t be able to avoid them entirely if you need the ability to paste tokens together, but with templated classes and type inference for templated functions, you shouldn’t need to use macros to create type-neutral code.

Another reason the prevent usage is that debugging a macro is not that comfortable…
Nevertheless a correct macro would be:

#define TO_UPPER(c)  ( ((c)>='a'&&(c)<='z') ? ((c)-'a'+'A') : (c) )

It’s short, readable and particularly reuseable.

Now we come to the piece of code I really wanted to get at. I found it yesterday night in a project I don’t want to embarrass in public (No, I DIDN’T find it at work!):

// Macro to normalize table names
// (all of them will be stored in upper case )
#define TO_UPPER( x )(         \
     ( 'a' == ( x ) ) ? 'A' :        \
     ( 'b' == ( x ) ) ? 'B' :        \
     ( 'c' == ( x ) ) ? 'C' :        \
     ( 'd' == ( x ) ) ? 'D' :        \
     ( 'e' == ( x ) ) ? 'E' :        \
     ( 'f' == ( x ) ) ? 'F' :        \
     ( 'g' == ( x ) ) ? 'G' :        \
     ( 'h' == ( x ) ) ? 'H' :        \
     ( 'i' == ( x ) ) ? 'I' :        \
     ( 'j' == ( x ) ) ? 'J' :        \
     ( 'k' == ( x ) ) ? 'K' :        \
     ( 'l' == ( x ) ) ? 'L' :        \
     ( 'm' == ( x ) ) ? 'M' :        \
     ( 'n' == ( x ) ) ? 'N' :        \
     ( 'o' == ( x ) ) ? 'O' :        \
     ( 'p' == ( x ) ) ? 'P' :        \
     ( 'q' == ( x ) ) ? 'Q' :        \
     ( 'r' == ( x ) ) ? 'R' :        \
     ( 's' == ( x ) ) ? 'S' :        \
     ( 't' == ( x ) ) ? 'T' :        \
     ( 'u' == ( x ) ) ? 'U' :        \
     ( 'v' == ( x ) ) ? 'V' :        \
     ( 'w' == ( x ) ) ? 'W' :        \
     ( 'x' == ( x ) ) ? 'X' :        \
     ( 'y' == ( x ) ) ? 'Y' :        \
     ( 'z' == ( x ) ) ? 'Z' :  ( x ) \
    )

I really didn’t want to deprive this of you. :D

Pretty cool to write this really terrifying macro instead of:

#define TO_UPPER(c) c^0x20

which is indeed the shortest way ;)

ruldrurd
« Previous PageNext Page »
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)