The Ghost Cursor

by in Feature Articles on

Everyone's got workplace woes. The clueless manager; the disruptive coworker; the cube walls that loom ever higher as the years pass, trapping whatever's left of your soul.

But sometimes, Satan really leaves his mark on a joint. I worked Tech Support there. You may remember The C-Level Ticket. I'm Anonymous. This is my story.



A Basic Mistake

by in CodeSOD on

Way back in 1964, people were starting to recgonize that computers were going to have a large impact on the world. There was not, at the time, very much prepackaged software, which meant if you were going to use a computer to do work, you were likely going to have to write your own programs. The tools to do that weren't friendly to non-mathematicians.

Thus, in 1964, was BASIC created, a language derived from experiments with languages like DOPE (The Dartmouth Oversimplified Programming Experiment). The goal was to be something easy, something that anyone could use.


A Truly Bad Comparison

by in CodeSOD on

For C programmers of a certain age (antique), booleans represent a frustrating challenge. But with the addition of stdbool.h, we exited the world of needing to work hard to interact with boolean values. While some gotchas are still in there, your boolean code has the opportunity to be simple.

Mark's predecessor saw how simple it made things, and decided that wouldn't do. So that person went and wrote their own special way of comparing boolean values. It starts with an enum:


A Government Data Center

by in Feature Articles on

Back in the antediluvian times, when I was in college, people still used floppy disks to work on their papers. This was a pretty untenable arrangement, because floppy disks lost data all the time, and few students had the wherewithal to make multiple copies. Half my time spent working helldesk was breaking out Norton Diskutils to try and rescue people's term papers. To avoid this, the IT department offered network shares where students could store documents. The network share was backed up, tracked versions, and could be accessed from any computer on campus, including the VAX system (in fact, it was stored on the VAX).

I bring this up because we have known for quite some time that companies and governments need to store documents in centrally accessible locations so that you're not reliant on end users correctly managing their files. And if you are a national government, you have to make a choice: either you contract out to a private sector company, or you do it yourself.


It's Daniel Time Again!

by in Error'd on

It's been several years now that our reliable contributor Daniel D. has been sending us the same gripe time after time. We get it, really we do. It irks us too, but it is astounding just how many times he's been able to find this!
With no further ado, here is Daniel's pet peeve. See if you can figure out what it is.

640 kB 40 characters must be enough for anybody," right? Daniel bemoaned "US Banks, brokers, financial institutions. You would expect them to put heavy safeguards with stronger the password the better, right? But then you find out they require just 8 to 40 and not a bit more."


This Is Really Empty

by in CodeSOD on

Konrad was trying to understand how an input form worked, and found this validation function.

function IsReallyEmpty($subject)
{
        $trimmed = trim(preg_replace("/&.*;/", "", $subject));
        return strlen($trimmed) != 0;
}

Forward Not Found

by in CodeSOD on

Anthony found this solution to handling 404 errors which um… probably shouldn't have been found.

function show_404($page = '') {
        $uri = $_SERVER['REQUEST_URI'];
        error_log("Caught 404: $uri");
        $redirect_url = "";
       
        switch($uri){
                case "/SOMEURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/SOMEURL";
                        break;
                case "/SOMEOTHERURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/SOMEOTHERURL";
                        break;
                case "/YETANOTHERURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/YETANOTHERURL";
                        break;
                // ... THERE ARE 300 of these ...
                case "/MOREURLS":
                        $redirect_url="http://www.SOMEWEBSITE.com/MOREURLS";
                        break;
                case "/EVENMOREURLS":
                        $redirect_url="http://www.SOMEWEBSITE.com/EVENMOREURLS";
                        break;
        }

        if ($redirect_url){
                Header( "HTTP/1.1 301 Moved Permanently" );
                Header( "Location: $redirect_url" );
        } else {
                parent::show_404($page);
        }
}

A Percentage of Refactoring

by in CodeSOD on

Joseph was doing a refactoring effort, merging some duplicated functions into one, cleaning up unused Java code that really should have been deleted ages ago, and so on. But buried in that pile of code that needed cleaning up, Joseph found this little bit of code, to validate that an input was a percentage.

@Override
public Integer validatePercent(final String perc, final int currentPerc){
    char[] percProc= perc.toCharArray();
    char[] newPerc = new char[perc.length()];
    int percent=0;
    int y=0;
    if(percProc.length>4){
        return -1;
    }
    for(int x=0;x<percProc.length;x++){
        if(Character.isDigit(percProc[x])){
            newPerc[y]=percProc[x];
            y++;
        }
    }
    if(y==0){
        return -1;
    }
    
    String strPerc=(new String(newPerc));
    strPerc=strPerc.trim();
    if(strPerc.length()!=0){
        percent=Integer.parseInt(strPerc);
        if(percent<0){
            return -1;
        }else if(percent>100){
            return -1;
        }else if(Integer.parseInt(strPerc)==currentPerc){
            return -1;
        }else{
            return Integer.parseInt(strPerc);
        }
    }else{
        return-1;
    }
}

Archives