1. Лучший говнокод

    В номинации:
    За время:
  2. C# / Говнокод #2182

    +135.6

    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
    public class Singleton<T> where T : class
        {
            private static T _Instance = null;
            protected static readonly object locker = new object();
    
            public static T Instance
            {
                get
                {
                    if (_Instance == null)
                    {
                        lock (locker)
                        {
                            if (_Instance == null)
                            {
                                ConstructorInfo[] info = typeof(T).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic);
                                if (info.Length > 0)
                                    _Instance = (T)info[0].Invoke(null);
                            }
                        }
                    }
                    return _Instance;
                }
            }
    
            protected Singleton() { }
    
            static Singleton() { }
    
        }

    Вот такой вот универсальный сиглтон нашел в проекте

    sven47, 26 Ноября 2009

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

    +135.6

    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
    for(int time = 0; time < 24 * 3600;  time++)
    {
    	for(int i = 0; i < arr.Length; i++) 
    		if(time >=toSec(arr[i]) && time < toSec(dep[i]))
    		{
    			if(time >= toSec("18:00:00") && time <= toSec("23:59:59"))
    				x++;
    			else if (time >= toSec("00:00:00") && time <= toSec("05:59:59"))
    				x++;
    			else
    				s++;
    			break;
    		}

    guest, 13 Апреля 2009

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

    +135.5

    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
    class PliggMailer{
    
    	var $subject = '';
    	var $body = '';
    	var $from = '';
    	var $to = '';
    
    	function PliggMailer($subj = '', $body = '', $from = '', $to = '', $cc = '', $bcc = ''){
    
    		if($subj != ''){$this->subject = $subj;}
    		if($body != ''){$this->body = $body;}
    		if($from != ''){$this->from = $from;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    
    	}

    Блоговый движок pligg жжот.

    guest, 11 Марта 2009

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

    +135.4

    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
    public static BitmapImage ConvertBitmapToBitmapImage(Bitmap bitmap)
            {
                var bitMapImage = new BitmapImage();
                var ms = new MemoryStream();
    
                try
                {
                    bitmap.Save(ms, ImageFormat.Bmp);
                    bitMapImage.BeginInit();
                    bitMapImage.StreamSource = ms;
                    bitMapImage.EndInit();
                }
                catch (NotSupportedException e)
                {
                    try
                    {
                        bitMapImage = new BitmapImage();
                        bitmap.Save(ms, ImageFormat.Png);
                        bitMapImage.BeginInit();
                        bitMapImage.StreamSource = ms;
                        bitMapImage.EndInit();
                    }
                    catch (NotSupportedException e2)
                    {
                        bitMapImage = new BitmapImage();
                        bitmap.Save(ms, ImageFormat.Bmp);
                        ms.Write(ms.ToArray(), 78, (int)(ms.Length - 78));
                        bitMapImage.BeginInit();
                        bitMapImage.StreamSource = ms;
                        bitMapImage.EndInit();
                    }
                }
    
                return bitMapImage;
            }

    wpf + System.Drawing + sql и хз что со всем этим делать )))))

    walash, 28 Декабря 2009

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

    +135.4

    1. 1
    2. 2
    3. 3
    while(1) {
     fork(); 
    }

    Зачем так жестоко...

    guest, 05 Июня 2009

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

    +135.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
    15. 15
    16. 16
    inline void clearbufshort (void *buff, unsigned int count, WORD clear)
    {
            if (!count)
                    return;
            SWORD *b2 = (SWORD *)buff;
            if ((int)b2 & 2)
            {
                    *b2++ = clear;
                    if (--count == 0)
                            return;
            }
            do
            {
                    *b2++ = clear;
            } while (--count);
    }

    Наткнулся на такой вот шедевр в коде ZDaemon. Это аналог memset, только заполняет не байтами, а словами.

    Кстати, там же рядом есть функция, запполняющая двойными словами:

    inline void clearbuf (void *buff, int count, SDWORD clear)
    {
    SDWORD *b2 = (SDWORD *)buff;
    while (count--)
    *b2++ = clear;
    }

    Arseniy, 13 Февраля 2010

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

    +135.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
    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
    protected void DuplicateFilterNameValidator(object source, ServerValidateEventArgs args)
        {
            string _filterName = FilterName.Text;
            SqlCommand command = new SqlCommand();
            SqlDataReader filterNameReader = null;
            try
            {
                SqlConnection connection = new SqlConnection(strConn);
                connection.Open();
                command.CommandText = "EventNotificationFilterSelectByName";
                command.Connection = connection;
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@filterName", _filterName));
                filterNameReader = command.ExecuteReader();
    
                if (filterNameReader.HasRows)
                {
                    args.IsValid = false;
                }
    
                if ((connection != null) & (connection.State == ConnectionState.Open))
                {
                    connection.Close();
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
    
        }

    omg...

    Sharp, 05 Февраля 2010

    Комментарии (10)
  9. Куча / Говнокод #2145

    +135.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?xml version="1.0" encoding="utf-8"?>
    
    < xmlns="*" xmlns:mx="http://www.adobe.com/2006/mxml">
        
    </>

    Это генерирует Flex Builder, если не указать, от какого компонента будет наследоваться вновь создаваемый компонент.

    Lavir_the_Whiolet, 16 Ноября 2009

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

    +135.2

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (Label ticketText in ticketFieldsToPrint)
    {
        g.DrawString(ticketText.Text, ticketFont, Brushes.Black, new PointF((Int32.Parse(iLeft.Text) * Int32.Parse(PPm.Text) / Int32.Parse(PPm.Text)) + ticketText.Left / Int32.Parse(PPm.Text), ((Int32.Parse(iTop.Text) * Int32.Parse(PPm.Text)) / Int32.Parse(PPm.Text)) + ticketText.Top / Int32.Parse(PPm.Text)));
    }

    Вывод всех лейблов на форме на печать.

    nolka4, 16 Октября 2009

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

    +135.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
    public string GetDollarKurs(string input)
    {
        string dol = "[.\\s]*<img height=\"11\" alt=\"Доллар США\" hspace=\"2\" src=\"/images/icon_dollar.gif\" width=\"11\" align=\"left\" vspace=\"2\" border=\"0\">Доллар \r\n\t\t\tСША</td>\r\n\t\t<td></td>\r\n\t\t<td class=\"digit\" align=\"right\">[\\s]*\\d+\\,\\d+[.\\s]*";
        MatchCollection Matches = Regex.Matches(input, dol);
        if (Matches.Count == 1)
        {
            string res = Matches[0].Value;
            res = res.Trim();
            res = res.Substring(res.LastIndexOf('>') + 1);
            return res;
        }
        else
            return "";
    }

    Функция для получения курса доллара, в input подаётся хтмл главной страницы сайта cbr.ru и парсится.
    А web-сервисы пусть кто-нибудь другой изучает... :o)

    Ordos, 06 Сентября 2009

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