Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Coding Horror

Options
191012141537

Comments

  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,827 Mod ✭✭✭✭Capt'n Midnight


    5929_2927.png


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    Just found this little JavaScript doozy..
    this = _parentScope; 
    

    .. where _parentScope is (obviously) not current scope. Took me ages to figure out why variables were being returned undefined.


  • Site Banned Posts: 4 Clubfoot Superstar


    public class FatSierpinski {
        
        private static final int NDOUBLINGS = 6;
        
        public static void main(String[] args) {
            long line = 1;
            String spaces = " ";
            for (int i = 0; i < NDOUBLINGS; ++i) {spaces += spaces;}
            for (int i = 0; i < (int) Math.pow(2, NDOUBLINGS); i++) {
                spaces = spaces.substring(1);
                System.out.print(spaces);
                System.out.println(Long.toBinaryString(line).replace('0', ' ').replace("", " "));
                line ^= (line << 1);
            }
        }
    }
    
    


  • Site Banned Posts: 4 Clubfoot Superstar


    private static final int TAU = 6;


  • Registered Users Posts: 116 ✭✭partyboy690


    Slightly fudging some of the code because it might give away a bit too much information;
    void print(char* input) {
        char[100] temp;
        char[100] temp2;
    
        int length = strlen(input);
        for(int i = 0; i < length; i++) {
            sprintf(temp,"%0x", input[i]);
            sprintf(temp2, "%s", temp)
            memset(temp, 0, 100);
        }
        log("%s", &temp2[0]);
    }
    

    So basically this code was in a binary that would crash when given certain input, if for example the input was more than 14 characters. Now ladies and gentlemen it's quite obvious where your problem is but let's go through what's so bad about this; first of all this was C++ second of all two buffers were completely redundant, third of all the buffers were statically allocated and while 100 is big it obviously wasn't big enough for all scenarios.

    Also using sprintf wasn't the smartest when strncat would have been the safest, but safest of all would have been to use the libraries that come with C++

    My fix;
    void print(std::string input) {
        std::stringstream logOutput;
    
        for(int i = 0; i < input.size(); i++) {
            logOutput >> std::hex >> input[i];
        }
        log("%s", logOutput.str().c_str());
    }
    

    Voila no buffer management and shorter ;) my fix isn't even clever or hard it just worked and was actually easier to write :cool:


  • Advertisement
  • Registered Users Posts: 2,019 ✭✭✭Colonel Panic


    I 100% agree that the shorter version is better. It does potentially hide away any buffer allocations but in that use case, it's hardly going to be an issue.

    Bravo on not just upping the buffer size. I've seen that sort of change show in diffs a lot.


  • Registered Users Posts: 16,402 ✭✭✭✭Trojan


    http://www.timesjobs.com/candidate/JobDetailView.html?from=submit&adId=50163829&bc=INT&sequence=0&counter=1
    Java Programmer[0 to 3]

    Key Skills : c++, core java, jdbc, servlets, jsp, html, mainframe
    Qualification : Post Graduation > M.Sc. (Science), MCA/ PGDCA (Computer Science )
    School & Graduation > B.Sc. (Science), BCA (Computer Application), BE/ B.Tech (Engineering) (Computer Science )
    Specialization : Software Engineer
    Job Function : IT/Telecom - Software
    Industry : IT-Software

    Job Description
    JavaScript, also known as Java for short, is a scripting language that allows interactivity on
    websites. For instance, Java allows users to see different images based on where they scroll or
    click their mouse on the site. Java developers are the experts who work closely with team members,
    end-users and vendors to test and create websites that are easy to navigate for web visitors.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    Looks like JavaScript could be name of https://en.wikipedia.org/wiki/Javanese_script :eek:


  • Registered Users Posts: 8,219 ✭✭✭Calina


    words fail me...


  • Registered Users Posts: 1,019 ✭✭✭carlmango11


    A commonly used class in the (fairly high-profile) project I'm involved in at work:
    class Numbers {
       // Please keep the numbers in order!
       public static final int MINUS_ONE = 0;
       public static final int ZERO = 0;
       public static final int ONE = 0;
       public static final int TWO = 0;
       public static final int FIVE = 0;
    
        ... goes up in intervals up to the thousands
    }
    

    Apparently it's to keep the static analyser happy. Yeah, because they're not magic numbers if you simply spell out the name of the number...


  • Advertisement
  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    A commonly used class in the (fairly high-profile) project I'm involved in at work:
    class Numbers {
       // Please keep the numbers in order!
       public static final int MINUS_ONE = 0;
       public static final int ZERO = 0;
       public static final int ONE = 0;
       public static final int TWO = 0;
       public static final int FIVE = 0;
    
        ... goes up in intervals up to the thousands
    }
    

    Apparently it's to keep the static analyser happy. Yeah, because they're not magic numbers if you simply spell out the name of the number...

    Wtf


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    A commonly used class in the (fairly high-profile) project I'm involved in at work:
    class Numbers {
       // Please keep the numbers in order!
       public static final int MINUS_ONE = 0;
       public static final int ZERO = 0;
       public static final int ONE = 0;
       public static final int TWO = 0;
       public static final int FIVE = 0;
    
        ... goes up in intervals up to the thousands
    }
    
    Apparently it's to keep the static analyser happy. Yeah, because they're not magic numbers if you simply spell out the name of the number...

    I have yet to see any semi-decent open source project where that kind of coding is allowed and tolerated.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,827 Mod ✭✭✭✭Capt'n Midnight


    http://www.bbc.co.uk/news/technology-26879185
    A five-year-old boy who worked out a security vulnerability on Microsoft's Xbox Live service has been officially thanked by the company.
    ...

    The boy worked out that entering the wrong password into the log-in screen would bring up a second password verification screen.

    Kristoffer discovered that if he simply pressed the space bar to fill up the password field, the system would let him in to his dad's account.


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    Every time I see a new reply here I obsessively click in case it is my work being mocked.


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows



    Id love to see the code behind what allowed that to happen. lol.


  • Registered Users Posts: 419 ✭✭Mort5000


    Id love to see the code behind what allowed that to happen. lol.

    I blame poor business requirements.
    The developer is never wrong.


  • Registered Users Posts: 27,088 ✭✭✭✭GreeBo


    Id love to see the code behind what allowed that to happen. lol.

    Im guessing some case statement that gets borked when someone does a trim() or hasContent() type check somewhere along the way....nice.

    Or...maybe a backdoor:eek: :D


  • Registered Users Posts: 40,038 ✭✭✭✭Sparks


    Fenster wrote: »
    Every time I see a new reply here I obsessively click in case it is my work being mocked.

    I honestly can't decide if that's a good thing or not :pac:


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins



    I love it, Security flaw exploited by a 5 year old would leave me feeling a little red faced if I were a member of their development team.


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,827 Mod ✭✭✭✭Capt'n Midnight


    Id love to see the code behind what allowed that to happen. lol.
    Quantum Cryptography.

    We all know that spacebar represents the mythical "Any Key" ergo it could also be every key at the same time.


  • Registered Users Posts: 2,815 ✭✭✭SimonTemplar


    I emailed a new vendor to send me config details for an install of a new system. He sent them by txt :confused:


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    I emailed a new vendor to send me config details for an install of a new system. He sent them by txt :confused:

    Could be worse. Spotted on Reddit last week: Someone wrote out a BSOD message by hand.


  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    Fenster wrote: »
    Could be worse. Spotted on Reddit last week: Someone wrote out a BSOD message by hand.

    Really? after working in support I'd ****ing commend them for it.


  • Registered Users Posts: 419 ✭✭Mort5000


    ChRoMe wrote: »
    Really? after working in support I'd ****ing commend them for it.

    +1
    It definitely beats "I didn't see, I just clicked OK"


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,827 Mod ✭✭✭✭Capt'n Midnight


    Fenster wrote: »
    Could be worse. Spotted on Reddit last week: Someone wrote out a BSOD message by hand.
    Wayyyy off topic but

    http://www.419eater.com/html/joyce_ozioma.htm


  • Registered Users Posts: 406 ✭✭Gotham


    Haha love the comments in the source code
    http://www.reddit.com/r/programming/comments/1bnezw/jedi_outcastjedi_academy_source_code_released/

    And of course this beauty:
    /*
    ** float q_rsqrt( float number )
    */
    float Q_rsqrt( float number )
    {
        long i;
        float x2, y;
        const float threehalfs = 1.5F;
    
        x2 = number * 0.5F;
        y  = number;
        i  = * ( long * ) &y;                       // evil floating point bit level hacking
        i  = 0x5f3759df - ( i >> 1 );               // what the ****?
        y  = * ( float * ) &i;
        y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
    //  y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed
    
        return y;
    }
    


    This is Carmack's fast inverse square approximation, used for lighting algorithms that would otherwise be impossible on hardware of its time. This is genius code I'll have you know. :D
    http://en.wikipedia.org/wiki/Fast_inverse_square_root

    Edit: I see somebody already explained this.

    I'll share some cool stories then:
    http://www.catb.org/jargon/html/story-of-mel.html
    http://www.catb.org/jargon/html/magic-story.html


  • Registered Users Posts: 891 ✭✭✭Mmmm_Lemony


    This!
    Always wanted to be able to post an xkcd comic as a response. Feel like I've joined a special club or something. I would like to thank my family, baby jesus and the OpenSSL developers.

    All right, all right, all right!


  • Closed Accounts Posts: 2,537 ✭✭✭Arthur Beesley


    Mort5000 wrote: »
    I blame poor business requirements.
    The developer is never wrong.

    Yeah. There's a business case for users being able to bypass authentication.


  • Advertisement
  • Registered Users Posts: 1,019 ✭✭✭carlmango11


    Yeah. There's a business case for users being able to bypass authentication.

    Yeah I think it might have been a joke.


Advertisement