- 1
#define RETURN_OR_THROW_EXCEPTION_IF_ERROR(Expression, Exception) if(!Expression) throw Exception; return Expression
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1011
#define RETURN_OR_THROW_EXCEPTION_IF_ERROR(Expression, Exception) if(!Expression) throw Exception; return Expression
+75
// Gets the starting position for the endtag of the first element in text.
private int getEndTagPosition(String element, String text) {
String startTag = "<" + element;
String endTag = "</" + element;
int nestingLevel = 1;
int end = 0;
int startPos = 1;
while (nestingLevel > 0) { // loop until matching endtag is found
int start = text.indexOf(startTag, startPos);
end = text.indexOf(endTag, startPos);
if ((start == -1) || (start > end)) { // next tag is an endtag
nestingLevel--;
startPos = end + 1;
} else { // next tag is a starttag
nestingLevel++;
startPos = start + 1;
}
}
return end;
}
+127
if (ddlSex.SelectedValue.Contains("мужской"))
cbPregnant.Visible = false;
if (employer.Pregnant.StartsWith("1"))
cbProject.Checked = true;
if (employer.Pregnant.StartsWith("2"))
cbPregnant.Checked = true;
+163
while($row = mysql_fetch_array($r))
echo $row[0] . '|' . $row[1] . '|' . $row[2] . '|' . $row[3] . '|' . $row[4] . '|' . $row[5] . "\n";
implode? не, не слышал
+165
mysql_query("DELETE FROM tblTokens WHERE intRestaurantID = $id AND cToken = '$token';");
mysql_query("INSERT INTO tblTokens (intRestaurantID, cToken) VALUES ($id, '$token');");
Увеличиваем id, наверное.
+71
/**
* @see ru.dwin.inbox.gtk.videotypes.IVideo#startPlay(int)
*/
@Override public void startPlay(int delay)
{
try
{
Thread.sleep(delay * 1000);
}
catch (InterruptedException e1)
{
RestartAllThreads();
}
if (theTimer == null)
{
theTimer = new Timer(ASECOND, new ActionListener()
{
@Override public void actionPerformed(ActionEvent e)
{
if (elapsedTime >= getDuration())
{
theTimer.stop();
resetPlay();
Toolkit.getDefaultToolkit().beep();
}
else
{
elapsedTime += (int) ASECOND / 1000;
notifyAddedRenderers(USwingWorker.ALL);
}
}
});
}
else
{
theTimer.start();
}
}
Играть через ХЗ сколько секунд...
+161
class Super_Loader extends Zend_Loader {
public static function loadClass($class, $dirs = null)
{
parent::loadClass($class, $dirs);
}
private function moduleIsExist($name) {
if(is_dir(APPLICATION_PATH . "/modules/" . $name . "/")) {
return true;
}
return false;
}
public static function autoload($class)
{
$classArray = explode("_", $class);
$firstPart = array_shift($classArray);
if(self::moduleIsExist($firstPart)) {
$moduleDir = APPLICATION_PATH . "/modules/";
$typePart = array_shift($classArray);
switch($typePart) {
case "Lib":
$file_name = $moduleDir . $firstPart . "/lib/" . implode("/", $classArray) . ".php";
break;
case "Model":
$file_name = $moduleDir . $firstPart . "/models/" . implode("/", $classArray) . ".php";
break;
default:
break;
}
if($file_name) {
try {
self::loadFile($file_name);
return $class;
} catch (Exception $e) {
return false;
}
}
} else {
try {
self::loadClass($class);
return $class;
} catch (Exception $e) {
return false;
}
}
}
}
Свой супер-автолоадер для ZF
−107
- (void)applicationWillTerminate:(UIApplication *)application
{
exit(0);
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}
На всякий пожарный, а то вдруг не завершиться апп.
+167
$query1234 = "select ....";
$result1234 = mysql_query($query1234);
$rs1234 = mysql_fetch_assoc($result1234);
Это до такой степени не было фантазии придумать осмысленное название переменным. И бедные боялись, что перепишет где-то другие $query, $result, $rs. Не говоря уже о том, что никакой модели, сплошные фетчи, вместо того, чтобы вытянуть всё сразу
+75
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;
}