1. JavaScript / Говнокод #12986

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    (function() {
        (function init() {
            document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
        })();
    })();
    
    function DOMContentLoaded() {
        //...
    }

    И да, jQuery подключена на странице.

    madhead, 13 Мая 2013

    Комментарии (7)
  2. ActionScript / Говнокод #12985

    −163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    public function algorithmChanged(arg1:flash.events.Event):*
            {
                var loc1:*;
                loc1 = null;
                if (currentAlgorithm != null)
                    removeChild(currentAlgorithm);
                loc1 = arg1.target.selectedLabel;
                currentAlgorithm = null;
                animationManager.resetAll();
                if (loc1 != "Heap")
                    if (loc1 != "Comparison Sort")
                        if (loc1 != "Counting Sort")
                            if (loc1 != "Bucket Sort")
                                if (loc1 != "Radix Sort")
                                    if (loc1 != "Heap Sort")
                                        if (loc1 != "Binary Search Tree")
                                            if (loc1 != "AVL Tree")
                                                if (loc1 != "Open Hashing")
                                                    if (loc1 != "Closed Hashing")
                                                        if (loc1 != "Graph")
                                                            if (loc1 != "DFS")
                                                                if (loc1 != "BFS")
                                                                    if (loc1 != "Connected Components")
                                                                        if (loc1 != "Dijkstra")
                                                                            if (loc1 != "Prim")
                                                                                if (loc1 != "Kruskal")
                                                                                    if (loc1 != "Topological Sort")
                                                                                        if (loc1 != "Floyd-Warshall")
                                                                                            if (loc1 != "B Tree")
                                                                                                if (loc1 != "Binomial Queue")
                                                                                                    if (loc1 != "Disjoint Sets")
                                                                                                        if (loc1 != "Array Stack")
                                                                                                            if (loc1 != "Array Queue")
                                                                                                                if (loc1 != "Linked List Stack")
                                                                                                                    if (loc1 != "Linked List Queue")
                                                                                                                        if (loc1 != "Red Black Tree")
                                                                                                                            if (loc1 != "Closed Hashing (buckets)")
                                                                                                                                if (loc1 == "B+ Tree")
                                                                                                                                {
                                                                                                                                    currentAlgorithm = new BPlusTree(animationManager);
                                                                                                                                    addChildAt(currentAlgorithm, 0);
                                                                                                                                }
                                                                                                                            else 
                                                                                                                            {
                                                                                                                                currentAlgorithm = new ClosedHash2(animationManager);
                                                                                                                                addChildAt(currentAlgorithm, 0);
                                                                                                                            }
                                                                                                                        else 
                                                                                                                        {
                                                                                                                            currentAlgorithm = new RedBlackTree(animationManager);
                                                                                                                            addChildAt(currentAlgorithm, 0);
                                                                                                                        }
    и т.д. пока не закроются все if'ы

    Визуализатор сортировок университета Сан-Франциско

    alexprey, 12 Мая 2013

    Комментарии (21)
  3. C# / Говнокод #12984

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    //top edge
                if (normal)
                    for (int i = y; i > 0; i--)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[0] = new Point(x, i - 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y - i) > 0); i++)
                        if (_map[x + i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[1] = new Point(x + i - 1 - minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //right edge
                if (normal)
                    for (int i = x; i < MAP_SIZE; i++)
                        if (_map[i, y] == 0)
                            if ((MAP_SIZE - i - 1) > minDist) { mnt.Corners[2] = new Point(i - 1 - minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y + i) < MAP_SIZE); i++)
                        if (_map[x + i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[3] = new Point(x + i - 1 - minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom edge
                if (normal)
                    for (int i = y; i > 0; i++)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[4] = new Point(x, i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-left edge
                if (normal)
                    for (int i = 0; ((x - i) < MAP_SIZE) & ((y + i) > 0); i++)
                        if (_map[x - i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[5] = new Point(x - i + 1 + minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //left edge
                if (normal)
                    for (int i = x; i > 0; i--)
                        if (_map[i, y] == 0)
                            if ((i + 1) > minDist) { mnt.Corners[6] = new Point(i + 1 + minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-left edge
                if (normal)
                    for (int i = 0; ((x - i) > 0) & ((y - i) > 0); i++)
                        if (_map[x - i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[7] = new Point(x - i + 1 + minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }

    Мне было лень думать. Очень лень.

    RaZeR, 11 Мая 2013

    Комментарии (1)
  4. Си / Говнокод #12983

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/types.h>
    
    void usage(char *progname)
    {
        fprintf(stderr,"Usage: %s [-i <interval>]\n",progname);
        exit(1);
    }
    
    int main(int argc, char *argv[])
    {
        int arg;
        size_t alloc = 1000;
        uid_t userid = getuid();
    
        while ((arg = getopt(argc,argv,"")) != -1) {
            switch(arg) {
                default:
                    usage(argv[0]);
                    break;
            }
        }
    
        //const char *basecmd = "sudo turbostat -s -i 1 2>&1";
        char ghz[8];
        char *junkbuffer = malloc(sizeof(char)*1000);
        const char *basecmd = "turbostat -s -i 1 2>&1";
    
        seteuid(0);
        setuid(0);
        FILE *turboPipe = popen(basecmd,"r");
        seteuid(userid);
        setuid(userid);
    
        /* ignore first line */
        getline(&junkbuffer,&alloc,turboPipe);
        fscanf(turboPipe,"%*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",ghz);
        free(junkbuffer);
    
        fprintf(stdout,"%s\n",ghz);
        pclose(turboPipe);
    
        return 0;
    }

    Установил новый Debian на ноут. Искал инфу по Intel TurboBoost.
    Наткунлся на это
    http://technicallyliving.blogspot.com/2012/06/intel-turboboost-and-linux.html

    Улыбнул вайл-свитч. Что мешало автору обойтись без свитча?

    denis90, 09 Мая 2013

    Комментарии (2)
  5. Java / Говнокод #12982

    +79

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    package testapp;
    
    public class TestApp {
        
        public static void main(String[] args) {
            int count = 0;
            for (int i = 0; i < 1000000; i++) {
                if (isLucky(i)) {
                    System.out.println(i);
                    count++;
                }
            }
            System.out.println("Total: " + count);
        }
        
        static boolean isLucky(final int n) {
            String num = Integer.toString(n);
            switch(6 - num.length()) {
                case 1: 
                    num = "0".concat(num);
                    break;
                case 2:
                    num = "00".concat(num);
                    break;
                case 3:
                    num = "000".concat(num);
                    break;
                case 4: 
                    num = "0000".concat(num);
                    break;
                case 5: 
                    num = "00000".concat(num);
                    break;
            }
            
            return (((getDigitAt(num, 0) + getDigitAt(num, 1) == getDigitAt(num, 2) + getDigitAt(num, 3))) & ((getDigitAt(num, 2) + getDigitAt(num, 3) == getDigitAt(num, 4) + getDigitAt(num, 5))));
        }
        
        static int getDigitAt(String number, int index) {
            return Character.getNumericValue(number.charAt(index));
        }
    }

    Моё. Проверяет числа на "счастливость". Число счастливое, если в 6-значном числе сумма каждой пары соседних цифр одинакова. Т.е 211221 - счастливое, т.к. (2+1) = (1+2) = (2+1)

    Govnocoder#0xFF, 09 Мая 2013

    Комментарии (29)
  6. Java / Говнокод #12981

    +89

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public void render(){
    	for(int y = 0; y < height; y++){
    		if(y < 0 || y >= height) break;
    		for(int x = 0; x < width; x++){
    			if(x < 0 || x >= width) break;
    			int tileIndex = (x >> 4) + (y >> 4) * 64;
    			pixels[x + y * width] = tiles[tileIndex];
    		}
    	}
    }

    чтоб уж наверняка
    http://www.youtube.com/watch?v=uPkXZmOuqGI

    lowercase, 08 Мая 2013

    Комментарии (11)
  7. Perl / Говнокод #12980

    −103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    sub exdef {
        my ($hash, $key) = @_;
    
        if (exists $hash->{$key} && defined $hash->{$key}) {
            return 1;
        }
    
        return 0;
    }

    No comments.

    BTW.
    http://perldoc.perl.org/functions/exists.html
    http://perldoc.perl.org/functions/defined.html

    Elvenfighter, 08 Мая 2013

    Комментарии (32)
  8. C++ / Говнокод #12979

    +16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    try
    {
       Application->Initialize();
    }
    catch (...)
     {
          try
         {
            throw Exception("");
           }
       catch (Exception &exception)
       {
          Application->ShowException(&exception);
       }
     }

    Найдено в проекте написанном на Borland C++Builder :)

    _Ru55_, 08 Мая 2013

    Комментарии (5)
  9. Pascal / Говнокод #12978

    +103

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    if (s[n][c]='1')and(s[n][c+1]='0')and(s[n+1][c]='0')and(n=1)and(c=1) then writeln('*');
    if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(s[n][c+1]='0')and(n=1) then writeln('*');
    if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(n=1)and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(s[n+1][c]='0')and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10)and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10) then writeln('*');
    if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(n=10)and(c=1) then writeln('*');
    if (s[n][c]='1')and(s[n+1][c]='0')and(s[n][c+1]='0')and(s[n-1][c]='0')and(c=1) then writeln('*');
    if (s[n][c]='1')and(s[n][c+1]='.')and(s[n+1][c]='.')and(n=1)and(c=1) then writeln('*');
    if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(s[n][c+1]='.')and(n=1) then writeln('*');
    if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(n=1)and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(s[n+1][c]='.')and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10)and(c=10) then writeln('*');
    if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10) then writeln('*');
    if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(n=10)and(c=1) then writeln('*');
    if (s[n][c]='1')and(s[n+1][c]='.')and(s[n][c+1]='.')and(s[n-1][c]='.')and(c=1) then writeln('*');

    Конец решения первой задачи все из той же дистанционки.
    На этот раз мопед не мой, а одной юной дамы.
    Вот за ЭТО я и недолюбливаю Паскаль: иногда код хер прочитаешь. А еще путаница с типами. И логикой. Гы.

    ckopo, 08 Мая 2013

    Комментарии (56)
  10. PHP / Говнокод #12977

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $content="{$_POST["From"]} - {$_POST["To"]}: {$_POST["DepartureDate"]},{$_POST["ArrivalDate"]}; {$_POST["date_type"]}";
    			
    $content=str_replace("'","",$content);
    
    if(!mysql_num_rows(mysql_query("select id from table where sess_id='$sess_id' AND aff_id='$aff_id' AND operation_id='$operation_id' AND `content`='$content'"))>0){
    }

    berejant, 08 Мая 2013

    Комментарии (9)