Database without the database



  • I'm trying to determine why my terminal is only displaying one column of data.  There's a file named "marketplace_storefronts_client_products_moreinfo.htm". Please note the extension.  There's nothing in Apache config stating that htm should be parsed by PHP. However, within this file is the following:

    $i = $_GET[id];
    $file = fopen('prod',"r");
    $id = 0;
    while (! feof($file)) {
       $string = fgets($file);
       if(preg_match("/$i/", $string)) {
         $arr = explode("\t",$string);
         if($arr[0] == $i) $id = $arr[1];
         if($id > 0) break;
       }
    }
    fclose($file);

    Note now that we're opening a file named 'prod'. This file contains 548 lines like the following:

    3671    266
    1000    224
    1032    96
    1033    100

    This file is used to redirect a browser request to another page.  This file is read and parsed, one line at a time, *every* single time the browser requests the page that redirects here. Or, it would, if it weren't being returned directly to the browser :(



  • It's a hash table implemented as a big string which is parsed by regex to get the key/value pair... I wish I had thought of that; it would have won me the OMGWTF contest.



  •  The creepy thing is that the guy who wrote this probably patted himself on the back and said "boy, am I smart"...



  • @Welbog said:

    It's a hash table implemented as a

    It's not any kind of hash table.  Note the lack of any hashing on the key and the straightforward sequential search.  It's just a bog-standard look-up table.


  • @DaveK said:

    It's not any kind of hash table.  Note the lack of any hashing on the key and the straightforward sequential search.  It's just a bog-standard look-up table.
    You're right. I tend to use incorrectly the term hash table when I mean generic name-value-pair dictionary. I don't know when I started doing it, but thanks for calling me on it.



  • @Welbog said:

    @DaveK said:

    It's not any kind of hash table.  Note the lack of any hashing on the key and the straightforward sequential search.  It's just a bog-standard look-up table.
    You're right. I tend to use incorrectly the term hash table when I mean generic name-value-pair dictionary. I don't know when I started doing it, but thanks for calling me on it.

    Well, if you want to put a positive spin on it, you could always say something like ...

    @Welbog said:

    You're right. I tend to use incorrectly the term hash table when only a complete freakin' idiot would use anything but a hash table for this goddam' trivial generic name-value-pair dictionary.

    There, FTFY :)


  •  This sort of reminds me of an old boss of mine, who I eventually told that I would charge him $5 every time he proposed comma-separated values as a solution.



  • @PSWorx said:

     The creepy thing is that the guy who wrote this probably patted himself on the back and said "boy, am I smart"...

    What's creepy is that you're not far off the mark. Found in Perl code where I work, above a function doing the technique the OP was talking about:

    # This is better than Perl's hashes because it allows multiple values per key

    Added by me, knowing he'd look when source control told him someone modified "his" file:

    # If, by "allow", you mean new values are invisible because they're later in the file


  • @Wolftaur said:

    Added by me, knowing he'd look when source control told him someone modified "his" file:

    # If, by "allow", you mean new values are invisible because they're later in the file
    You're not evil enough!  You should have hand-edited the ,v file (or equivalent) directly in the repository and made it look like he put that there himself!  Then just forgemail a watch notification and sit back and giggle as his brain melts and he starts to wonder if he's coming down with MPD...


  • @DaveK said:

    You're not evil enough!  You should have hand-edited the ,v file (or equivalent) directly in the repository and made it look like he put that there himself!  Then just forgemail a watch notification and sit back and giggle as his brain melts and he starts to wonder if he's coming down with MPD...

    Pfffft. I was trying to be educational and humiliating, not evil. If I wanted to be evil, I'd patch Perl to actually flag some of his common idioms as runtime errors.



  • @spacecadet said:

      This sort of reminds me of an old boss of mine, who I eventually told that I would charge him $5 every time he proposed comma-separated values as a solution.
     

     O.o what's wrong with comma-separated values? You can even parse them in a sql clause directly! Also, /,([^,]+),/ is super efficient because it has a nonvariable character at the end!

     Comma-separated values are the backbone of MUD programming -- at least according to some wizards. You wouldn't believe  what loops you have to jump through before they start thinking in hash tables (LPC has quite efficient hashtable called 'mapping')... I once found from deep within a MUD library an IP logger that actually used comma-separated values to store who had been in from what IP. Before you ask, yes, they logged player => IP and IP => player and yes, searching through it did hang/crash the MUD every now and then. Lovely.



  • @Wolftaur said:

    @DaveK said:
    You're not evil enough!  You should have hand-edited the ,v file (or equivalent) directly in the repository and made it look like he put that there himself!  Then just forgemail a watch notification and sit back and giggle as his brain melts and he starts to wonder if he's coming down with MPD...

    Pfffft. I was trying to be educational and humiliating, not evil.

    Hey, who ever said that has to be an either/or choice?



  • @Ren said:

    Also, /,([^,]+),/ is super efficient because it has a nonvariable character at the end!
    ...

    /,((?:[^,"]+|"(?:[^"]*|\\")*")*),?/

    Edge cases suck.



  •  Unfortunately, we actually have a table column that stores a CSV data :(



  •  @gms8994 said:

     Unfortunately, we actually have a table column that stores a CSV data :(

    How about kinda-Java code embedded in XML which is then embedded into a column of a CSV?

    The kinda-Java code itself also contains XML.



  • @HypocriteWorld said:

    How about kinda-Java code embedded in XML which is then embedded into a column of a CSV?

    The kinda-Java code itself also contains XML.

     

    I don't know... I'd transfer the code through an asynchronous SOAP connection just to be sure it's enterprisey enough



  • @dtech said:

    @HypocriteWorld said:

    How about kinda-Java code embedded in XML which is then embedded into a column of a CSV?

    The kinda-Java code itself also contains XML.

     

    I don't know... I'd transfer the code through an asynchronous SOAP connection just to be sure it's enterprisey enough

     

    I'm  pretty sure that stuff is in there as well... this was just the way we do Soft Coding here.


Log in to reply