1. C++ / Говнокод #12997

    +12

    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
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    #include <iostream>
    
    namespace dynamic {
    
    template <class T> class scope;
    template <class T> class variable {
    public:
        variable() : initial(0), current(&initial) {}
        variable(const T &val) : initial(val, 0), current(&initial) {}
        operator T() { return current->val; }
        const T & operator = (const T & new_val) {
            return current->val = new_val;
        }
    private:
        struct node {
            node(node *prev) : val(), prev(prev) {}
            node(const T &val, node *prev) : val(val), prev(prev) {}
            T val;
            node *prev;
        };
        node initial;
        node *current;
        friend class scope<T>;
    };
    
    template <class T> class scope {
    public:
        scope(variable<T> &var) : var(var), node(var.current) {
            var.current = &node;
        }
        scope(variable<T> &var, const T &val) : var(var), node(val, var.current) {
            var.current = &node;
        }
        ~scope() {
            var.current = node.prev;
        }
    private:
        variable<T> &var;
        typename variable<T>::node node;
    };
    
    }
    
    
    dynamic::variable<int> x(100500);
    
    void foo() {
        std::cout << x << std::endl;
    }
    
    void bar() {
        dynamic::scope<int> x_(x, 42);
        foo();
        x = 265;
        foo();
    }
    
    int main() {
        foo();
        bar();
        foo();
        return 0;
    }

    Навеяно http://govnokod.ru/12993.

    https://ideone.com/7AA33Q

    bormand, 14 Мая 2013

    Комментарии (11)
  2. C++ / Говнокод #12993

    +20

    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
    56. 56
    57. 57
    58. 58
    59. 59
    #include <iostream>
    #include <cstring>
    
    const char tag[] = "Secret tag!";
    const size_t tagSize = sizeof(tag);
    const size_t nameSize = 32;
    
    template<class T>
    struct Value
    {
        Value(const char* name, const T& data) :
    data(data)
    {
        std::strncpy(this->tag, ::tag, tagSize);
        std::strncpy(this->name, name, nameSize);
    }
    char tag[tagSize];
    char name[nameSize];
    T data;
    };
    
    int getStackDir()
    {
        char a;
        char b;
        return &b > &a ? 1 : -1;
    }
    
    template<class T>
    T getValue(const char* name)
    {
        static const size_t stackSize = 1024 * 1024;
        const int stackDir = getStackDir();
        char begin;
        for(char* p = &begin, *end = &begin - stackSize * stackDir; p != end; p -= stackDir)
        {
            Value<T>* value = (Value<T>*)p;
            if(std::strcmp(value->tag, tag) != 0) continue;
            if(std::strcmp(value->name, name) != 0) continue;
            return value->data;
        }
        return T();
    }
    
    #define SET(type, name, value) Value<type> name(#name, value)
    #define GET(type, name) getValue<type>(#name)
    
    //-----------------------------------------------------------
    
    void test()
    {
        std::cout << GET(int, x) << std::endl;
    }
    
    int main()
    {
        SET(int, x, 13);
        test();
    }

    Отсюда http://www.rsdn.ru/forum/cpp/5163916.flat#5163916

    Artur, 13 Мая 2013

    Комментарии (19)
  3. Python / Говнокод #12992

    −94

    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
    #/usr/bin/python
    import sys, os, time, httplib
    if sys.platform == 'linux' or sys.platform == 'linux2':
     clearing = 'clear'
    else:
     clearing = 'cls'
     os.system(clearing)
    if len(sys.argv) != 2:
     print "\n|-------------------------------------------------------------|"
     print "|               Admin login finder     v2.0                     |"
     print "| Help: admin-find.py -h                                        |"
     print "|---------------------------------------------------------------|\n"
     sys.exit(1)
    for arg in sys.argv:
     if arg == '-h':
    	print "\n|-----------------------------------------------------------------------------|"
    	print "|                Admin login finder     v2.0                                    |"
    	print "| Usage: admin-find.py www.site.com                                             |"
    	print "| Example: admin-find.py site.com                                               |"
    	print "|-------------------------------------------------------------------------------|\n"
    	sys.exit(1)
    site = sys.argv[1].replace("http://","").rsplit("/",1)[0] 
    site = site.lower()
    admin_path = ['admin.php','admin/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/','memberadmin/','administratorlogin/','adm/','admin/account.php','admin/index.php','admin/login.php','admin/admin.php','admin/account.php','joomla/administrator','login.php',
    'admin_area/admin.php','admin_area/login.php','siteadmin/login.php','siteadmin/index.php','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html','admin_area/index.php','bb-admin/index.php','bb-admin/login.php','bb-admin/admin.php','admin/home.php','admin_area/login.html','admin_area/index.html','admin/controlpanel.php','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html','w    ebadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html','admin/cp.php','cp.php','administrator/index.php','administrator/login.php','nsw/admin/login.php','webadmin/login.php','admin/admin_login.php','admin_login.php','administrator/account.php','administrator.php','admin_area/admin.html','pages/admin/admin-login.php','admin/admin-login.php','admin-login.php','bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','modelsearch/login.php','moderator.php','moderator/login.php','moderator/admin.php','account.php','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.php','admincontrol.php',    
    'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.php','adminarea/index.html','adminarea/admin.html','webadmin.php','webadmin/index.php','webadmin/admin.php','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.php','moderator.htm    l','administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','m    odelsearch/login.html','moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html','admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.php','account.html','controlpane    l.html','admincontrol.html','panel-administracion/login.php','wp-login.php','adminLogin.php','admin/adminLogin.php','home.php','adminarea/index.php','adminarea/admin.php','adminarea/login.php','panel-administracion/index.php','panel-administracion/admin.php','modelsearch/index.php','modelsearch/admin.php','admincontrol/login.php','adm/admloginuser.php','admloginuser.php','admin2.php',    'admin2/login.php','admin2/index.php','adm/index.php','adm.php','affiliate.php','adm_auth.php    ','memberadmin.php','administratorlogin.php']
    print "\n|-------------------------------------------------------------|"
    print "|                Admin login finder     v2.0                    |"
    print "|---------------------------------------------------------------|\n"
    print "\n[-] %s" % time.strftime("%X")
    print "[+] Target:",site
    print "[+] Checking paths..."
    print
    try:
     for admin in admin_path:
      admin = admin.replace("\n","")
      admin = "/" + admin
      connection = httplib.HTTPConnection(site)
      connection.request("GET",admin)
      response = connection.getresponse()
      print "%s %s %s" % (admin, response.status, response.reason)
    except(KeyboardInterrupt,SystemExit):
     raise
    except:
     pass

    Оригинал тут:
    http://paste.org.ru/?8l6f57

    lancerok, 13 Мая 2013

    Комментарии (14)
  4. PHP / Говнокод #12991

    +149

    1. 1
    $this->t = (date('w')+1)>6?0:(date('w')+1);

    фак мой мозг

    CRRaD, 13 Мая 2013

    Комментарии (6)
  5. PHP / Говнокод #12990

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $useDummy = true;
            do {
                if (!file_exists($filename)){ break; }
                require_once $filename;            
                if (!class_exists($className)){ break; }                        
                $useDummy = false;
            } while(false);

    Новый оператор ветвления do ... while

    dimkich, 13 Мая 2013

    Комментарии (81)
  6. C++ / Говнокод #12989

    +22

    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
    // поверка наличия указазанного флага в набора флагов
    bool __fastcall TfrmFieldsEditor::HasFlag(int nAFlag, int nAFlagsCollection)
    {
        bool bRetVal = false;
        std::bitset<8> bsFlagBits;
        bsFlagBits.reset();
        bsFlagBits = nAFlagsCollection;
        int nBitsCount = bsFlagBits.size();
        for(int i= 0 ; i < nBitsCount; ++i)
            {
            if(bsFlagBits[i]==1)
                {
                bsFlagBits.reset();
                bsFlagBits[i] = 1;
                if (bsFlagBits.to_ulong() == nAFlag)
                    {
                    bRetVal = true;
                    break;
                    }
                else
                    bsFlagBits = nAFlagsCollection;
                }
     
     
     
            }
        return bRetVal;
    }

    Ulysses, 13 Мая 2013

    Комментарии (8)
  7. Java / Говнокод #12988

    +69

    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
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    package javaapplication4;
    import java.util.Scanner;
    
    public class JavaApplication4 {    
        public static void main(String[] args) {            
            int powerOfTwo[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536};
            int lengthOfHammingCode = 0;      
            Scanner in = new Scanner(System.in);
            System.out.print("Введите двоичное число, которое хотите закодировать: "); String code = in.nextLine();
            in.close();
            if (code.length() < 2) System.out.println("Слишком маленькое число.");
            
            boolean controlBits[] = new boolean[code.length()*2+1]; 
            int i = 0;
            
            //---------------ВЫЧИСЛЯЕМ ДЛИНУ КХ И КОНТРОЛЬНЫЕ БИТЫ------------------
             do {        
                 controlBits[powerOfTwo[i]] = true;
                 i++;
            } while (powerOfTwo[i] <= (code.length()+1)); // Цикл ищет такую НАИМЕНЬШУЮ степень двойки, которая > либо = длине входного кода.
             
            lengthOfHammingCode = code.length() + i;   
            //----------------------------------------------------------------------
            
            //-------------ЗАПИСЫВАЕМ ВВЕДЁННЫЙ КОД С КОНТРОЛЬНЫМИ БИТАМИ-----------
            boolean hammingCode[] = new boolean[lengthOfHammingCode];       
            int j = 0;
            for (i = 0; i < lengthOfHammingCode; i++) { // Устанавливаем биты для промежуточного кода. 
                if (!controlBits[i+1]) {
                    hammingCode[i] = (code.charAt(j) == '1');
                    j++;
                }
            }
            //----------------------------------------------------------------------
            
            System.out.print("Промежуточный код с контрольными битами: [");
            for (int k = 0; k < lengthOfHammingCode; k++) {
                char c = (hammingCode[k]) ? '1' : '0';
                if (controlBits[k+1]) System.out.print("!");
                System.out.print(c);
            }
            System.out.print("]\n");
            
            //---------------------ВЫЧИСЛЯЕМ ЗНАЧЕНИЕ КОНТРОЛЬНЫХ БИТ----------------
            for (i = 0; i < (lengthOfHammingCode - code.length()); i++) { // Цикл проходится по всем контрольным битам.
                boolean nextBit = false;         
                for (j = powerOfTwo[i]-1; j < lengthOfHammingCode; j += powerOfTwo[i]*2) {
                    for (int n = j; n < j + powerOfTwo[i]; n++) {
                        if (n > lengthOfHammingCode - 1) break;
                        nextBit ^= hammingCode[n]; // Ксорим со следующим битом
                    }             
                }           
                hammingCode[powerOfTwo[i]-1] = nextBit; // Записываем значение i-ного бита.
            }
            //----------------------------------------------------------------------
            
            System.out.print("Код Хемминга с контрольными битами: [");
            for (int k = 0; k < lengthOfHammingCode; k++) {
                char c = (hammingCode[k]) ? '1' : '0';
                System.out.print(c);
            }
            System.out.print("]\n"); 
        }
    }

    Реализация вычисления кода Хемминга по заданному двоичному коду.

    Govnocoder#0xFF, 13 Мая 2013

    Комментарии (6)
  8. 1C / Говнокод #12987

    −167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    МассивКоэффициентов = Новый Структура;
    -------------------------------------------------------------------------------------------------------
    Если Элемент.Имя = "КнопкаПерсонал" тогда
    	СписокВидоврасчета = 1;
    иначе
    	СписокВидоврасчета = 2;
    конецЕсли;

    "Принцип наименьшего удивления" при выборе имен переменных в работе

    doom2good, 13 Мая 2013

    Комментарии (4)
  9. 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)
  10. 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)