1. Куча / Говнокод #25455

    +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
    !DOCTYPE html>
    <html>
    <%c++
        auto para=@@.get<std::map<std::string,std::string>>("parameters");
    %>
    <head>
        <meta charset="UTF-8">
        <title>{{ title }}</title>
    </head>
    <body>
        <%view header %>
        <%c++ if(para.size()>0){%>
        <H1>Parameters</H1>
        <table border="1">
          <tr>
            <th>name</th>
            <th>value</th>
          </tr>
          <%c++ for(auto iter:para){%>
          <tr>
            <td>{%iter.first%}</td>
            <td><%c++ $$<<iter.second;%></td>
          </tr>
          <%c++}%>
        </table>
        <%c++ }else{%>
        <H1>no parameter</H1>
        <%c++}%>
    </body>

    C++ шаблонизатор
    https://github.com/an-tao/drogon/blob/master/examples/simple_example/ListParaView.csp

    HEymHblu_nemyx, 19 Марта 2019

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

    +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
    template<typename T>
    class IsClassT {
      private:
        typedef char One;
        typedef struct { char a[2]; } Two;
        template<typename C> static One test(int C::*);
        // Will be chosen if T is anything except a class.
        template<typename C> static Two test(...);
      public:
        enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1 };
        enum { No = !Yes };
    };

    Как эта поебота работает?
    Что такое "int C::*"?

    A3APTHblu_nemyx, 19 Марта 2019

    Комментарии (133)
  3. Куча / Говнокод #25453

    +1

    1. 1
    https://code.jsoftware.com/wiki/Jd/Guide

    > A db is a folder with a folder for each table. Each table folder has a folder for each column. Each folder has a few metadata files (prefix jd).

    Я знаю, что базы данных обычно хранятся в файлах. А зачем хранить их как здесь, в котологах и файлах? Мы же получаем в базе ограничения и баги файловой системы (типа https://code.jsoftware.com/wiki/Jd/Ops_common#names), а если хотим переносимости, то нескольких ФС.

    BEKTOPHblu_nETyX, 18 Марта 2019

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    include('translate.class.php');
    $x = new translator_text();
    $text = 'Al Hotel Demo si vive in armonia con se stessi, immersi nel verde di una natura rigogliosa, con i boschi di pini, querce e tamerici in un terreno a terrazze sul mare. Il Villaggio Turistico è un moderno centro di vacanze, concepito e costruito per rispondere a tutte le esigenze dei suoi ospiti.';
    echo'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
    echo $x->translate(strip_tags(trim($text)), 'it', 'ru');
    ?>

    Автоматический переводчик текста на "PHP"...
    https://xdan.ru/avtomaticheskij-perevodchik-teksta-na-php-cherez-google-translate.html

    Perevedi_na_PHP, 17 Марта 2019

    Комментарии (53)
  5. Python / Говнокод #25451

    +2

    1. 1
    int(data[:4][::-1].encode('hex'),16)

    Кто-то не знал про struct

    syoma, 16 Марта 2019

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

    +1

    1. 1
    https://habr.com/ru/sandbox/127860/

    3_dar, 16 Марта 2019

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

    +1

    1. 1
    #define BSWAP16(x) ( (uint16_t)(((uint32_t)x)*(1 | 1 << 16) >> 8) )

    j123123, 15 Марта 2019

    Комментарии (158)
  8. Куча / Говнокод #25448

    +2

    1. 1
    2. 2
    error_logger:format("Cannot force master when other "
                                  "node is up and is not a forced slave",[]),

    Overriding leader election в случае disaster recovery это тот ещё BDSM.

    CHayT, 13 Марта 2019

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