- 1
- 2
- 3
- 4
public static long hash(URL url) {
FNV1 fnv; (fnv = new FNV1a32()).init(url.toExternalForm());
return fnv.getHash();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+77.2
public static long hash(URL url) {
FNV1 fnv; (fnv = new FNV1a32()).init(url.toExternalForm());
return fnv.getHash();
}
Какой читаемый код... :)
+75.4
<many-to-one name="nurseSex" entity-ref="sex" title="Пол ухаживающего"/>
Атрибут "title" развеял все мои фантазии о сексе с медсестрой :)
+77.3
// Год и месяц редактируются как Double, а хранятся в базе как два инта
if (aValue == null) {
current.setStartMonth(0);
current.setStartMonth(0);
} else {
current.setStartMonth(Integer.parseInt(aValue.toString().split(".")[0]));
current.setStartMonth(Integer.parseInt(aValue.toString().split(".")[1]));
}
Программисты клиента и базы стоят один другого
+79.8
String _desc = postParams.get( "description" );
if (_desc == null)
_desc = "Merchant payment";
_desc = _desc.replace("%20", " ");
_desc = _desc.replace("%21", "!");
_desc = _desc.replace("%22", "\"");
_desc = _desc.replace("%23", "#");
_desc = _desc.replace("%24", "$");
_desc = _desc.replace("%25", "%");
_desc = _desc.replace("%26", "&");
_desc = _desc.replace("%27", "'");
_desc = _desc.replace("%28", "(");
_desc = _desc.replace("%29", ")");
_desc = _desc.replace("%2A", "*");
_desc = _desc.replace("%2B", "+");
_desc = _desc.replace("%2C", ",");
_desc = _desc.replace("%2D", "-");
_desc = _desc.replace("%2E", ".");
_desc = _desc.replace("%2F", "/");
_desc = _desc.replace("%3A", ":");
_desc = _desc.replace("%3B", ";");
_desc = _desc.replace("%3C", "<");
_desc = _desc.replace("%3D", "=");
_desc = _desc.replace("%3E", ">");
_desc = _desc.replace("%3F", "?");
_desc = _desc.replace("%40", "@");
_desc = _desc.replace("%5B", "[");
_desc = _desc.replace("%5C", "\\");
_desc = _desc.replace("%5D", "]");
_desc = _desc.replace("%5E", "^");
_desc = _desc.replace("%5F", "_");
_desc = _desc.replace("%60", "`");
_desc = _desc.replace("%7B", "{");
_desc = _desc.replace("%7C", "|");
_desc = _desc.replace("%7D", "}");
_desc = _desc.replace("%7E", "~");
Разработчики java.net.URLDecoder были идиотами. Напишем КРУЧЕ!
+72.6
TransferInfo info = new QiwiTransferInfo();
if( command.equalsIgnoreCase( "pay" ) )
{
( ( QiwiTransferInfo ) info ).setCommand( QiwiCommand.PAY );
( ( QiwiTransferInfo ) info ).setTxnDate( request.getParameter( "txn_date" ) );
}
else
{
( ( QiwiTransferInfo ) info ).setCommand( QiwiCommand.CKECK );
}
( ( QiwiTransferInfo ) info ).setAmout( Double.parseDouble( amount ) );
( ( QiwiTransferInfo ) info ).setTxnId( txn_id );
( ( QiwiTransferInfo ) info ).setAccount( account );
( ( QiwiTransferInfo ) info ).setCurrency( Currency.getInstance( "RUB" ) );
C другой стороны, я никогда не могу предсказать что же вернет конструктор...
+72.2
assert ( false );
Найдено в глубинах кода :)
+75.2
boolean isCustomerWMIDExists = containParameterWithName( request, CUSTOMER_WMID_PARAM_NAME );
boolean isSellerWMIDExists = containParameterWithName( request, SELLER_WMID_PARAM_NAME );
boolean isPurseExists = containParameterWithName( request, PURSE_PARAM_NAME );
boolean isDescriptionExists = containParameterWithName( request, BasePaymentSystem.DESCRIPTION_PARAM_NAME );
boolean isInvAddressExists = containParameterWithName( request, INVADDRESS_PARAM_NAME );
boolean isPeriodExists = containParameterWithName( request, PERIOD_PARAM_NAME );
boolean isExperationExists = containParameterWithName( request, EXPERATION_PARAM_NAME );
boolean isDateCrtExists = containParameterWithName( request, DATECRT_PARAM_NAME );
boolean isDateUpdExists = containParameterWithName( request, DATEUPD_PARAM_NAME );
boolean isWmInvIdExists = containParameterWithName( request, INVID_PARAM_NAME );
boolean isRequestNExists = containParameterWithName( request, REQUESTN_PARAM_NAME );
boolean isProjectIdExists = containParameterWithName( request, BasePaymentSystem.PROJECTID_PARAM_NAME );
boolean isUserIdExists = containParameterWithName( request, BasePaymentSystem.USERID_PARAM_NAME );
boolean isCurrencyExists = containParameterWithName( request, CURRENCY_PARAM_NAME );
if (isCustomerWMIDExists && isSellerWMIDExists && isPurseExists && isDescriptionExists && isInvAddressExists && isPeriodExists
&& isExperationExists && isDateCrtExists && isDateUpdExists && isWmInvIdExists && isRequestNExists && isProjectIdExists
&& isUserIdExists && isCurrencyExists)
{
wminfo.setCustomerWMID( request.getParameter( CUSTOMER_WMID_PARAM_NAME ) );
wminfo.setSellerWMID( request.getParameter( SELLER_WMID_PARAM_NAME ) );
wminfo.setPurse( request.getParameter( PURSE_PARAM_NAME ) );
wminfo.setDescription( request.getParameter( BasePaymentSystem.DESCRIPTION_PARAM_NAME ) );
wminfo.setInvAddress( request.getParameter( INVADDRESS_PARAM_NAME ) );
wminfo.setPeriod( Byte.parseByte( request.getParameter( PERIOD_PARAM_NAME ) ) );
wminfo.setExperation( Byte.parseByte( request.getParameter( EXPERATION_PARAM_NAME ) ) );
wminfo.setDateCrt( ( getWebMoneyDateString( Long.parseLong( request.getParameter( DATECRT_PARAM_NAME ) ) ) ) );
wminfo.setDateUpd( ( getWebMoneyDateString( Long.parseLong( request.getParameter( DATEUPD_PARAM_NAME ) ) ) ) );
wminfo.setWmInvID( request.getParameter( INVID_PARAM_NAME ) );
wminfo.setRequestN( Long.parseLong( request.getParameter( REQUESTN_PARAM_NAME ) ) );
wminfo.setCurrency( Currency.getInstance( request.getParameter( CURRENCY_PARAM_NAME ) ) );
...
}
Разбор параметров GET-запроса, переданных из http://govnokod.ru/2015
// не дай бог, начальство заметит, что я рабочий код публикую
+80.4
StringBuilder sb = new StringBuilder();
sb.append( "?" + BasePaymentSystem.CHECKPAYMENT_PARAM_NAME + "=true&" + WebMoneyXmlSystem.CUSTOMER_WMID_PARAM_NAME + "="
+ getCustomerWMID() + "&" + WebMoneyXmlSystem.CURRENCY_PARAM_NAME + "=" + getCurrency().toString() + "&"
+ WebMoneyXmlSystem.SELLER_WMID_PARAM_NAME + "=" + _sellerWMID + "&" + WebMoneyXmlSystem.PURSE_PARAM_NAME + "=" + _purse
+ "&" + WebMoneyXmlSystem.DESCRIPTION_PARAM_NAME + "=" + getDescription() + "&" + WebMoneyXmlSystem.INVADDRESS_PARAM_NAME
+ "=" + _invAddress + "&" + WebMoneyXmlSystem.PERIOD_PARAM_NAME + "=" + _period + "&"
+ WebMoneyXmlSystem.EXPERATION_PARAM_NAME + "=" + _experation + "&" + WebMoneyXmlSystem.DATECRT_PARAM_NAME + "="
+ dateCreateMills.toString() + "&" + WebMoneyXmlSystem.DATEUPD_PARAM_NAME + "=" + dateUpdateMills.toString() + "&wmInvId="
+ _wmInvId + "&requestN=" + String.valueOf( _requestn ) + "&" + BasePaymentSystem.PROJECTID_PARAM_NAME + "="
+ _projectId.toString() + "&" + BasePaymentSystem.USERID_PARAM_NAME + "=" + _userId.toString() );
return new String( sb );
Формирование строки GET запроса.
+77.5
//devPin и pin - массивы байт, а сравниваем мы их так :
if (Utils.bytesToHex(devPin).equals(Utils.bytesToHex(pin))) {
....
:)))
+72.2
private char readNextChar() throws IOException {
synchronized (in) {
if (plain) {
if (BANDWIDTH_DEBUG) {
CasinoServer.bandwidthChecker.addClientMessageReceived(1);
}
int c = in.read();
if (c == -1) {
throw new IOException("Client disconnected");
}
return (char) c;
}
if (num_bytes_read % 5 == 0) {
if (!isNgClient()) {
last_byte_read = readURLEncodedChar();
} else {
if (BANDWIDTH_DEBUG) {
CasinoServer.bandwidthChecker.addClientMessageReceived(1);
}
int c = in.read();
if (c == -1) {
throw new IOException("Client disconnected");
}
last_byte_read = c & 0xff;
}
++num_bytes_read;
}
int x;
if (!isNgClient()) {
x = readURLEncodedChar();
} else {
if (BANDWIDTH_DEBUG) {
CasinoServer.bandwidthChecker.addClientMessageReceived(1);
}
int c = in.read();
if (c == -1) {
throw new IOException("Client disconnected");
}
x = c & 0xff;
}
last_byte_read ^= x;
int y = last_byte_read;
last_byte_read = (x & 0xff);
++num_bytes_read;
return (char) (y & 0xff);
}
}
This is the ingenious algorithm, invented by the estonians to read a simple byte from a socket. Couldn't think of anything more error-prone, and less readable. Enjoy!