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

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

    +75

    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
    private Connection getConnection() throws SQLException {
    		Connection conn = null;
    		try{
    			conn = DriverManager.getConnection(OnlineUsers.db,OnlineUsers.user,OnlineUsers.pass);
    		} catch (Exception e) {
    			log.severe(name + ": " + e.getMessage());
    		}
    		checkConnection(conn);
    		return conn;
    	}
    	
    	private boolean checkConnection (Connection conn) throws SQLException {
    		if (conn == null) {
    				log.severe("Could not connect to the database. Check your credentials in online-users.settings");
    			throw new SQLException();
    		}
    		if (!conn.isValid(5)) {
            	log.severe("Could not connect to the database.");
            	throw new SQLException();
            }
    		return true;
    	}
    	
    	private boolean execute(String sql) {
    		return execute(sql, null);
    	}
    	
    	private boolean execute(String sql, String player) {
    		Connection conn = null;
            PreparedStatement ps = null;
            try {
            	conn = getConnection();
            	ps = conn.prepareStatement(sql);
            	if (player != null && !player.equalsIgnoreCase("")) {
            		ps.setString(1, player);
            	}
            	
            	if (ps.execute()) {
            		return true;
            	}
            } catch (SQLException ex) {
            	log.severe(name + ": " + ex.getMessage());
            	String msg = name + ": could not execute the sql \"" + sql + "\"";
            	if (player != null ) {
            		msg += "    ?=" +player;
            	}
            	log.severe(msg);
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                    if (conn != null) {
                        conn.close();
                    }
                } catch (SQLException ex) {
                	log.severe(name + ": " + ex.getMessage());
                }
            }
            return false;
    	}

    Мартин, 02 Ноября 2011

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

    −101

    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
    def api_login() :
    	url = 'https://api.vk.com/oauth/authorize'
    	
    	values = {
    		'client_id' : '1998533',
    		'response_type' : 'token'
    		}
    	
    	headers = {
    		'User-Agent' : 'Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.9.168 Version/11.51',
    		'Cookie' : 'remixsid=' + sid
    		}
    	
    	try:
    		data = urllib.urlencode(values)
    		req = urllib2.Request(url, data, headers)
    		response = urllib2.urlopen(req)
    		res = response.read()
    		geturl = response.geturl()
    
    		if geturl != url :
    			reg = 'access_token=(.*?)&'
    			rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
    			m = rg.search(geturl)
    			if m:
    				token=m.group(1)
    				print 'API: login'
    				return token
    		else :
    			reg='\?hash=(.*?)&'
    			rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
    			m = rg.search(res)
    			
    			if m:
    				hash = m.group(0)
    				url = 'https://api.vk.com/oauth/grant_access'+hash+'client_id=1998533&redirect_uri=blank.html&response_type=token'
    				
    				req = urllib2.Request(url, '', headers)
    				response = urllib2.urlopen(req)
    				res = response.read()
    				geturl = response.geturl()
    
    				reg = 'access_token=(.*?)&'
    				rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
    				m = rg.search(geturl)
    				if m:
    					token = m.group(1)
    					print 'API: login'
    					return token
    	except Exception, detail:
    		print "Error ", detail
    
    def api(method, values = {}) :
    	url = 'https://api.vk.com/method/' + method + '.json'
    	
    	values.update({'access_token' : token})
    
    	headers = {
    		'User-Agent' : 'Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.9.168 Version/11.51',
    		'Cookie' : 'remixsid=' + sid
    		}
    	
    	try:
    		data = urllib.urlencode(values)
    		req = urllib2.Request(url, data, headers)
    		response = urllib2.urlopen(req)
    		res = response.read()
    		return res
    	except Exception, detail:
    		print "Error ", detail

    anonymouse587658967, 01 Ноября 2011

    Комментарии (4)
  4. Java / Говнокод #8387

    +75

    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
    private enum UpdateToken {
        W, A, F, D, H;
    
        private static final Pattern PATTERN = compilePattern(UpdateToken.class);
    }
    
    private static Pattern compilePattern(Class<? extends Enum> clazz) {
        StringBuilder builder = new StringBuilder("(");
        for (Enum enumConstant : clazz.getEnumConstants()) {
            if (enumConstant.ordinal() > 0) {
                builder.append("|");
            }
            builder.append(enumConstant.name());
        }
        builder.append(")");
        return Pattern.compile(builder.toString());
    }
    
    //и это добро вот так используется:
    
        if (!UpdateToken.PATTERN.matcher(token).matches()) {
            continue;
        }
        UpdateToken setupToken = UpdateToken.valueOf(token);

    https://github.com/aichallenge/aichallenge/blob/epsilon/ants/dist/starter_bots/java/AbstractSystemInputParser.java

    rat4, 01 Ноября 2011

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

    +100

    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
    {Podschet dlini}
    Reset(f1);
    kol:=0;
    while not eof(f1) do begin
    readln(f1,l);
    For i1:=1 to length(l) do if (l[i]='a')or(l[i]='A') or (l[i]='b')or(l[i]='B')
    or(l[i]='c')or(l[i]='C')or(l[i]=' ')or(l[i]='d')or(l[i]='D')
    or(l[i]='e')or (l[i]='E') or(l[i]='f') or(l[i]='F')
    or (l[i]='g')or (l[i]='G') or (l[i]='h')or(l[i]='H')
    or(l[i]='i')or(l[i]='I')or(l[i]='J')or(l[i]='j')
    or(l[i]='k')or(l[i]='K')or(l[i]='l')or(l[i]='L')
    or (l[i]='m')or (l[i]='M')or(l[i]='n')or(l[i]='N')
    or (l[i]='o')or(l[i]='O')or(l[i]='p')or(l[i]='P')
    or(l[i]='q')or(l[i]='Q')or (l[i]='r')or (l[i]='R')
    or(l[i]='S')or(l[i]='s')or(l[i]='t')or(l[i]='T')
    or(l[i]='v')or(l[i]='V') or(l[i]='w')or(l[i]='W')
    or(l[i]='u')or(l[i]='U')or(l[i]='x')or(l[i]='X')
    or(l[i]='y')or(l[i]='Y')or (l[i]='z')or(l[i]='Z') then
    kol:=kol+1;
    end;
    WriteLn('kol=',kol);

    Необходимо создать текстовый файл, содержащий исходную программу, а также подсчитать длину созданного файла.
    http://ithappens.ru/story/7652

    d_dev, 31 Октября 2011

    Комментарии (4)
  6. SQL / Говнокод #8316

    −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
    -- Create table
    create global temporary table REPLDATALOBS
    (
      dummy       VARCHAR2(1),
      table_name  VARCHAR2(30) not null,
      column_name VARCHAR2(30) not null,
      row_id      VARCHAR2(4000) not null,
      position    NUMBER not null,
      data        VARCHAR2(4000)
    )
    on commit delete rows;
    -- Create/Recreate primary, unique and foreign key constraints 
    alter table REPLDATALOBS
      add constraint C_REPLDATALOBS_PK primary key (ROW_ID, TABLE_NAME, COLUMN_NAME, POSITION);
    -- Grant/Revoke object privileges 
    grant select, insert, update, delete, references, alter, index on REPLDATALOBS to PUBLIC;

    Продакшн Oracle10g, PK из 4х элементов, а один из 4000 символов Т_Т блжад, что за жизнь ..........

    d4rw1n1s7, 27 Октября 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $(document).ready(function(){
    	var obj = $("#answers_list .answer_tool2");
    	if (obj.hasClass('act')) {
    		obj.removeClass('act');
    	} else {
    		$("#answers_list .answer_tool2").removeClass('act');
    		obj.addClass('act');
    	}
    });

    Строчка #6

    Tairesh, 27 Октября 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public function action_delete(){   
            if (ORM::factory($_GET['type'], $_GET['id'])->delete())        
                $arr[0] = array("text" => "ok");
            else
                $arr[0] = array("text" => "no");
                                                   
            echo json_encode($arr);                               
    }

    Метод контролера (kohana), который используется для ajax запросов. Хоть в нем ничего не проверяется, за то этот метод очень функциональный. С помощью GET request можно удалить из БД практически все!

    k1011, 27 Октября 2011

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

    +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
    bsz = (bsz + 3) & ~3L;
    
      tp->beg = alloc_malloc(bsz, tp->almark);
      tp->end = tp->beg + bsz;
      tp->cur = tp->beg;
      tp->aux = tp->beg;
    
      tp->mode = TAPE_MODE_IDLE;
      tp->err = FAKE_OK;
    
      tp->drv = drv;
      tp->info = NULL;
    
      ret = tp->drv->init(tp, argv);
    
      if (ret == FAKE_FAIL) {
        alloc_free_by_mark(almark);

    http://www.gamedev.ru/flame/forum/?id=153724&page=13#m190

    AnimeGovno-_-, 26 Октября 2011

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

    +75

    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
    /**
     * Workaround ObjectInputStream for maintaining backward compatibility with serialization.
     * 
     * In the future, please, please, PLEASE assign each serializable class an explicit serialVersionUID.
     * 
     */
    public final class DecompressibleInputStream extends ObjectInputStream {
    	private static final Logger logger = Logger.getLogger(DecompressibleInputStream.class);
    
        public DecompressibleInputStream(InputStream in) throws IOException {
            super(in);
        }
    
        protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
            ObjectStreamClass resultClassDescriptor = super.readClassDescriptor();
            Class<?> localClass;
            
            try {
                localClass = Class.forName(resultClassDescriptor.getName()); 
            } catch (ClassNotFoundException e) {
                logger.error("No local class for " + resultClassDescriptor.getName(), e);
                return resultClassDescriptor;
            }
            
            ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
            
            if (localClassDescriptor != null) { // only if class implements serializable
                final long localSUID = localClassDescriptor.getSerialVersionUID();
                final long streamSUID = resultClassDescriptor.getSerialVersionUID();
                
                if (streamSUID != localSUID &&
                		(localClass == ByteArraySerial.class || localClass == Vector2D.class)) {
                	// Workaround: check for serialVersionUID mismatch with two specific classes
                    logger.error(String.format("Overriding serialized class version mismatch for %s: " +
                    		"local serialVersionUID = %s, stream serialVersionUID = %s",
                    		localClass.getName(), localSUID, streamSUID));
                    resultClassDescriptor = localClassDescriptor; // Use local class descriptor for deserialization
                }
            }
            
            return resultClassDescriptor;
        }
    }

    Продукт использует в качестве бинарного формата сохранённых файлов встроенную сериализацию. При этом ранние версии полагались на встроенный serialVersionUID.

    Вот теперь приходится расхлёбывать. Наши воркэраунды - самые воркэраундные воркэраунды в мире.

    lucidfox, 24 Октября 2011

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

    +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
    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
    <script src=scripts.js></script>
    <?
    
        if (isset($remove) && $user1 !="selectuser"):  //to remove user from DB
    	print "Was updated sucsessfully: user '$user1' was removed<br>";
    	print "<font color=red>If You want to reload this page use <u>our 'Reload' button only</u></font>";
    	$query="delete from users where login=\"$user1\"";
            $result=mysql_query($query);     
    
       if (!isset($reloadme) ):
    
    
       //decremet when registered users removed users.txt
    	$file_loc="users.txt";
    	chmod ($file_loc,0755);
    	$newfile = fopen($file_loc, "r");
    	$file_contents = fread($newfile, filesize($file_loc));
            $file_contents=$file_contents-1;   //value contains how many users
    	$newfile = fopen($file_loc, "w+");
    	fwrite($newfile, "$file_contents");
    	fclose($newfile);
    	chmod ($file_loc,0700);       // end of adding data to file
    	endif;
       endif;   //end of reloadme
    //counting of users
    	$file_loc = "users.txt";
    //	chmod ($file_loc,0644);
    	$whattoread = fopen($file_loc, "r");
    	$file_contents = fread($whattoread, filesize($file_loc));
    	fclose($whattoread);
    //	chmod ($file_loc,0755);       // end of adding data to file
    //end of counting
    
    
    
        $query="select * from users order by id";
        $result=mysql_query($query);     // for first while	
        $result1=mysql_query($query);   // for second while
    	print "<table border=1 cellspacing=0 cellpadding=0 bordercolor=#007898><tr><td>";   //external table
    	print "<table border=0 cellspacing=2 cellpadding=2 width=590><tr><td>
    	<form action=$PHP_SELF method=post><select name=\"user1\" class=select1><option value=\"selectuser\"> Select user ";
        while($row=mysql_fetch_object($result)):	
    	print"<option value=\"$row->login\" style=\"background-color:#FFFFFF;\">$row->login";	
    	endwhile;
    	print "</select><br>
    	<input type=hidden name=remove>
    	<input type=hidden name=show>
    	<input type=hidden name=admin_login value=$admin_login_compare>";   // to enter one more time to login.php
    	print "<input type=hidden name=admin_password value=$admin_password_compare>"; // if ($admin_password!=$admin_password_compare) etc....
    	print "<input type=submit value=\"Remove User\" class=button1></form>";
    
    //reload this page
    	print "<form action=$PHP_SELF method=post>
    	<input type=hidden name=show>
    	<input type=hidden name=admin_login value=$admin_login_compare>";   // to enter one more time to login.php
    	print "<input type=hidden name=admin_password value=$admin_password_compare>"; // if ($admin_password!=$admin_password_compare) etc....
    	print "<input type=hidden name=reloadme ><input type=submit value=Reload  class=button1></form>";
    
    
    	print "Counter: $file_contents users
    	</td>";
    
    
    	print "<td>
    	<table border=1 cellspacing=0 cellpadding=4 bordercolor=#007898><tr><td>ID</td><td>Login</td><td>Password</td><td>Email</td><td>Last visit (Y/M/D)</td></tr></tr>";
        while($row=mysql_fetch_object($result1)):	
            print "<tr>";
    	print "<td>$row->id</td>";
    	print "<td><a href=\"javascript:showuserdata('$row->login','$row->address','$row->fax','$row->tel','$row->site')\" title=\"Show about $row->login\">$row->login</td>";
    	print "<td>$row->password </td>";
    	print "<td><a href=\"mailto:$row->email\" title=\"Email to $row->login\">$row->email</td>";
    	print "<td>$row->last_date</td>";
    	print "</tr>";
    	endwhile;
    	print "</table></td></tr></table>";
    	print "	</table>";  //end of external table
    	print "<br>&nbsp; Click user name to view data about him";
    
    	exit;
    
    ?>

    ITdocer, 23 Октября 2011

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