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;
    }
}

The Batch Managing Batch File

by in Representative Line on

Carl was debugging a job management script. The first thing that caught his attention was that the script was called file.bat. They were running on Linux.

The second thing he noticed, was that the script was designed to manage up to 999 jobs, and needed to simply roll job count over once it exceeded 999- that is to say, job 1 comes after job 999.


Domino Theory

by in Error'd on

Cool cat Adam R. commented "I've been getting a bunch of messages from null in my WhatsApp hockey group."


A Date Next Month

by in Representative Line on

We all know the perils of bad date handling, and Claus was handed an annoying down bug in some date handling.

The end users of Claus's application do a lot of work in January. It's the busiest time of the year for them. Late last year, one of the veteran users raised a warning: "Things stop working right in January, and it creates a lot of problems."


A Refreshing Change

by in Feature Articles on

Dear Third-Party API Support,

You're probably wondering how and why your authorization server has been getting hammered every single day for more than 4 years. It was me. It was us—the company I work for, I mean. Let me explain.


The Bob Procedure

by in CodeSOD on

Joe recently worked on a financial system for processing loans. Like many such applications, it started its life many, many years ago. It began as an Oracle Forms application in the 90s. By the late 2000s, Oracle was trying to push people away from forms into their newer tools, like Oracle ApEx (Application Express), but this had the result of pushing people out of Oracle's ecosystem and onto their own web stacks.

The application Joe was working on was exactly that. Now, no one was going to migrate off of an Oracle database, especially because 90% of their business logic was wired together out of PL/SQL packages. But they did start using Java for developing their UI, and then at some other point, started using Liquibase for helping them maintain and manage their schema.


The File Transfer

by in CodeSOD on

SQL Server Integration Services is Microsoft's ETL tool. It provides a drag-and-drop interface for describing data flows from sources to sinks, complete with transformations and all sorts of other operations, and is useful for migrating data between databases, linking legacy mainframes into modern databases, or doing what most people seem to need: migrating data into Excel spreadsheets.

It's essentially a full-fledged scripting environment, with a focus on data-oriented operations. The various nodes you can drag-and-drop in are database connections, queries, transformations, file system operations, calls to stored procedures, and so on. It even lets you run .NET code inside of SSIS.


Archives