Bug Vanquisher

16 September 2009

When Oracle Met A Computer Architect

Filed under: Bugz, Dev inside!, Tips — Tanveer Badar @ 7:49 PM

Oracle can’t handle more than 1000 expressions in a single in clause. (Really stupid restriction, I know and here’s the tip: you can do (, ,,,,,) or abc in (,,,,,,) ad infinitum).

When compilers software pipeline a loop, they calculate two things at first. The remainder and the dividend.

(This post got too keyword heavy. Matrix fans will curse me that its the other Oracle. That Oracle’s users will not find all ORA-xyz error descriptions here. Architects may not have any interest in writing computer code. Computer architects will not see any processors discussed. One post to rule them all. ]:) )

The problem at hand was hand generating a query with in clause in its where section. Number of expressions was unbounded. And the genius who came up with the loop did this:

for( int i = 0 , n = 0 ; i < count ; ++i )
{
    n++;
    if( n == 1000 )
    {
        quwry += " ) or in ( ";
        n = 0;
    }
    query += list [ i ] + ‘,’;
}
query = query.Remove( query.Length – 1 , 1 );

Remember this is the work of someone who has never heard about software pipeline and may never know what gcc or cl are. Thinking one level above will help us arrive at the correct solution (notice, there is nothing wrong functionally with the above code either. It does what it says it does.):

int n = numbers.Count / stride , k = numbers.Count % stride;
StringBuilder builder = new StringBuilder( );
if( n > 0 )
{
    builder.AppendFormat( "’{0}’" , numbers [ 0 ] );
    for( int j = 1 ; j < stride ; j++ )
        builder.AppendFormat( " , ‘{0}’ " , numbers [ j ] );
    for( int i = 1 ; i < n ; ++i )
    {
        builder.Append( separator );
        builder.AppendFormat( "’{0}’" , numbers [ i * stride ] );
        for( int j = i * stride + 1 ; j < ( i + 1 ) * stride ; j++ )
            builder.AppendFormat( " , ‘{0}’ " , numbers [ j ] );
    }
}
if( k > 0 )
{
    if( n > 0 )
        builder.Append( separator );
    builder.AppendFormat( "’{0}’" , numbers [ n * stride ] );
    for( int j = n * stride + 1 ; j < numbers.Count ; ++j )
        builder.AppendFormat( " , ‘{0}’ " , numbers [ j ] );
}

No repetitive checking of one variable which also displays off-by-1 error. And which is also mission the other correction in first line of this post in bold.

13 September 2009

is This Beautiful?

Filed under: Dev inside!, Rant vs Vent — Tanveer Badar @ 10:01 PM

CodeTypeDeclaration tablerow = new CodeTypeDeclaration
{
    IsClass = true ,
    Name = ( row [ "TABLE_NAME" ] + "Row" ) ,
    IsPartial = true ,
    BaseTypes = { datarowref } ,
    Members =
    {
        new CodeMemberField( ( row [ "TABLE_NAME" ].ToString( ) + "DataTable" ) , "table" + row [ "TABLE_NAME" ] ),
        new CodeConstructor
        {
            Attributes = MemberAttributes.Public ,
            Parameters = { parameter } ,
            BaseConstructorArgs = { buildervar } ,
            Statements =
            {
                new CodeAssignStatement( new CodeFieldReferenceExpression( thisref , "table" + row [ "TABLE_NAME" ] ) , new CodeCastExpression( row [ "TABLE_NAME" ].ToString( ) + "DataTable" , tablefield ) )
            }
        }
    }
};

To some, it may be but for me it is nauseating. What happened to all those .Add and .Insert calls?

CodeDom Fun

Filed under: Dev inside! — Tanveer Badar @ 5:52 PM

Writing CodeDom statements by hand is no fun. Visual studio team members who wrote the code to generate data sets must be the finest. For example, guess what would be the output of this statement:

constructor.Statements.Add( new CodeAssignStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression( ) , "table" + row [ "TABLE_NAME" ] ) , new CodeCastExpression( row [ "TABLE_NAME" ].ToString( ) + "DataTable" , new CodeFieldReferenceExpression( new CodeThisReferenceExpression( ) , "Table" ) ) ) );

Just something like

this.tableDT = ( DTDataTable ) (this.Table );

Side note:

I am back!

1 June 2009

Silver Jubilee Week

Filed under: Personal — Tanveer Badar @ 11:58 AM

Its Silver Jubilee Week people. Get ready!!!

19 May 2009

Destroy

Filed under: Rant vs Vent — Tanveer Badar @ 10:50 PM

Destroy pakistan, save a child.
World relief foundation

24 April 2009

Tales From Interviewer’s Desk

Filed under: Dev inside!, Fun, Tips — Tanveer Badar @ 8:24 PM

Part 1:

How to reverse a string in-place?

Take 1: (Fresh)

