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

    +154

    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
    include "./include/db.conf.php";
    $con = mysql_connect($DB["host"],$DB["user"],$DB["pass"]) or die ("could not connect:".mysql_error());
    mysql_set_charset('utf8');
    mysql_select_db($DB["dbName"]) or die ("could not connect:".mysql_error());
    
    $hash = $_GET['hash'];
    $login = $_GET['login'];
    echo "SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'";
    
    $query = mysql_query("SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'") or die ("MYSQL error".mysql_error());
    
    if ($query) {
        while($row = mysql_fetch_array($query)) {
        echo row['id'];}
                
    $query = mysql_query("UPDATE reg SET commit=1 WHERE id=".row['id'])
         or die ("MYSQL error".mysql_error());}

    Знакомая поделилась шедевром. Так, конечно, можно... но в общем комментарии излишни.
    Да, форматирование оригинала сохранено.

    0rt, 16 Июня 2011

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

    +86

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public static String hello()
    	{
    		String s = "";
    		s += "Добро пожаловать на наш сайт.";
    		return s;
    	}

    redenemy, 16 Июня 2011

    Комментарии (9)
  3. JavaScript / Говнокод #6961

    +163

    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
    // Checks if the passed input's value is nothing. 
    function isEmptyText(theField) 
    {     
    // Copy the value so changes can be made..     
    var theValue = theField.value;       
    // Strip whitespace off the left side.     
    while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
            theValue = theValue.substring(1, theValue.length);
         // Strip whitespace off the right side.
         while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
            theValue = theValue.substring(0, theValue.length - 1);
           if (theValue == '')
            return true;
         else
            return false;
      }
    ...
    function in_array(variable, theArray) 
    {
         for (var i in theArray)
            if (theArray == variable)
               return true;
           return false;
    }

    zomg, 16 Июня 2011

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

    +125

    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
    protected string getUpdateNotesDE(string fieldNameAlias, string fieldName, string fieldValue, ASPxDateEdit newValue)
            {
                if (isSaveField("fieldName"))
                {
                    if (fieldValue != "")
                        return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = " + Convert.ToDateTime(fieldValue).ToString("dd/MM/yyyy") + ", New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                    else
                        if (newValue.Text != "")
                            return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = , New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                }
                return "";
    
            }
    
     protected Boolean isSaveField(string fieldName)
            {
                if (locCom.getVisible(fieldName))
                    return true;
                return false;
            }
    
     public bool getVisible(string fldName)
                {
                    Boolean showall = Convert.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Show-all-fields"));
                    if (showall) return true;
    
                    if (fldAccess.Tables.Count == 0) return false;
    
                    foreach (System.Data.DataRow item in fldAccess.Tables[0].Rows)
                    {
                        if (item["fieldname"].ToString().Replace('@', 'a').Replace("%", "percent").Replace("$", "dollar").ToLower() == fldName.ToLower())
                            return Convert.ToBoolean(item["visible"]);
                    }
                    return false;
                }

    особенно доставляет
    protected string getUpdateNotesDE(string fieldName){
    if (isSaveField( !!! "fieldName" !!!)){}
    }

    valorkin, 15 Июня 2011

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

    +162

    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
    public function save() {
            try {
                try {
                    $this->create();
                } catch (Exception $e) {
                    //probably dulplicate
                    $this->update();
                }
            } catch (Exception $e) {
                logger::error($e);
            }
    
        }

    try-catch много не бывает

    super, 15 Июня 2011

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

    +129

    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
    public void ReadFromFile()
    {
    	LoadIntervals = new TimeIntervals(Color.Black);
    	StreamReader tReader = null;
    	tReader = File.OpenText("DefaultIntervals");
    	string income = null;
    	while ((income = tReader.ReadLine()) != null)
    	{
    		// string income = tReader.ReadLine();
    		string colorR = null; string colorG = null; string colorB = null; string colorA = null; string interval = null;
    		int i = 0;
    		for (i = 4; i < income.Length; i++)
    		{
    			if (income[i] != ',')
    			{
    
    				interval += income[i];
    			}
    			else { break; }
    		}
    
    		for (int a = i + 10; a < income.Length; a++)
    		{
    			if (income[a] != ',')
    			{
    				colorA += income[a];
    			}
    			else
    			{
    
    				for (int r = a + 4; r < income.Length; r++)
    				{
    					if (income[r] != ',')
    					{
    						colorR += income[r];
    					}
    					else
    					{
    						for (int g = r + 4; g < income.Length; g++)
    							if (income[g] != ',')
    							{
    								colorG += income[g];
    							}
    							else
    							{
    								for (int b = g + 4; b < income.Length; b++)
    									if (income[b] != ',')
    									{
    										if (income[b] != ']')
    											colorB += income[b];
    									}
    									else
    									{
    										break;
    									}
    								break;
    							}
    						break;
    					}
    				}
    				break;
    			}
    		}
    		TimePoint tp = new TimePoint(Convert.ToDouble(interval), Color.FromArgb(Convert.ToInt32(colorA), Color.FromArgb(Convert.ToInt32(colorR), Convert.ToInt32(colorG), Convert.ToInt32(colorB))));
    		LoadIntervals.Add(tp);
    	}
    
    	tReader.Close();
    	Intervals = LoadIntervals;
    }

    Так мы парсим файл конфигов вида. (Формат придуман автором кода)
    Int=3,Color [A=223, R=253, G=4, B=38]
    Int=10,Color [A=255, R=86, G=86, B=185]
    Int=20,Color [A=200, R=255, G=215, B=0]
    Int=50,Color [A=200, R=255, G=165, B=0]

    lomomike, 15 Июня 2011

    Комментарии (49)
  7. Java / Говнокод #6957

    +85

    1. 1
    boolean ROLLBACK = new Boolean(false).booleanValue();

    И это пишет тимлид (сеньор) в моей конторе

    Loord, 15 Июня 2011

    Комментарии (17)
  8. PHP / Говнокод #6956

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function date_preobr($date, $ind=0) {
    $date1=substr($date, 8, 2); $date21=substr($date, 5, 2); $date3=substr($date, 0, 4);
    if ($ind==0) $data=$date1.".".$date21.".".$date3;
    elseif ($ind==1) $data=$date1.".".$date21.".".substr($date3, 2, strlen($date3)-2);
    elseif ($ind==2) {switch ($date21) {case "01":$date21="января";break;case "02":$date21="февраля";break;
    case "03":$date21="марта";break;case "04":$date21="апреля";break;case "05":$date21="мая";break;
    case "06":$date21="июня";break;case "07":$date21="июля";break;case "08":$date21="августа";break;
    case "09":$date21="сентября";break;case "10":$date21="октября";break;case "11":$date21="ноября";break;
    case "12":$date21="декабря";break;} $data=$date1." ".$date21." ".$date3;}
    return $data;}

    Были даты, есть дата, будут даты.
    Привожу в первозданном виде.

    De-Luxis, 15 Июня 2011

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

    +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
    if (body.ToLower().Contains("pr") || 
                    subject.Contains("PM") ||
                    subject.Contains("pm") ||
                    subject.Contains("Pm") ||
                    subject.Contains("pM") ||
                    subject.Contains("PMR") ||
                    subject.Contains("prs") || 
                    subject.ToLower().Contains("prt") ||
                    subject.ToLower().Contains("prm") ||
                    subject.ToLower().Contains("pmt") ||
                    subject.ToLower().Contains("pmk") ||
                    subject.ToLower().Contains("pml") ||
                    subject.ToLower().Contains("pal"))
                {
                    result = true;
                }

    Пишут друзья из Норвегии

    jenik15, 15 Июня 2011

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

    +70

    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
    import java.util.Random;
    public class A {
    	public static void main(String args[]) {
    		int minimalSuccessTime = Integer.MAX_VALUE;
    		int maximalSuccessTime = Integer.MIN_VALUE;
    		for(int i = 0; i < 10000; i++) {
    			Random rnd = new Random();
    			boolean state = rnd.nextBoolean();
    			final byte prisonersCount = 100;
    			boolean prisoners[] = new boolean[prisonersCount];
    			byte prisonersCounted = 1;
    			int daysPassed = 0;
    			while(true) {
    				daysPassed++;
    				int tmp = rnd.nextInt(prisonersCount);
    				if(tmp == 0) {
    					if(state) {
    						state = false;
    						prisonersCounted++;
    						if(prisonersCounted == prisonersCount) {
    							break;
    						}
    					}
    				} else {
    					if(!state && !prisoners[tmp]) {
    						state = true;
    						prisoners[tmp] = true;
    					}
    				}
    			}
    			if(daysPassed < minimalSuccessTime) {
    				minimalSuccessTime = daysPassed;
    			}
    			if(daysPassed > maximalSuccessTime) {
    				maximalSuccessTime = daysPassed;
    			}
    		}
    		System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
    		System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
    	}
    }

    One hundred prisoners have been newly ushered into prison. The warden tells
    them that starting tomorrow, each of them will be placed in an isolated cell,
    unable to communicate amongst each other. Each day, the warden will choose
    one of the prisoners uniformly at random with replacement, and place him in
    a central interrogation room containing only a light bulb with a toggle switch.
    The prisoner will be able to observe the current state of the light bulb. If he
    wishes, he can toggle the light bulb. He also has the option of announcing that
    he believes all prisoners have visited the interrogation room at some point in
    time. If this announcement is true, then all prisoners are set free, but if it is
    false, all prisoners are executed.
    The warden leaves, and the prisoners huddle together to discuss their fate.
    Can they agree on a protocol that will guarantee their freedom?

    guest2011, 14 Июня 2011

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