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

    +165

    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
    65. 65
    66. 66
    67. 67
    68. 68
    if ($date_reg_2!="0000-00-00 00:00:00")
      	{
      	$start_date_array_2 = explode (" ",$date_reg_2);
      	$start_time_array_2 = explode (":",$start_date_array_2[1]);
      	$time_base_2 = $start_time_array_2[0].":".$start_time_array_2[1];
      	$request_date_start_2 = $start_date_array_2[0]." ".$time_base_2;
      	$request_time_start_2 = $time_base_2.":00";
      	}
      	 if($date_do_array[0]!="0000-00-00")
            {
            $request_date_start_2 = $date_do_array[0]." ".$time_do_array[0].":".$time_do_array[1];
            }
    	if (date("Y-m-d H:m")>$request_date_start_2)
    	{
    	if ($con_from_bill=='0') $color = "#FED0D0";
    	elseif ($time_online<$request_time_start_2&&$con_from_bill==0) $color = "#CAF0BC";
    	else if ($con_from_bill==1||$status==5) $color = "#CAF0BC";
    	else $color = "#FED0D0";
            }
            else
            {
            if ($date_perezvon_array[0]!='0000-00-00' && $perezvon=='0')$color = "#F6FC48";
            else $color = "#ffffff";
            
            }
            
             if ($date_do_array[0]!="0000-00-00") $time_base = $time_do_array[0].":".$time_do_array[1];
            else $time_base =$start_time_array[0].":".$start_time_array[1];
             if($date_do_array[0]!="0000-00-00" && $start_date_array[0]==$date[$w])
            {
            $color = "#D2EAFD";
            }
            else $color = $color;
            
             if (date("Y-m-d")>$day_today)
    	{
    	if ($con_from_bill=="0" && $status != 5) $color = "#F51F1F";
    	else $color = "#CAF0BC";
    	
    	}
    	else  $color= $color;
        
            $url_edit = "/start/incoming_info.php?callid=$callid&teamid=$teamid&from=from_connect";
        if ($date_do!="0000-00-00 00:00:00" && $date[$w]==$start_date_array[0])$ahref = "<a href=\"#\" class=\"hint\" onMouseover=\"showhint('$info_request', this, event, '250px')\"><span style=\"background-color:$color;font-size:8pt;font-family:arial,helvetica,sans serif;color: #969595;font-weight:normal;\">";
            else $ahref="<A HREF=\"javascript:;\" onClick=\"openHorWin('$url_edit')\" class=\"link_incoming\" style=\"background-color:$color;width:100%\"><span style=\"color:$text_color\">";
      if($status!="33" && $status!="34") $time_info = $time_info."<nobr>$ahref $time_base - $incoming </a></span><nobr><br>";
      	else
      	{				
    		
    		if ( $status == 34 && $cancel == 1 ) $color = "#FF8A42";
    		else if      ( $connect_poe == 0 )  $color = "#72AFFF";
    		else if ( $connect_poe == 1 )  $color = "#CAF0BC";
    		else      					   $color = "#FED0D0";
    		
    		if ( $status == "33" )
    	        $url_edit = "/start/psevdo.php?do=info&callid=$callid";
    		else
    			$url_edit = "/start/poe.php?callid=$callid";
    	
      	$start_date_array_33 = explode (" ",$date_reg_2);
      	$start_time_array_33 = explode (":",$start_date_array_33[1]);
      	$time_base_33 = $start_time_array_33[0].":".$start_time_array_33[1];
      	 $ahref="<A HREF=\"$url_edit\"   onClick=\"openHorWin2()\" target=\"displayWindow\"   class=\"link_incoming\" style=\"background-color:$color;width:100%;text-decoration:none;\"><span style=\"color:$text_color\">";
        	 $comments = substr($comments,0,20);
    		 $incoming = $incoming == "., -0" ? $comments : $incoming;
        	 $time_info = $time_info."<nobr>$ahref $time_base - $incoming</a></span><nobr><br>";
      	}
      	}

    Долго и упорно пытался вставить свой "если" в этот код никак не мог найти куда лучше его вставить :-D
    Люди не пишита так никогда, кому то потом придется в этом ковырятся...

    jackkum, 30 Августа 2010

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

    +171

    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
    TCHAR szPort[7];
    
    	strcpy(m_szAddress,szAddress);
        
        // INITIALIZE RETURN VALUE TO INDICATE COM PORT NOT INITIALIZED 	
    	bool bRetVal = false;
    	
    	switch( byCOMPort )
    	{
    	case 1:
    		_tcscpy(szPort,_T("COM1:"));
    		break;
    	case 2:
    		_tcscpy(szPort,_T("COM2:"));
    		break;
    	case 3:
    		_tcscpy(szPort,_T("COM3:"));
    		break;
    	case 4:
    		_tcscpy(szPort,_T("COM4:"));
    		break;
    	}

    Вот так гибко можно отрывать любой из четырёх COM портов.

    slavap, 30 Августа 2010

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

    +142

    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
    using System;
    using System.IO;
    using System.IO.Compression;
    using System.Text;
    using System.Net;
    
    class Data : IDisposable
    {
        public void Dispose() { }
    
        MemoryStream MemStr;
    
        public Data(string Url)
        {
            UnZipFile(Url);
        }
    
        MemoryStream DownloadData(string Url)
        {
            using (WebClient Wc = new WebClient())
            {
                MemStr = new MemoryStream(Wc.DownloadData(Url));
            }
    
            return MemStr;
        }
    
        void UnZipFile(string Url)
        {
            MemoryStream MemStr = DownloadData(Url);
    
            using (GZipStream ZipStr = new GZipStream(MemStr, CompressionMode.Decompress))
            {
                byte[] P = new byte[ZipStr.BaseStream.Length];
                ZipStr.BaseStream.Read(P, 0, P.Length);
                FileStream Fs = new FileStream("TmpFile.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                Fs.Write(P, 0, P.Length);
                Fs.Flush();
            }
        }
    }
    
    class Program
    {
        static void Main()
        {
            while (true)
            {
                Console.Write("\nPlease, insert link to download ZIP-file >> ");
                string Abc = Console.ReadLine();
    
                using (Data Obj = new Data(Abc)) ;
            }
        }
    }

    sergylens, 29 Августа 2010

    Комментарии (36)
  4. C++ / Говнокод #4124

    +177

    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
    namespace markup 
    {
        // case sensitive string equality test
        // s_lowcase shall be lowercase string
        inline bool equal(const char* s, const char* s1, size_t length)
        {
          switch(length)
          {
            case 8: if(s1[7] != s[7]) return false;
            case 7: if(s1[6] != s[6]) return false;
            case 6: if(s1[5] != s[5]) return false;
            case 5: if(s1[4] != s[4]) return false;
            case 4: if(s1[3] != s[3]) return false;
            case 3: if(s1[2] != s[2]) return false;
            case 2: if(s1[1] != s[1]) return false;
            case 1: if(s1[0] != s[0]) return false;
            case 0: return true;
            default: return strncmp(s,s1,length) == 0;
          }
        }
    ...

    rat4, 29 Августа 2010

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

    +144

    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
    <?php 
    date_default_timezone_set('Europe/Kiev');
    header('Content-Type: text/html; charset=utf-8');
    include_once 'simplehtmldom/simple_html_dom.php';
    
    /* формирование урл */ 
    $url="http://ru.wikipedia.org/wiki/"; 
    $date_today = date("j"); 
    $down="_"; 
    $test="%D0%B0%D0%B2%D0%B3%D1%83%D1%81%D1%82%D0%B0"; 
    $full=$url.$date_today.$down.$test; 
    echo $full; 
    
    ?>
    
    <hr>
    
    <?
    $html = file_get_html($full);
    
    foreach($html->find('p') as $element) 
           echo $element->plaintext . '<br>';
    
    
    $html->clear(); 
    unset($html);
    ?>

    Суть: парсить на свой сайт в зависимости от даты первую строку из википедии о том какой сегодня день. Сей код тянет следующее:

    Состояниеотпатрулирована
    29 августа — 241-й день года (242-й в високосные годы) в григорианском календаре. До конца года остаётся 124 дня.
    См. также: Категория:Праздники 29 августа
    Дата дана по новому стилю[1]:
    См. также: Категория:События 29 августа
    См. также: Категория:Родившиеся 29 августа
    См. также: Категория:Умершие 29 августа


    а нужна только вторая строка. Средствами самого simplehtmldom на сколько я понял нельзя ограничить вывод.
    Возможно ли придумать какой-нить костыль к echo, которое выводит массив $element ?

    dimiork, 29 Августа 2010

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

    +164

    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
    void load(char *file)
    	{
    		reader = fopen((const char*)file, "r+b");
    		if(reader)
    		{
    			byte *b = (byte*)malloc(sizeof(byte));
    			fread(b, sizeof(byte), 1, reader);
    			if(b == 0x0)
    			{
    				int *wh_val = (int*)malloc(sizeof(int) * 2);
    				fread(wh_val, sizeof(int), 2, reader);
    				width = *wh_val;
    				height = *(wh_val + 1);
    				pixels = (Color**)malloc(sizeof(Color*) * width);
    				for (int i = 0; i < width; ++i)
    				{
    					*(pixels + i) = (Color*)malloc(sizeof(Color) * height);
    					for (int j = 0; j < height; ++j)
    					{
    						byte *rgb = (byte*)malloc(sizeof(byte) * 3);
    						fread(rgb, sizeof(byte), 3, reader);
    						Color c = Color(0);
    						c.red = *(rgb) / 255.0;
    						c.green = *(rgb + 1) / 255.0;
    						c.blue = *(rgb + 2) / 255.0;
    						*(*(pixels + i) + j) = c;
    					}
    				}
    			}
    		}
    	}

    Пишу я код ни о чем не задумываясь, а когда задумался, уже было это.
    ЗЫ. эта ф-ция читает картинку из спец. файла.

    psina-from-ua, 28 Августа 2010

    Комментарии (46)
  7. C# / Говнокод #4121

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    string mailTo = ((Config.GetSetting("AdminNotifications_EmailAddress") == null) ||
                                 (Config.GetSetting("AdminNotifications_EmailAddress").Length <= 0))
                                    ? Globals.GetHostPortalSettings().HostSettings["SMTPPassword"].ToString()
                                    : Config.GetSetting("AdminNotifications_EmailAddress");

    из модуль для DotNetNuke

    Coffeeholic, 28 Августа 2010

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

    +158

    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
    const char* def = "DEFINE";
    while(*def && (m_position != m_end) && (*m_position == charT(*def)))
      ++m_position, ++def;
    if((m_position == m_end) || *def)
    {
      // Rewind to start of (? sequence:
      --m_position;
      while(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_open_mark) --m_position;
      fail(regex_constants::error_perl_extension, m_position - m_base);
      return false;
    }
    re_brace* br = static_cast<re_brace*>(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
    br->index = 9999; // special magic value!
    if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
    {
      // Rewind to start of (? sequence:
      --m_position;
      while(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_open_mark) --m_position;
      fail(regex_constants::error_perl_extension, m_position - m_base);
      return false;
    }

    Фрагмент из boost::regex, "magic value!", улыбнуло =]
    basic_regex_parser.hpp : 2160

    rudvil, 28 Августа 2010

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

    +156

    1. 1
    if($urate['time'] < $time and count($urate) > 0) { // Если в течении суток голосовали и есть записи - фиг

    Мартин, 28 Августа 2010

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

    +148

    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
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    struct _elem
    {
        int x, y, z, num;
        bool r;
        long long square;
        void read(int i)
        {
            cin >> x >> y >> z;
            num = i;
            square = 0;
        }
    
        friend bool operator<(_elem a, _elem b)
        {
            if ( a.z == b.z)
            {
                return a.r == true;
            }
            else
            {
                return a.z < b.z;
            }
        }
    };
    
    _elem mas[500000];
    bool vis[500000];
    int main()
    {
        int N, W, L;
        cin >> N >> W >> L;
    
        for ( int i = 0; i < N; i++)
        {
            mas[i].read(i);
            mas[i].r = false;
            mas[i + N].read(i);
            mas[i + N].r = true;
            mas[i].square = mas[i + N].square = abs(mas[i].x - mas[i + N].x) * abs(mas[i].y - mas[i + N].y);
            vis[i] = vis[i + N] = false;
        }
    
        sort(mas, mas + 2 * N);
    
        long long square = 0;
        int count = 0;
        int min = -1;
        for ( int i = 0; i < 2 * N; i++)
        {
            if ( mas[i].r == false)
            {
                square += mas[i].square;
                count++;
            }
            else
            {
                square -= mas[i].square;
                count--;
            }
            if ( square == W * L)
            {
                if (min == -1 || count < min)
                {
                    min = count;
                }
            }
        }
       
        if ( min == -1)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
            count = 0;
            square = 0;
            int i = 0;
            while (count != min || square != W * L)
            {
                if ( mas[i].r == false)
                {
                    square += mas[i].square;
                    count++;
                    vis[mas[i].num] = true;
                }
                else
                {
                    square -= mas[i].square;
                    count--;
                    vis[mas[i].num] = false;
                }
                i++;
            }
            cout << min << endl;
            }
         }
    }

    hromjo, 28 Августа 2010

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