The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Database without the database

Last post 11-18-2008 4:48 PM by HypocriteWorld. 16 replies.
Page 1 of 1 (17 items)
Sort Posts: Previous Next
  • 11-10-2008 2:14 PM

    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 :(

  • 11-10-2008 3:12 PM In reply to

    Re: Database without the database

    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.

  • 11-10-2008 4:38 PM In reply to

    Re: Database without the database

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

  • 11-10-2008 4:39 PM In reply to

    Re: Database without the database

    Welbog:

    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.
  • 11-10-2008 4:51 PM In reply to

    Re: Database without the database

    DaveK:
    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.

  • 11-10-2008 4:58 PM In reply to

    Re: Database without the database

    Welbog:

    DaveK:
    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:
    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 :)
  • 11-10-2008 4:59 PM In reply to

    Re: Database without the database

     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.

  • 11-10-2008 5:26 PM In reply to

    Re: Database without the database

    PSWorx:

     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
    When sucking up to IT gets even dumber than usual:
    <DriveThruGuy> Welcome to Wendy's. May I take your order?
    <MyStupidBoss> I can haz cheezburger?
  • 11-10-2008 6:04 PM In reply to

    Re: Database without the database

    Wolftaur:

    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...
  • 11-10-2008 8:50 PM In reply to

    Re: Database without the database

    DaveK:
    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.

    When sucking up to IT gets even dumber than usual:
    <DriveThruGuy> Welcome to Wendy's. May I take your order?
    <MyStupidBoss> I can haz cheezburger?
  • 11-11-2008 7:54 AM In reply to

    • Ren
    • Top 500 Contributor
    • Joined on 07-04-2008
    • Posts 53

    Re: Database without the database

    spacecadet:
      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.

  • 11-11-2008 9:40 AM In reply to

    Re: Database without the database

    Wolftaur:
    DaveK:
    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?

  • 11-11-2008 10:25 AM In reply to

    Re: Database without the database

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

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

    Edge cases suck.

  • 11-11-2008 10:33 AM In reply to

    Re: Database without the database

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

  • 11-12-2008 1:48 PM In reply to

    Re: Database without the database

     

    gms8994:

     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.

    ((lambda (f) (f f)) (lambda (f) (f f)))
  • 11-12-2008 2:32 PM In reply to

    • dtech
    • Top 50 Contributor
    • Joined on 11-13-2007
    • Utrecht, Netherlands
    • Posts 424

    Re: Database without the database

    HypocriteWorld:

    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

  • 11-18-2008 4:48 PM In reply to

    Re: Database without the database

    dtech:

    HypocriteWorld:

    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.

    ((lambda (f) (f f)) (lambda (f) (f f)))
Page 1 of 1 (17 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems