1. Python / Говнокод #25447

    0

    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
    import sqlite3
    from bs4 import BeautifulSoup
    import requests, hashlib
    from io import open as iopen
    from urlparse import urlsplit
    
    def md5sum(filename, blocksize=65536):
    	hash = hashlib.md5()
    	with open(filename, "rb") as f:
    		for block in iter(lambda: f.read(blocksize), b""):
    			hash.update(block)
    	return hash.hexdigest()
    
    def parse_image_url(url):
    	html_doc = requests.get(url).text
    	soup = BeautifulSoup(html_doc, 'html.parser')
    	first = soup.find(class_='postContainer')
    	two = first.find_all('img')
    	requests_image(two[1].get('src'))
    
    def unic_check(file_name):
    	check_sum = md5sum(file_name)
    	if c.execute("SELECT * FROM sums WHERE sum = '%s'" % check_sum) != None:
    		cur.close()
    		conn.close()
    		return
    	else:
    		c.execute("INSERT INTO sums VALUES (%s)" % check_sum)
    		c.commit()
    		cur.close()
    		conn.close()
    		return
    
    def requests_image(file_url):
    	suffix_list = ['jpg', 'gif', 'png', 'tif', 'svg',]
    	file_name =  urlsplit(file_url)[2].split('/')[-1]
    	file_suffix = file_name.split('.')[1]
    	i = requests.get(file_url)
    	if file_suffix in suffix_list and i.status_code == requests.codes.ok:
    		with iopen(file_name, 'wb') as file:
    			file.write(i.content)
    	else:
    		return False
    	unic_check(file_name)
    
    def main():
    	Anime_types = ['http://anime.reactor.cc/tag/Anime+%D0%9D%D1%8F%D1%88%D0%B8', 'http://anime.reactor.cc/tag/Anime+Cosplay', 'http://anime.reactor.cc/tag/Anime+%D0%9A%D0%BE%D0%BC%D0%B8%D0%BA%D1%81%D1%8B', 'http://anime.reactor.cc/tag/Anime+Art']
    	global conn
    	global c
    	conn = sqlite3.connect('anime.db')
    	c = conn.cursor()
    	for x in Anime_types:
    		parse_image_url(x)
    		
    if __name__ == "__main__":
    	main()

    marataziat, 13 Марта 2019

    Комментарии (20)
  2. JavaScript / Говнокод #25446

    +1

    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
    // http://pacipfs2.antizapret.prostovpn.org/proxy-ssl.js
    
    function FindProxyForURL(url, host) {
      if (d_ipaddr.length < 10) return "DIRECT"; // list is broken
    
      if (!az_initialized) {
        var prev_ipval = 0;
        for (var i = 0; i < d_ipaddr.length; i++) {
         d_ipaddr[i] = parseInt(d_ipaddr[i], 36) + prev_ipval;
         prev_ipval = d_ipaddr[i];
        }
        for (var i = 0; i < special.length; i++) {
         special[i][1] = nmfc(special[i][1]);
        }
        az_initialized = 1;
      }
    
      var shost;
      if (/\.(ru|co|cu|com|info|net|org|gov|edu|int|mil|biz|pp|ne|msk|spb|nnov|od|in|ho|cc|dn|i|tut|v|dp|sl|ddns|dyndns|livejournal|herokuapp|azurewebsites|cloudfront|ucoz|3dn|nov|linode|amazonaws|sl-reverse|kiev)\.[^.]+$/.test(host))
        shost = host.replace(/(.+)\.([^.]+\.[^.]+\.[^.]+$)/, "$2");
      else
        shost = host.replace(/(.+)\.([^.]+\.[^.]+$)/, "$2");
      // Script optimization, see https://bugs.chromium.org/p/chromium/issues/detail?id=678022
      for (var k in dn) {
        var r = new RegExp('\\.'+k+'$');
        if (r.test(shost)) {shost = shost.replace(r, dn[k]); break;}
      }
      var curarr;
      if (/^[a-d]/.test(shost)) curarr = d_ad;
      else if (/^[e-h]/.test(shost)) curarr = d_eh;
      else if (/^[i-l]/.test(shost)) curarr = d_il;
      else if (/^[m-p]/.test(shost)) curarr = d_mp;
      else if (/^[q-t]/.test(shost)) curarr = d_qt;
      else if (/^[u-z]/.test(shost)) curarr = d_uz;
      else curarr = d_other;
    
      var oip = dnsResolve(host);
      var iphex = "";
      if (oip) {
       iphex = oip.toString().split(".");
       iphex = parseInt(iphex[3]) + parseInt(iphex[2])*256 + parseInt(iphex[1])*65536 + parseInt(iphex[0])*16777216;
      }
      var yip = 0;
      if (iphex) {
       for (var i = 0; i < d_ipaddr.length; i++) {
        if (iphex === d_ipaddr[i]) {yip = 1; break;}
       }
      }
      for (var i = 0; i < curarr.length; i++) {
        if (yip === 1 || shost === curarr[i]) {
          return "HTTPS proxy.antizapret.prostovpn.org:3143; PROXY proxy.antizapret.prostovpn.org:3128; DIRECT";
        }
      }
      for (var i = 0; i < special.length; i++) {
        if (isInNet(oip, special[i][0], special[i][1])) {return "PROXY CCAHIHA.antizapret.prostovpn.org:3128; DIRECT;";}
      }
    
      return "DIRECT";
    }

    CCAHIHA

    j123123, 13 Марта 2019

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

    +2

    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
    #include <type_traits>
    
    struct Foo {
      void bar(int) const & {}
    };
    
    int main() {    
      using MethodPtr = decltype(&Foo::bar);
      const MethodPtr arr[] = { &Foo::bar };
      auto *ptr = &arr;
      auto &ref = ptr;
    
      static_assert(std::is_same_v<decltype(ref), void (Foo::* const (*&)[1])(int) const &>);
    }

    Магия указателей возведенная в степень магии массивов в степени магии ссылок.

    https://wandbox.org/permlink/8DygQ6oocrEY1K1M

    Elvenfighter, 11 Марта 2019

    Комментарии (23)
  4. Куча / Говнокод #25444

    0

    1. 1
    https://medium.com/@evnowandforever/f-you-i-quit-hiring-is-broken-bb8f3a48d324

    tl;tr:

    Чувак говорит что его заебали интервьюеры которые просят на доске перевернуть бинарное дерево.
    Он считает что надо давать практические задачи, пускай даже и на дом. Если для решения практической задачи ему понадобится перевернуть бинарное дерево -- он почитает статью и напишет алгоритм.

    А интервьюеры сначала хотят дерево, а потом ноют.

    HEymHblu_nemyx, 11 Марта 2019

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

    +1

    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
    if ($_REQUEST['hash']==md5('2445355'.$uid.'__SECRET_KEY__')) {
      //доверяем вконтактику, и далее полагаем, что пользователь действительно авторизован там
      //для учетных записей пользователей я решил выделить логины вида vk-********
      $result = mysql_query("SELECT id, random, password FROM tracker_users WHERE username = 'vk-$uid'");
      setcookie('uid','');
      setcookie('pass','');
      if (mysql_num_rows($result)) {
        //пользователь авторизован, просто пересоздадим куки
        $user = mysql_fetch_assoc($result);
        mysql_query("UPDATE tracker_users SET name = '$name' WHERE username = 'vk-$uid' LIMIT 1");
        setcookie('pass',md5($user['random'].$user['password'].$user['random']));
        setcookie('uid',$user['id']);
      } else {
        //добавим запись в таблицу пользователей
        $random = mt_rand(100000,999999);
        $pwd = $uid . 'verysecretlonglongword-';
        $pid=md5(uniqid(rand(),true));
        mysql_query("INSERT INTO tracker_users 
          (username, name, password, random, id_level, email, style, language, flag, joined, lastconnect, pid, time_offset) VALUES 
          ('vk-$uid', '$name', '" . md5($pwd) . "', $random, 3, '', 5, 7, 0, NOW(), NOW(),'$pid', '0')");
        //вставили строчку, теперь создадим куки и перебросим на другую страницу
        setcookie('pass',md5($random.md5($pwd).$random));
        setcookie('uid',mysql_insert_id());
      }
      header("Location: /index.php");
    }

    https://habr.com/ru/post/126717/

    HEymHblu_nemyx, 10 Марта 2019

    Комментарии (14)
  6. Assembler / Говнокод #25442

    −2

    1. 1
    https://github.com/pustladi/MS-DOS-v.1.1

    давайте обсуждать сырцуы доса

    HEymHblu_nemyx, 10 Марта 2019

    Комментарии (21)
  7. Си / Говнокод #25441

    +1

    1. 1
    https://github.com/pustladi/Windows-2000

    давайте обсуждать срцы винд

    HEymHblu_nemyx, 10 Марта 2019

    Комментарии (26)
  8. Си / Говнокод #25440

    0

    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
    // https://patents.google.com/patent/US20160357533A1/en
    // Generating code in statically typed programming languages for dynamically typed array-based language 
    /*
    Example 2
    
    The cell array is classified as heterogeneous and translated into a C structure. Source code includes the following array, which is classified as belonging to a heterogeneous class.
    	
    x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1};
    ...
    function y = process (x)
     ...
     y = 0;
     for i = 1:2:numel(x)
      if ~strcmp(x{i}, ‘add’)
       y = y + x{i+ 1};
      elseif ~strcmp(x{i}, ‘multiply’)
       y = y * x{i+1};
      end
     end
    end
    
    C code generated in the STPL contains a C structure type that is used for the variable “x”:
    */
    typedef struct {
        char f1[3];
        double f2;
        char f3[8];
        double f4;
        char f5[3];
        double f6;
        char f7[3];
        double f8;
      } cell_0;
    static double process(const cell_0 x)
    {
      ...
    }

    Сраные софтерные патенты. Блядь, вдумайтесь в эту хуйню. Вам дан динамически-типизированный язык, вот типа есть такой "массив" в котором элементы могут быть произвольной поеботой, например строками, флоатами. Как нам это оттранслировать? Да запросто, вот допустим есть такое говно: x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1}; - хуйнуть структуру надо
    typedef struct {
      char f1[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f2;
      char f3[8]; // тут сука 8 букв потому что слово "multiply" из 8 букв
      double f4;
      char f5[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f6;
      char f7[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f8;
    } cell_0;

    А нахуй? Ну т.е. вот потом там будет сгенерен в сишке код, который будет через memcmp проверять этот char f1[3] что там "add", и потом будет еще код, который проверит что char f3[8] это "multiply", да? Ну т.е. у вас структура специализирована под конкретную поебень x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1}; и там блядь и так понятно, что вот там будет add, там будет multiply, и что вот такое количество элементов, это ясно из самого определения структуры, нахуй это говно вообще? И это говно еще запатентовали

    j123123, 10 Марта 2019

    Комментарии (16)
  9. Си / Говнокод #25439

    0

    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 (memory[i] == CRG && memory[i + 1] == STDI) {
    	fprintf(code, "%d %d ", CRG, STDI);
    	i++;
    }
    else if (memory[i] == CRC && memory[i + 1] == STDI) {
    	fprintf(code, "%d %d ", CRC, STDI);
    	i++;
    }
    else if (memory[i] == PRG && memory[i + 1] == STDI) {
    	fprintf(code, "%d %d ", PRG, STDI);
    	i++;
    }
    else if (memory[i] == PRC && memory[i + 1] == STDI) {
    	fprintf(code, "%d %d ", PRC, STDI);
    	i++;
    }

    h: post/442988 / https://github.com/Centrix14/TVM/blob/master/TVM/ngl.c
    На статье стоит меточка «Tutorial».

    gost, 09 Марта 2019

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

    −1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // Microsoft открыла код Калькулятора Windows
    
    // https://github.com/Microsoft/calculator/blob/057401f5f2b4bb1ea143da02c773ac18d1bb9a2e/src/CalcViewModel/Common/CalculatorButtonUser.h#L8
    
    namespace CalculatorApp
    {
        namespace CM = CalculationManager;
    
        public enum class NumbersAndOperatorsEnum
        {
            Zero = (int) CM::Command::Command0,
            One = (int) CM::Command::Command1,
            Two = (int) CM::Command::Command2,
            Three = (int) CM::Command::Command3,
            Four = (int) CM::Command::Command4,
            Five = (int) CM::Command::Command5,
            Six = (int) CM::Command::Command6,
            Seven = (int) CM::Command::Command7,
            Eight = (int) CM::Command::Command8,
            Nine = (int) CM::Command::Command9,
            Add = (int) CM::Command::CommandADD,
            Subtract = (int) CM::Command::CommandSUB,
            Multiply = (int) CM::Command::CommandMUL,
            Divide = (int) CM::Command::CommandDIV,
            Invert = (int) CM::Command::CommandREC,
            Equals = (int) CM::Command::CommandEQU,
            Decimal = (int) CM::Command::CommandPNT,
            Sqrt = (int) CM::Command::CommandSQRT,
            Percent = (int) CM::Command::CommandPERCENT,
            Negate = (int) CM::Command::CommandSIGN,
            Backspace = (int) CM::Command::CommandBACK,
            ClearEntry = (int) CM::Command::CommandCENTR,
            Clear = (int) CM::Command::CommandCLEAR,
            Degree = (int) CM::Command::CommandDEG,
            Radians = (int) CM::Command::CommandRAD,
            Grads = (int) CM::Command::CommandGRAD,
            Degrees = (int) CM::Command::CommandDegrees,
            OpenParenthesis = (int) CM::Command::CommandOPENP,
            CloseParenthesis = (int) CM::Command::CommandCLOSEP,
            Pi = (int) CM::Command::CommandPI,
            Sin = (int) CM::Command::CommandSIN,
            Cos = (int) CM::Command::CommandCOS,
            Tan = (int) CM::Command::CommandTAN,
            Factorial = (int) CM::Command::CommandFAC,
            XPower2 = (int) CM::Command::CommandSQR,
            Mod = (int) CM::Command::CommandMOD,
            FToE = (int) CM::Command::CommandFE,
            LogBaseE = (int) CM::Command::CommandLN,
            InvSin = (int) CM::Command::CommandASIN,
            InvCos = (int) CM::Command::CommandACOS,
            InvTan = (int) CM::Command::CommandATAN,
            LogBase10 = (int) CM::Command::CommandLOG,
            XPowerY = (int) CM::Command::CommandPWR,
            YRootX = (int) CM::Command::CommandROOT,
            TenPowerX = (int) CM::Command::CommandPOW10,
            EPowerX = (int) CM::Command::CommandPOWE,
            Exp = (int) CM::Command::CommandEXP,
            IsScientificMode = (int) CM::Command::ModeScientific,
            IsStandardMode = (int) CM::Command::ModeBasic,
            None = (int) CM::Command::CommandNULL,
            IsProgrammerMode = (int) CM::Command::ModeProgrammer,
            DecButton = (int) CM::Command::CommandDec,
            OctButton = (int) CM::Command::CommandOct,
            HexButton = (int) CM::Command::CommandHex,
            BinButton = (int) CM::Command::CommandBin,
            And = (int) CM::Command::CommandAnd,
            Ror = (int) CM::Command::CommandROR,
            Rol = (int) CM::Command::CommandROL,
            Or = (int) CM::Command::CommandOR,
            Lsh = (int) CM::Command::CommandLSHF,
            Rsh = (int) CM::Command::CommandRSHF,
            Xor = (int) CM::Command::CommandXor,
            Not = (int) CM::Command::CommandNot,
            A = (int) CM::Command::CommandA,
            B = (int) CM::Command::CommandB,
            C = (int) CM::Command::CommandC,
            D = (int) CM::Command::CommandD,
            E = (int) CM::Command::CommandE,
            F = (int) CM::Command::CommandF,
            Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.        
            Sinh = (int) CM::Command::CommandSINH,
            Cosh = (int) CM::Command::CommandCOSH,
            Tanh = (int) CM::Command::CommandTANH,
            InvSinh = (int) CM::Command::CommandASINH,
            InvCosh = (int) CM::Command::CommandACOSH,
            InvTanh = (int) CM::Command::CommandATANH,
            Qword = (int) CM::Command::CommandQword,
            Dword = (int) CM::Command::CommandDword,
            Word = (int) CM::Command::CommandWord,
            Byte = (int) CM::Command::CommandByte,
            Cube = (int) CM::Command::CommandCUB,
            DMS = (int) CM::Command::CommandDMS,
    
            BINSTART = (int) CM::Command::CommandBINEDITSTART,
            BINPOS0 = (int) CM::Command::CommandBINPOS0,
            BINPOS1 = (int) CM::Command::CommandBINPOS1,
            BINPOS2 = (int) CM::Command::CommandBINPOS2,
            BINPOS3 = (int) CM::Command::CommandBINPOS3,
            BINPOS4 = (int) CM::Command::CommandBINPOS4,
            BINPOS5 = (int) CM::Command::CommandBINPOS5,

    Интересно, а эту херню кодогенерировали? Или это всё ручной труд?

    j123123, 09 Марта 2019

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