terça-feira, 15 de fevereiro de 2011

Hello World

    #include < stdlib.h >

    void main () {
        system("echo Hello world!");
    }

domingo, 13 de fevereiro de 2011

Switch-case consistente

Sem um framework web, o desenvolvimento de código baseado em AJAX pode ser um pouco complicado. Principalmente por causa da forma de como a resposta deve ser lida: você deve "ouvir" um "onreadystatechange" e fazer alguma coisa quando o "readyState" é 4.

É claro, a maioria das pessoas lidam com isso usando um simples "readyState == 4". Mas alguns programadores... bem... eles fazem isso:
    onreadystatechange = function(){

        switch(httpReq.readyState){
            case 0: if(httpReq.readyState == 0){
                break;
            }
            case 1: if(httpReq.readyState == 1){
                break;
            }
            case 2: if(httpReq.readyState == 2){
                break;
            }
            case 3: if(httpReq.readyState == 3){
                break;
            }
            case 4: if(httpReq.readyState == 4){
                if(httpReq.status == 200){
                    var val = httpReq.responseText;

                    alert(httpReq.responseText)
                    dataInsert(val);
                    break;
                }
                else{
                    alert("Error "+httpReq.status);
                    break;
                }
            }
        }
    };
Acho que desta forma, garante-se que o switch está funcionando!

Bitwise Operator

Será que o cara que escreveu este código esqueceu que existem operadores Bitwise???
    public bool IsFileReadOnly(int attributes)
    {
        bool retVal = false;

        if (attributes > 63)
        {
            attributes = attributes - 63;
        }

        if (attributes > 32)
        {
            attributes = attributes - 32;
        } 

        if (attributes > 16)
        {
            attributes = attributes - 16;
        }

        if (attributes > 8)
        {
            attributes = attributes - 8;
        }

        if (attributes > 4)
        {
             attributes = attributes - 4;
        }

        if (attributes > 2)
        {
            attributes = attributes - 2;
        }
  
        if (attributes  == 1)
        {
            retVal = true;
        }

        return retVal;
    }

Row Count

A falta que faz um leve conhecimento de SQL:
    static int GetTableRowCount(string tableName) {
        int count = 0;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = getConn();
        cmd.CommandText = "SELECT * FROM [" + tableName + "]";
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read()) { 
            count += 1; 
        }
        return count;
    }

Fatorial

O que importa é passar no teste!
    def testFactorial
        assert_equal(120, factorial(5))
    end

    def factorial(input)
        case input
            when 5 : 5 * 4 * 3 * 2 * 1
            when 3 : 3 * 2 * 1
            when 0 : 1
            else raise "input cannot be negative"
        end
    end

Eu odeio Strings

Isso que é odiar maninupalção de Strings!
    #include < wchar.h > //I hate strings.
    #include < tchar.h > //I HATE STRINGS!!!
    #include < string > //I HAT TEH STRINGES!!! DIE! DIEDIE! DIE!!!!!!

sábado, 12 de fevereiro de 2011

Incremento

Incrementar uma variável do tipo inteiro é bem simples, basta fazer isso:
    p += 5;
ou isso:
    p = p + 5;
Mas olha só o que o cidadão fez:
    for (int i = 0; i < 5; i++) {
        p++;
    }

P.O.G. Flowchart

A definição da palavra "gambiarra" no mundo nerd:

Técnica avançada de depuração

    flag=0
    if flag=1 then
        display "passei"
        flag=0
    else
        display "passei aqui!"
        flag=2
    end if
    display "ainda estah de peh... nao acredito!!!"
IMPORTANTE : Caso você não consiga mostrar o display na tela, poderá utilizar o método erro condicional colocando um comando que não existe para dar pau direto.

sexta-feira, 11 de fevereiro de 2011

Stupid Fucking Iterator

    /*
     * OK; before you read the following code know what I am trying to do.
     * I needed to get the list of child catagories from the root node so that
     * the root node didn't appear in the selection box. But for some stupid
     * fucking reason the stupid fucking DBA wont let me access the items using
     * indices and I instead have to use their stupid fucking Iterator
     * implementation. So there.
     */
    $firstList = $this->getRootNode()->getChildren();
    foreach ($firstList as $node)
    {
        $nodes = $node->getChildren();
        break;                // WTF?
    }

Angry comments

Isso que dá programar revoltado...
    // Either the app is exiting or the world is coming to an end.
    // Take your pick.

    // I'd trade my office mate for a layout manager.

    /* PB, is this right? -- AW */

    // Everything is shamelessly stolen and rewritten.
    // Feel the consequences of GPL ;-)

Newbie no VB

Não é por que é nosso primeiro Funny Code que eu vou pegar leve. Olha o que esse programador super-ultra-mega junior aprontou no Visual Basic:
    if (day=1) or (day=8) or (day=15) or (day=22) or (day=29) then
        weekday = "Monday"
    elseif (day=2) or (day=9) or (day=16) or (day=23) or (day=30) then
        weekday = "Tuesday"
    ...

Humor "nerd"

Antes de começar a postar os "Funny Codes", quero aqui deixar bem claro que nenhum nome será citado e que nenhuma empresa de desenvolvimento de softwares terá sua imagem afetada.

O objetivo deste blog é trazer um pouco do humor "nerd" que somente os mais aficcionados em programação conseguirão rir com algo aqui visto.

Então, divirtam-se!