Coffeehouse Thread

9 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Brilliant Code! Got Some?

Back to Forum: Coffeehouse
  • User profile image
    jsampsonPC

    "Billiant" is sarcastic - the code here is less-than-brilliant...far less than brilliant.



    I wrote the following up as a joke to a friend. Curious if you .NET guys have ever written your own jokes?

    The following code prints a link for each day of the current month: Day 1, Day 2, etc. The links direct you to another page that can do something with the query string...Enjoy.

    (Oh, and yes, this IS a joke - so no flaming Wink)

    <?php

        getDays();

        function getDays() {
            $day = array("1","2","3","4","5","6","7","8","9","10","11","12","13",
                        "14","15","16","17","18","19","20","21","22","23","24",
                        "25","26","27","28","29","30","31");
            $trueDays = array();
            $arrayLinks = array();
      
            for($i = 0; $i < count($day); $i++) {
                if ($i < date("t") && $i > 0) {
                    if (is_numeric($i)) {
                        $trueDays[] = ($day[$i] > 0) ? $day[$i] : 0 ;
                    }
                }
            }
            if (is_array($trueDays) && 1 == 1) {
                $dayString = implode(",",$trueDays);
            }
            if (strlen($dayString) > 0) {
                foreach ($trueDays as $day) {
                    $arrayLinks[] = "<a href='getDays.php?day={$day}'>Day {$day}</a>";
                }
            }
      
            print "<a href='getDays.php?day=1'>Day 1</a>, " . implode(", ",$arrayLinks);   
        }

    ?>

  • User profile image
    W3bbo

    I executed the PHP... it's just a list of days, clicking on a link doesn't actually do anything other than reload the page.

    This is under PHP5 though. Does your script make use of any PHP4-specific behaviour?

  • User profile image
    jsampsonPC

    W3bbo said:
    I executed the PHP... it's just a list of days, clicking on a link doesn't actually do anything other than reload the page.

    This is under PHP5 though. Does your script make use of any PHP4-specific behaviour?
    It's not suppose to do anything other than list days. Something that could have been done like this:

    $list = "";
    for ($i = 0; $i < date('t"); $i++) {
      $list .= "<a href='pointlessCode.php?day={$i}' title='Day {$i}'>Day {$i}</a>, ";
    }
    print $list;

    As for any PHP4-Specific behaviour, not sure. I think all of the code is ambiguous. No PHP OO activity or anything. No usage of $_SESSION...I think  it's all cross-compat with 4 and 5 Wink

    Somebody actually wanted a solution over at DevShed. They wanted links for days 1 - n of the current month. This was a joke-solution (although a functional one) for their problem. I thought it was funny Tongue Out

    I was mostly curious if anybody here had every done anything similar as a joke.

  • User profile image
    jsampsonPC

    Just found this one online:

    #include <stdio.h>

    typedef struct {
        int ch;
        int count;
    } star_t;

    int main(void) {
        star_t foo[] = {
    {46, 22}, {47, 1}, {194, 1}, {180, 1}, {194, 1}, {175, 1}, {47, 1}, {41, 1}, {'\n', 1},
    {46, 20}, {44, 1}, {47, 1}, {194, 1}, {175, 1}, {46, 2}, {47, 1}, {'\n', 1},
    {46, 19}, {47, 1}, {46, 4}, {47, 1}, {'\n', 1},
    {46, 13}, {47, 1}, {194, 1}, {180, 1}, {194, 1}, {175, 1}, {47, 1}, {39, 1}, {46, 3}, {39, 1}, {47, 1}, {194, 1}, {180, 1}, {194, 1}, {175, 1}, {194, 1}, {175, 1}, {96, 1}, {194, 1}, {183, 1}, {194, 1}, {184, 1}, {'\n', 1},
    {46, 10}, {47, 1}, {39, 1}, {47, 1}, {46, 3}, {47, 1}, {46, 4}, {47, 1}, {46, 7}, {47, 1}, {194, 1}, {168, 1}, {194, 1}, {175, 1}, {92, 1}, {'\n', 1},
    {46, 8}, {40, 1}, {39, 1}, {40, 1}, {46, 3}, {194, 1}, {180, 1}, {46, 3}, {194, 1}, {180, 1}, {46, 4}, {32, 1}, {194, 1}, {175, 1}, {126, 1}, {47, 1}, {39, 1}, {46, 3}, {39, 1}, {41, 1}, {'\n', 1},
    {46, 9}, {92, 1}, {46, 17}, {39, 1}, {46, 5}, {47, 1}, {'\n', 1},
    {46, 10}, {39, 2}, {46, 3}, {92, 1}, {46, 10}, {32, 1}, {95, 1}, {46, 1}, {194, 1}, {183, 1}, {194, 1}, {180, 1}, {'\n', 1},
    {46, 12}, {92, 1}, {46, 14}, {40, 1}, {'\n', 1},
    {46, 14}, {92, 1}, {46, 13}, {92, 1}, {46, 1}, {32, 1}, {'\n', 1}
        };
        int i, j;
        for (i = 0; i < sizeof(foo) / sizeof(foo[0]); i++) {
            star_t bar = foo[i];
            for (j = 0; j < bar.count; j++) {
                printf("%c", (char )bar.ch);
            }
        }
        return 0;
    }

  • User profile image
    figuerres

    Well there are some odd SQL tricks I have used one or two times,  you can run a single SQL select with a dynamic text/string and a TSQL function....  if you for example have a table of ID,Name to put into a dropdown you can make SQL build the complete HTML for the dropdown.... I'd have to dig out the code.... but it's kinda sweet how it works.

  • User profile image
    cheong

    I've seen someone asking others to post code for some "hello world" level assignment on a C++ community in C, so someone took time to write a main.c that consist of all kinds of "ooOOo", "oOoo" and "#define" directive that replacing them with meaningful keywords like "void", "main"...

    That's what we called remarkable "OO programming in C"... Tongue Out

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    Bass

    cheong said:
    I've seen someone asking others to post code for some "hello world" level assignment on a C++ community in C, so someone took time to write a main.c that consist of all kinds of "ooOOo", "oOoo" and "#define" directive that replacing them with meaningful keywords like "void", "main"...

    That's what we called remarkable "OO programming in C"... Tongue Out

    /* efdtt.c Author: Charles M. Hannum <root@ihack.net> */
    /* */
    /* Thanks to Phil Carmody <fatphil@asdf.org> for additional tweaks. */
    /* */
    /* DVD-logo shaped version by Alex Bowley <alex@hyperspeed.org> */
    /* */
    /* Usage is: cat title-key scrambled.vob | efdtt >clear.vob */


    #define m(i)(x[i]^s[i+84])<<

    unsigned char x[5] ,y,s[2048];main(
    n){for( read(0,x,5 );read(0,s ,n=2048
    ); write(1 ,s,n) )if(s
    [y=s [13]%8+20] /16%4 ==1 ){int
    i=m( 1)17 ^256 +m(0) 8,k =m(2)
    0,j= m(4) 17^ m(3) 9^k* 2-k%8
    ^8,a =0,c =26;for (s[y] -=16;
    --c;j *=2)a= a*2^i& 1,i=i /2^j&1
    <<24;for(j= 127; ++j<n;c=c>
    y)
    c

    +=y=i^i/8^i>>4^i>>12,
    i=i>>8^y<<17,a^=a>>14,y=a^a*8^a<<6,a=a
    >>8^y<<9,k=s[j],k ="7Wo~'G_\216"[k
    &7]+2^"cr3sfw6v;*k+>/n."[k>>4]*2^k*257/
    8,s[j]=k^(k&k*2&34)*6^c+~y
    ;}}

  • User profile image
    Ion Todirel

    Bass said:
    cheong said:
    *snip*

    /* efdtt.c Author: Charles M. Hannum <root@ihack.net> */
    /* */
    /* Thanks to Phil Carmody <fatphil@asdf.org> for additional tweaks. */
    /* */
    /* DVD-logo shaped version by Alex Bowley <alex@hyperspeed.org> */
    /* */
    /* Usage is: cat title-key scrambled.vob | efdtt >clear.vob */


    #define m(i)(x[i]^s[i+84])<<

    unsigned char x[5] ,y,s[2048];main(
    n){for( read(0,x,5 );read(0,s ,n=2048
    ); write(1 ,s,n) )if(s
    [y=s [13]%8+20] /16%4 ==1 ){int
    i=m( 1)17 ^256 +m(0) 8,k =m(2)
    0,j= m(4) 17^ m(3) 9^k* 2-k%8
    ^8,a =0,c =26;for (s[y] -=16;
    --c;j *=2)a= a*2^i& 1,i=i /2^j&1
    <<24;for(j= 127; ++j<n;c=c>
    y)
    c

    +=y=i^i/8^i>>4^i>>12,
    i=i>>8^y<<17,a^=a>>14,y=a^a*8^a<<6,a=a
    >>8^y<<9,k=s[j],k ="7Wo~'G_\216"[k
    &7]+2^"cr3sfw6v;*k+>/n."[k>>4]*2^k*257/
    8,s[j]=k^(k&k*2&34)*6^c+~y
    ;}}
    wow lol that's crazy Smiley lol again

  • User profile image
    Bas

    Bass said:
    cheong said:
    *snip*

    /* efdtt.c Author: Charles M. Hannum <root@ihack.net> */
    /* */
    /* Thanks to Phil Carmody <fatphil@asdf.org> for additional tweaks. */
    /* */
    /* DVD-logo shaped version by Alex Bowley <alex@hyperspeed.org> */
    /* */
    /* Usage is: cat title-key scrambled.vob | efdtt >clear.vob */


    #define m(i)(x[i]^s[i+84])<<

    unsigned char x[5] ,y,s[2048];main(
    n){for( read(0,x,5 );read(0,s ,n=2048
    ); write(1 ,s,n) )if(s
    [y=s [13]%8+20] /16%4 ==1 ){int
    i=m( 1)17 ^256 +m(0) 8,k =m(2)
    0,j= m(4) 17^ m(3) 9^k* 2-k%8
    ^8,a =0,c =26;for (s[y] -=16;
    --c;j *=2)a= a*2^i& 1,i=i /2^j&1
    <<24;for(j= 127; ++j<n;c=c>
    y)
    c

    +=y=i^i/8^i>>4^i>>12,
    i=i>>8^y<<17,a^=a>>14,y=a^a*8^a<<6,a=a
    >>8^y<<9,k=s[j],k ="7Wo~'G_\216"[k
    &7]+2^"cr3sfw6v;*k+>/n."[k>>4]*2^k*257/
    8,s[j]=k^(k&k*2&34)*6^c+~y
    ;}}
    That's awesome. Big Smile

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.