1. Java / Говнокод #11767

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    Process process = Runtime.getRuntime().exec("su");
    OutputStream outputStream = process.getOutputStream();
    String cmd = "keycode " + KeyEvent.KEYCODE_BACK;
    outputStream.write((cmd + "\n").getBytes("ASCII"));

    Андроид. Вот такой вот прекрасный способ программно нажать кнопочку "Back".

    http://stackoverflow.com/questions/5832861/android-back-key-by-software

    bormand, 13 Сентября 2012

    Комментарии (8)
  2. SQL / Говнокод #11766

    −160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    QString query4="INSERT INTO `"+mb+"`.`cubes` (`user_id`, `name`) VALUES (0, '"+name+"')";
    mysql.sqlQuery(query4, true);
    mysql.sqlQuery("SELECT * FROM `"+mb+"`.`cubes` WHERE name='"+name+"' AND user_id="+QString::number(userID), true);
    mysql.data_connection_bind(true);
    mysql.getRow();
    int id=mysql.getUint32(o);
    mysql.sqlQuery("UPDATE `"+mb+"`.`cubes` SET user_id=1 WHERE user_id="+QString::number(userID), true);
    mysql.sqlQuery("DELETE FROM `"+mb+"`.`users` WHERE `name`="+QString::number(getpid()), true);
    qDebug()<<"CubeID"<<id;

    Судя по словам автора: он не осилил lastInsertId, поэтому пытался вставить запись с заранее не существующим user_id, чтобы затем однозначно извлеч эту строку и получить уже долгожданое поле id.

    Try, 13 Сентября 2012

    Комментарии (3)
  3. SQL / Говнокод #11765

    −158

    1. 1
    2. 2
    3. 3
    4. 4
    SELECT ft_login,fi_system,ft_password,fk_id
    FROM users u
    INNER JOIN taccountscontent t ON u.id = t.fk_id
    WHERE u.id IN (select id from users where id=123)

    Оригинал http://www.askdev.ru/question/16663/%D0%97%D0%B0%D0%BF%D1%80%D0%BE%D1%81-%D0%BA-%D0%91%D0%94-%D0%B8-%D1%86%D0%B8%D0%BA%D0%BB-While/

    et, 13 Сентября 2012

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

    +53

    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
    <?if($arElement["PROPERTIES"]["POSTAV"]["VALUE_ENUM_ID"]==73){?>
    <?if($arElement["PREVIEW_PICTURE"]["HEIGHT"]<105){?><div width="115px" height="105px"><?}?>
    
      <a href="<?=$arElement["DETAIL_PICTURE"]["SRC"]?>" class="preview" onclick="return false;" onmousedown="window.location.href='<?=$arElement["DETAIL_PAGE_URL"]?>';"><img src="<?=$arElement["PREVIEW_PICTURE"]["SRC"]?>"  width="115" border="0px" alt="<?=$arElement["PREVIEW_PICTURE"]["ALT"]?>" title="<?=$arElement["NAME"]?>"/></a></div>
    <?if($arElement["PREVIEW_PICTURE"]["HEIGHT"]<105){?></div><?}?>
    <?}else{?>
        <a href="<?=$arElement["DETAIL_PICTURE"]["SRC"]?>" class="preview" onclick="return false;" onmousedown="window.location.href='<?=$arElement["DETAIL_PAGE_URL"]?>';"><img src="<?=$arElement["PREVIEW_PICTURE"]["SRC"]?>" width="115" height="105" border="0px" alt="<?=$arElement["PREVIEW_PICTURE"]["ALT"]?>" title="<?=$arElement["NAME"]?>"/></a>
    <?}?>
    	<br>&nbsp;
    					<?endif?></td>
                                              </tr>
                                            </table></td>
    									</tr>
    								</table>
    
                                    </div>
    		  </td>
    		<?$cell++;
    		if($cell%$arParams["LINE_ELEMENT_COUNT"] == 0):?>
    	</tr>
    		<?endif?>
    
    		<?endforeach; // foreach($arResult["ITEMS"] as $arElement):?>
    
    		<?if($cell%$arParams["LINE_ELEMENT_COUNT"] != 0):?>
    			<?while(($cell++)%$arParams["LINE_ELEMENT_COUNT"] != 0):?>
    
    			<?endwhile;?>
    			</tr>
    		<?endif?>
    
    </table></div>
     <?if($arParams["DISPLAY_BOTTOM_PAGER"]):?>
    	<br />
    	<?
    	$arResult["NAV_STRING"] = str_replace('|&nbsp;<a href="/e-store/rings/diamond.php?bitrix_include_areas=Y&amp;bitrix_show_mode=configure&amp;login=yes&amp;SHOWALL_1=1">Все</a>','',$arResult["NAV_STRING"]);
    	?>
    	<?=$arResult["NAV_STRING"]?>
    <?endif;?>

    randombot, 13 Сентября 2012

    Комментарии (9)
  5. Ruby / Говнокод #11763

    −166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class User < ActiveRecord::Base
        
      def full_name
      	user_info=User.find(self.id)
      	[user_info.name,user_info.surname].join(" ")
      end
    end

    Получаем полное имя себя

    1101_debian, 13 Сентября 2012

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

    −161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (IDATUMS is null) then
        begin
            suspend;
            exit;
            REZULT = "Nevar importet gramatojumu id:" || :NOMER_DOC;
            execute procedure TSEND_ERROR(:REZULT);
        end

    Гениальнейшая PSQL-конструкция в СУБД Firebird. Автор, видимо, не в курсе, что после EXIT процедура больше не выполняется :]

    N21, 13 Сентября 2012

    Комментарии (3)
  7. C# / Говнокод #11760

    +140

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    private void SendFile(string root, string url, DateTime dateTimeBegin)
    {
    	if ( ... isSend ... )
    	{
    		...MoveToArchive();
    		...Dispose();
    	}
    	else
    	{
    		SendFile(root, url, dateTimeBegin);
    	}
    }

    Ну тут всё ясно...
    Если файлики отсылаются нормально, то всё работает хорошо.
    Зато если файлики не отсылаются, то начинается злая рекурсия, которая постепенно сжирает всю память :).

    ddv_demon, 13 Сентября 2012

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

    +55

    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
    <option <? if(isset($_POST['day']) and $_POST['day']=="01") echo "selected";  ?>   value="01">1</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="02") echo "selected";  ?>  value="02">2</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="03") echo "selected";  ?>  value="03">3</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="04") echo "selected";  ?>  value="04">4</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="05") echo "selected";  ?>  value="05">5</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="06") echo "selected";  ?>  value="06">6</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="07") echo "selected";  ?>  value="07">7</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="08") echo "selected";  ?>  value="08">8</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="09") echo "selected";  ?>  value="09">9</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="10") echo "selected";  ?>  value="10">10</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="11") echo "selected";  ?>  value="11">11</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="12") echo "selected";  ?>  value="12">12</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="13") echo "selected";  ?>  value="13">13</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="14") echo "selected";  ?>  value="14">14</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="15") echo "selected";  ?>  value="15">15</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="16") echo "selected";  ?>  value="16">16</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="17") echo "selected";  ?>  value="17">17</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="18") echo "selected";  ?>  value="18">18</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="19") echo "selected";  ?>  value="19">19</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="20") echo "selected";  ?> value="20">20</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="21") echo "selected";  ?> value="21">21</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="22") echo "selected";  ?>  value="22">22</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="23") echo "selected";  ?>  value="23">23</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="24") echo "selected";  ?>  value="24">24</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="25") echo "selected";  ?>  value="25">25</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="26") echo "selected";  ?>  value="26">26</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="27") echo "selected";  ?> value="27">27</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="28") echo "selected";  ?> value="28">28</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="29") echo "selected";  ?>  value="29">29</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="30") echo "selected";  ?>  value="30">30</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="31") echo "selected";  ?> value="31">31</option>

    вЫводим дни в селекте )) А как ты выводишь дни в селекте? %)

    Diwms, 13 Сентября 2012

    Комментарии (35)
  9. PHP / Говнокод #11758

    +49

    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
    wordpress:
    function __( $text, $domain = 'default' ) {
    	        return translate( $text, $domain );
    }
    
    function translate( $text, $domain = 'default' ) {
    	        $translations = &get_translations_for_domain( $domain );
    	        return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
    }
    
    PHP-manual:
    PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality. 
    
    wordpress:
    /*
    * Don't use translate() directly, use __()
    */

    xcont, 12 Сентября 2012

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

    +141

    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
    internal static double GetExtendedFromBytes(byte[] bytes)
            {
                /*
                    1   15      1   63
                    s   e       i 	f
    
                        The value v of the number is given by: 
                    if 0 <= e < 32767, then v = (-1)s * 2(e-16383) * (i.f) 
                    if e = 32767 and f = 0, then v = (-1)s * Inf 
                    if e = 32767 and f <> 0, then v is a NaN
                 */
                const int memSize = 10;
                if (bytes == null)
                    throw new ArgumentNullException("bytes");
                if (bytes.Length != memSize)
                    throw new ArgumentException("Must be " + memSize + " bytes", "bytes");
    
                int s = bytes[0] >> 7;
                int e = 0x7FFF & ((bytes[0] << 8) | bytes[1]);
                int i = bytes[2] >> 7;
                ulong f = (ulong)(0x7F & bytes[2]);
                for (int j = 3; j < memSize; j++)
                {
                    f <<= 8;
                    f |= bytes[j];
                }
    
                decimal df = (decimal)f / 10000000000000000000 /* 10^19 */; // число f в формате 0.f
                double v;
                if (0 <= e && e < 32767)
                {
                    int pow = e - 16383;
                    decimal c = (s == 0 ? 1 : -1) * (decimal)Math.Pow(2, pow);
                    decimal dv = c * (i + df); // значение, полученное по формуле для x86 Extended Precision Format
    
                    if (f != 0) // HACK при вычислении по формуле искомое значение не удается получить - исправляем
                    {
                        const decimal mn = 0.0776627963145224192m; // magic number, при значениях отличных от 2^x возникает разница кратная этому значению
    
                        decimal delta = Math.Abs(dv - c);
                        decimal add = 0;
                        if (pow >= 4)
                            add = Math.Round(delta * 1.0842021724855044340074528009m); // еще magic number
                        else if (pow >= 2)
                            add = Math.Ceiling(delta);
                        else if (pow >= 0)
                            add = Math.Ceiling(delta * 10) / 10m;
                        else
                        {
                            decimal m = 10m * (decimal)Math.Pow(2, Math.Abs(pow));
                            add = Math.Ceiling(delta * m) / m;
                        }
                        if (dv > 0)
                            dv += add * mn;
                        else
                            dv -= add * mn;
                    }
                    v = (double)dv;
                }
                else if (e == 32767)
                {
                    if (f == 0)
                        v = s == 0 ? double.PositiveInfinity : double.NegativeInfinity;
                    else
                        v = double.NaN;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("bytes");
                }
    
                return v;
            }

    Местные индусы постарались. Перевод 80 bit floating point в double. Причём если прочитать спецификацию IEEE-754, то код займет 3-4 строчки с простыми битовыми операциями.

    NetDeveloper, 12 Сентября 2012

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