string reverse( string str )
{
    char ch = str [ 0 ];
    foreach( int i = 0 ; i < str.length ; ++i )
        Response.RedirectWrite( str [ str.length - i ] ) + ch.tostring( );
}

Take 2: (Big words, no knowledge)

string reverse( object obj )
{
    string str = TypeCaste.tostring( obj );
    stack< ch > s;
    for( int i = 0 ; i < length ; ++i )
        s.push( str.charat( i ) );
    for( i = 0 ; i < length ; ++i )
        str.insertat( 0 , s.pop( ) );
}

Take 3: (2.5  year experience in C#)

string reverse( object obj )
{
    if( typeof( obj ) == "string" )
    {
        for( int i = 0 ; i < obj.length ; ++I )
        {
            char ch = str [ i ];
            str [ i ] = str [ length - i ];
            str [ length - i ] = ch;
        }
    }
    return obj.tostring( );
}

Take 4: (Fresh)

string reverse( object obj )
{
    if( obj == "string" )
    {
        char ch = str [ 0 ];
        for( int i = 0 ; i < obj.length ; ++I )
            str [ i ] = str [ length - i ];
        str [ str.length ] = ch;
    }
}

12 April 2009

Bilkamism Syndrome :OR: How to Kill a Product

Filed under: Dev inside!, Rant vs Vent, S&G — Tanveer Badar @ 3:31 PM

[Edit: Even the genius couldn't catch sarcasm, well perhaps he's sleepy right now.]

[Edit # 2: Correct two typos.]

Symptoms:

  1. Oracle locks entire table for a single select. And entire database is unavailable while update/delete happen. You must unplug database server from network for create table to succeed.
  2. Create 500 threads in one process to bog down a server, and end up blaming vendor for any resulting slow downs.
  3. Get a degree in Physics and end up working as a manager for a software product. :) Isn’t it simply cute?
  4. This one’s a bit longer so we’ll have to resort to an analogy. Suppose, a cell phone provider allows you to transfer credit to someone else through some crafted command. Now, there are clearly two types of monetary transactions. One when you recharge your own account, one where someone transfers credit to someone else.
    You must have two different tables for these transaction types because “I” doubt Oracle will handle such loads. When generalizing, each transaction type must reside in its own table. This concept is spliheritence.
  5. Requirements. What heavenly entity is that? Why! Just drag up 50 lines of code to get the job done at its face value and everyone is happy.
  6. Edge cases are a Microsoft/Sun/Google conspiracy to kill everyone’s productivity. If it happens in 1 out of 10000000…000 cases, it never happened.
  7. Change requirements mid project and later on deny everything till the exact communication is reproduced. :D
  8. Users are responsible for any race conditions, it is not our duty to insert locks anywhere. Screw you!
  9. Every single class must follow singleton pattern. World ends otherwise and we turn into green Martians.
  10. For bonus fun, copy live customer data to test systems without overwriting actual pins and other personal customer information.
  11. VSS > SVN. Enough said!
  12. Why. Now that is the question. Shakespeare’s “To be or not to be” is ancient.  Question everything, even those which are working perfectly and then blame others for their correct functioning. We understand you must appear doing something to justify your existence in the first place. And NO! The answer is NO.
  13. log ex != x

Keep checking here, I’ll post more as I remember them.

5 April 2009

Enough!

Filed under: Intelligence :( ?? — Tanveer Badar @ 2:45 PM

Facebook is becoming an information disclosure nightmare. People are too stupid to be handed a public social network for their own good. For example, this just crossed my ridiculously crafted homepage few minutes ago.

"Muhammad just added the birthdays of 15 friends to their MyCalendar.
Muhammad has requested to add the following birthdays to their MyCalendar:"

[more blah blah blah with actual dates]“

My comment:

Tanveer Badar at 14:31 on 05 April
[noun], you should know better. It is information disclosure, and about other people’s personal information you have no right to publish in public.
Please don’t add mine to this application.

What amuses me is that the guy is supposed to be specializing in networking, and security by implication (I think). I shudder to think whose data rests in the hands of such and likes.

Those who take time to read this blog might have noticed there is very little information about me here. You won’t find much about me online because I don’t want you to. But how are you supposed to prevent others leaking information about you online.

28 March 2009

Work Efficiency

Filed under: Bugz — Tanveer Badar @ 7:01 PM

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current Dload  Upload   Total   Spent    Left  Speed
109   219  109   219    0     0    438      0 –:–:– –:–:– –:–:—   438

I like this downloader, given how it built redundancy by downloading 109% of a 219 byte long file.

Work Efficiency

Filed under: Bugz — Tanveer Badar @ 6:22 PM

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current Dload  Upload   Total   Spent    Left  Speed
109   219  109   219    0     0    438      0 –:–:– –:–:– –:–:—   438

I like this downloader, given how it built redundancy by downloading 109% of a 219 byte long file.

« Newer PostsOlder Posts »

Blog at WordPress.com.