1. PHP / Говнокод #14212

    +153

    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
    <?php
    sfConfig::set('show_counters', true);
    /**
     * Lite
     *
     * @category Symfony
     * @package Plugins
     * @subpackage liteSearchsite
     * @author 
     * @since 12.11.2008
     * @version $Id: actions.class.php 28664 2011-03-15 13:14:49Z ringtail $
     */
    
    /**
     * class liteSearchsiteActions. Функции для работы с поиском
     *
     * @category Symfony
     * @package Plugins
     * @subpackage liteSearchsite
     * @author Tretyakov Ilya <[email protected]>
     * @version $Id: actions.class.php 28664 2011-03-15 13:14:49Z ringtail $
     */
    class liteSearchsiteActions extends sfActions
    {
      protected $searchsite;
      protected $search_server = 'http://217.148.52.134:17000/';
    
      /**
       * конструктор
       *
       * @see sfComponent
       */
      public function __construct($context, $moduleName, $actionName)
      {
        $this->searchsite = new liteSearchsite();
        parent::__construct($context, $moduleName, $actionName);
      }
    
      /**
       * Поиск. главная
       *
       * @param unknown_type $request
       */
      public function executeIndex($request)
      {
        if ($request) {
          $page = $request->getParameter('id');
          $this->text = htmlspecialchars($request->getParameter('search_text'));
          $reqid = $request->getParameter('reqid');
          $page = $request->getParameter('p');
          $numdoc = $request->getParameter('numdoc');
    
        }
        if (!$page) $page = 0;
    
        if (!$this->searchsite->checkServer($this->search_server)) { throw new sfException('Ахтунг!'); }
        if (!1) {
          $this->search_work = 0;
        } else
        if ($this->searchsite->uploadXml($this->search_server, $this->text, $reqid, $page, $numdoc)) {
    
          $this->pages_found = $this->searchsite->getCountItem();
          $this->start_page = $this->searchsite->getStartPage();
    
          $this->pages_found_word = $this->searchsite->getWordLinks();
          $this->reqid = $this->searchsite->getRegId();
          $this->pages = $this->searchsite->getPages();
          $this->count_results = $this->searchsite->getDifPages();
    
          if ($this->pages) {
            $this->nextpagelink = $this->searchsite->getLinkNextPage();
            $this->prepagelink = $this->searchsite->getLinkPrePage();
          }
    
          $this->search_work = 1;
    
          if (!$this->pages_found) {
            $this->no_result = 1;
            $this->pages_found = 0;
          } else {
            $this->no_result = 0;
    
            $this->list = $this->searchsite->getList($page);
    
            //пересчитаем
            //$this->pages_found = $this->searchsite->getCountItem();
            //$this->searchsite->setCountPages();
            //$this->pages_found_word = $this->searchsite->getWordLinks();
            //$this->pages = $this->searchsite->getPages();
            //$this->count_results = $this->searchsite->getDifPages();
    
            if ($this->pages) {
              $this->nextpagelink = $this->searchsite->getLinkNextPage();
              $this->prepagelink = $this->searchsite->getLinkPrePage();
            }
          }
        } else {
          $this->search_work = 0;
        }
      }

    kix, 11 Декабря 2013

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

    +15

    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
    if( (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||
                (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||
    
               (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) ||
               (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)||
    
               (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||
               (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||
    
               ...
    
            {
                int i; int e;
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 0;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 1;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 2;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 3;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 4;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 5;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 6;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 7;
    
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 8;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 9;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 10;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 11;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 12;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 13;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 14;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 15;
    
                ...
    
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 40;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 41;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 42;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 43;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 44;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 45;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 46;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 47;
    
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 0; // Bracers
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) e = 1; // Hands
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) e = 2; // Sword
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) e = 3; // Off hand
    
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 4; // Helmet
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) e = 5; // Chest
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)  e = 6; // Legs

    https://github.com/LaurentGomila/SFML/wiki/Tutorial%3A-Basic-Inventory-System

    Crazy_penguin, 11 Декабря 2013

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

    +128

    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
    object Point2D {
    
      type Point2D = Object {def apply(method: Method): method.type#signature}
    
      trait Method {
        type signature
      }
    
      object ToString extends Method {
        override type signature = () => String
      }
    
      object GetX extends Method {
        override type signature = () => Int
      }
    
      object SetX extends Method {
        override type signature = (Int) => Point2D
      }
    
      def Point2D(x: Int, y: Int): Point2D = {
    
        class Dispatch {
    
          def apply(method: Method): method.signature = (method match {
            case ToString => () => s"($x, $y)"
            case GetX => () => x
            case SetX => (x: Int) => Point2D(x, y)
          }).asInstanceOf[method.signature]
    
        }
    
        new Dispatch
      }
    
    }

    LispGovno, 10 Декабря 2013

    Комментарии (26)
  4. JavaScript / Говнокод #14209

    +153

    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
    if (/mail\/\?r=mail\/message_list/gim.test(location.href)) {
    		var ihoho = $($('form')[1]).parent().clone(true);
    		var myNickName = $($('li.sep_bl:has("a[href*=\'/mysite/\']")').find("a")[0]).prop("title");
    		eval('var prrtrns = /<b style="color:navy;">' + myNickName + '<\\/b>/gim;');
    		$($('form')[1]).parent().remove();
    		$($('.blue_wrap_block')[0]).after(ihoho);
    		var xls = $($($('form')[1]).find("input[type*='submit']")[0]);
    		xls.prop('type', 'button');
    		xls[0].setAttribute('onclick', 'var temp_tT = this.parentNode.parentNode.texttT.value; var rrr = this.parentNode.parentNode.r.value;var sid = this.parentNode.parentNode.sid.value;var CK = this.parentNode.parentNode.CK.value;var texttT = this.parentNode.parentNode.texttT.value;var Link_id = this.parentNode.parentNode.Link_id.value;var user = this.parentNode.parentNode.user.value;$.ajax({type:"POST",url: "http://spaces.ru/mail/?",data: {r:rrr,user:user,CK:CK,sid:sid,Link_id: Link_id,texttT:texttT},success:function(){document.forms[1].texttT.value = "";}});');
    		xls[0].setAttribute('name', 'okletsgo');
    		xls[0].setAttribute('style', 'display:none');
    		$('#navi').before("<script></script>");
    		document.forms[1].setAttribute('onkeypress', 'function lovly(e) { if (e.keyCode == 87 && e.altKey) document.forms[1].texttT = temp_tT; if (e.keyCode == 13 && !e.shiftKey && !e.ctrlKey) document.forms[1].okletsgo.click(); } lovly(event)');
    		$('.t-bg3').each(function(i) {
    					$(this).html($(this).html().replace(/<b style="color:darkmagenta;">Я<\/b>/gim, '<b style="color:navy;"><img src="http://spaces.ru/i//man_on.gif" alt="(ON)"/> <span style="text-decoration:underline">' + myNickName + '</span></b>').replace("<div class=\"overfl_hid service_links_block service_links_block_top clear\">", "<div style='display:none'>"));
    		}); //replace("<div class=\"left font0 avatar_wrap padd_right\">", '<div style="display:none">').
    		var reloadedMail = function(data) {
    			var dt = '';
    			$($(data).find("form")[1]).parent().each(function() {
    				dt = this.outerHTML;
    			});
    			data = data.replace(dt, "");
    			$(data).find('.t-bg3').each(function(i) {
    				if ($(this).html().replace(/Link_id=([0-9]+)/gim) != $($('.main').find('.t-bg3')[i]).html().replace(/Link_id=([0-9]+)/gim)) 
    				{
    					$($('.main').find('.t-bg3')[i]).html($(this).html().replace(/<b style="color:darkmagenta;">Я<\/b>/gim, '<b style="color:navy;"><img src="http://spaces.ru/i//man_on.gif" alt="(ON)"/> <span style="text-decoration:underline">' + myNickName + '</span></b>').replace("<div class=\"overfl_hid service_links_block service_links_block_top clear\">", "<div style='display:none'>"));
    					if ($(this).html().match(prrtrns) && settings.ajaxMailNotifications) {
    						$('#navi').before('<audio preload="auto" autoplay src="http://driverjs.webservis.ru/income.ogg"></audio>');
    					}
    				}
    			});
    		}
    		var reloadMail = function() {
    			$.ajax({
    				url: location.href,
    				success: reloadedMail
    			});
    			setTimeout(reloadMail, settings.ajaxTimeout);
    		}
    		reloadMail();
    	}

    Что? Разработчики сайта не сделали отправку/принятие сообщений на AJAX?!
    Поправим! Юзерскрипт порешает все.
    //P.S. ЭТО КАК-ТО работает. Правда.

    Efog, 10 Декабря 2013

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

    +78

    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
    private int compareDates(java.sql.Date date1, java.sql.Date date2) {
    
    if (date1.getYear() < date2.getYear())
    return 1;
    
    if (date1.getYear() > date2.getYear())
    return -1;
     
    if (date1.getMonth() < date2.getMonth())
    return 1;
    
    if (date1.getMonth() > date2.getMonth())
    return -1;
     
    if (date1.getDate() < date2.getDate())
    return 1;
    
    if (date1.getDate() > date2.getDate())
    return -1;
     
    return 0;
    }

    Сравнение двух дат

    iboken, 10 Декабря 2013

    Комментарии (12)
  6. JavaScript / Говнокод #14207

    +148

    1. 1
    $('#navi').before('<audio autoplay src="http://driverjs.webservis.ru/income.wav"></audio>');

    Я, конечно, понимаю, что это нифига не форум программистов. Но все-таки, может найдется X-перт, который скажет мне, какого хера этот код работает, только если я предварительно зайду на адрес звука и нажму плей? Т.е. без кэшированного звука воспроизведения нет. Opera/Chrome/Firefox.

    Efog, 10 Декабря 2013

    Комментарии (43)
  7. PHP / Говнокод #14206

    +154

    1. 1
    2. 2
    if (!empty($_GET[ret])) $_SESSION[ret] = $_GET[ret];
    else if (!empty($_SESSION[ret])) $_GET[ret] = $_SESSION[ret];

    Из разряда черной магии

    psycho-coder, 10 Декабря 2013

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

    −110

    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
    struct testStruct
    {
        char test[1024*1024*110];
    };
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        logMemUsage();
        testStruct* test = new testStruct();
        NSLog(@"test mem: %d", sizeof(test));
        logMemUsage();
        delete test;
        logMemUsage();
    
       <...>
    }

    Особенности управления памятью в iOS 6.
    Без этого фрагмента на слабых устройствах может ВНЕЗАПНО понизить объём доступной для приложения памяти со 120 до 90мб.

    Почему-то не порнографических ассоциаций не возникает.

    krypt, 10 Декабря 2013

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

    +153

    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
    php_sapi_name() === 'cli' or exit('Only CLI mode allowed');
    
    getenv('API_HOST') or exit(<<<EOT
    
      To run tests you should setup "API_HOST" environment variable.
      Try follow in bash command line:
    
      $ export API_HOST=<api_host>
      cd path/to/tests
      php direct_report_problem.php
    
    
    EOT
    );
    
    defined('API_ENDPOINT') || define('API_ENDPOINT', getenv('API_HOST') . '/webservice/index.php');
    
    $method = API_ENDPOINT . '?op=...';
    
    $describe = function ($msg, $test) {
        printf("\n\n[%s]\n\n%s\n\n", $msg, shell_exec($test()));
        sleep(2);
    };
    
    $describe('Cannot upload empty report', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report note', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report image', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload all data direct report note, image, sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' -F [email protected]'
        . ' -F [email protected]'
        . ' ' . $method;
    });

    __proto__, 10 Декабря 2013

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

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function lastDay($month, $year) {
        if ($month != 12) {
            $m = $month + 1;
            $y = $year;
        } else {
            $m = 1;
            $y = $year + 1;
        }
        return strftime("%d", mktime(0, 0, 0, $m, 0, $y));
    }

    Оригинальный и дофига понятный способ получить последний день текущего месяца.

    anton0xf, 09 Декабря 2013

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