1. Perl / Говнокод #702

    −307.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    sub get_ppl{
    	my $self = shift;
            my ($U, $print_done, $team) = @_;
    
             return "<ppl team_id='$team' battle_stats='$U->{_CHAR}->{win},$U->{_CHAR}->{loose},$U->{_CHAR}->{nobody}' medals='".$U->get_medal_string_for_user($U)."' $clan team_id='0' av_id='$U->{_CHAR}->{av_id}' fn='$U->{_CHAR}->{avatara}' u='$U->{_CHAR}->{u}' hp_u='$U->{_CHAR}->{hp_u}' stat0_u='$U->{_CHAR}->{stat0_u}' stat0='$U->{_CHAR}->{f}' stat1='$U->{_CHAR}->{m}' stat2='$U->{_CHAR}->{y}'  stat3='$U->{_CHAR}->{l}' hpmax='$U->{_CHAR}->{maxhp}' hp='$U->{_CHAR}->{hp}' aname='$U->{_USER_NAME}' lvl='$U->{_CHAR}->{lvl}' cname='$U->{_CHAR}->{name}' id='$U->{_ID}' carma='$U->{_CHAR}->{carma}' sex='$U->{_CHAR}->{sex}' slot0='$Item[0]' slot8='$Item[8]' slot7='$Item[7]' slot6='$Item[6]' slot1='$Item[1]' weight='$U->{_CHAR}->{weight}' slot5='$Item[5]' slot4='$Item[4]' slot3='$Item[3]' slot2='$Item[2]' city_id='$U->{_CHAR}->{city_id}'/>" if !$print_done;
             return "<ppl done='true' battle_stats='$U->{_CHAR}->{win},$U->{_CHAR}->{loose},$U->{_CHAR}->{nobody}' medals='".$U->get_medal_string_for_user($U)."' $clan team_id='0' av_id='$U->{_CHAR}->{av_id}' fn='$U->{_CHAR}->{avatara}' u='$U->{_CHAR}->{u}' hp_u='$U->{_CHAR}->{hp_u}' stat0_u='$U->{_CHAR}->{stat0_u}' stat0='$U->{_CHAR}->{f}' stat1='$U->{_CHAR}->{m}' stat2='$U->{_CHAR}->{y}'  stat3='$U->{_CHAR}->{l}' hpmax='$U->{_CHAR}->{maxhp}' hp='$U->{_CHAR}->{hp}' aname='$U->{_USER_NAME}' lvl='$U->{_CHAR}->{lvl}' cname='$U->{_CHAR}->{name}' id='$U->{_ID}' carma='$U->{_CHAR}->{carma}' sex='$U->{_CHAR}->{sex}' slot0='$Item[0]' slot8='$Item[8]' slot7='$Item[7]' slot6='$Item[6]' slot1='$Item[1]' weight='$U->{_CHAR}->{weight}' slot5='$Item[5]' slot4='$Item[4]' slot3='$Item[3]' slot2='$Item[2]' city_id='$U->{_CHAR}->{city_id}'/>" if $print_done;
    }

    Забавная проверка

    guest, 12 Марта 2009

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

    −868

    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
    CREATE OR REPLACE VIEW my_schema.my_view AS
    SELECT 
       TO_NUMBER (c.payment_term_code) ID, 
       c.payment_term_code sap_code, c.payment_term_name longname,
              c.short_name shortname, c.comment_line comments, c.cust_relevant, c.vend_relevant, c.active active,
              c.updated_by created_by, c.updated_by updated_by, c.updated_on created_on, c.updated_on updated_on, 1 txn_ver
         FROM my_schema.my_table c
        WHERE (    LENGTH (c.payment_term_code) = 1
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 2
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 3
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 4
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 5
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 5, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
       UNION
       SELECT ID, sap_code, longname, shortname, comments, 'Y', 'Y', active, created_by, updated_by, created_on, updated_on, 1
         FROM my_schema.my_other_table) tt

    Вот так в 30 строк пиндосы защищаются от проникновения буковков в TO_NUMBER()

    guest, 12 Марта 2009

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

    −870.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    select 
    --
    (case
        when (sum(distinct sub.est_cost) - sum(distinct sub.act_cost)) > 0 then
          (sum(distinct sub.est_cost) - sum(distinct sub.act_cost))
        when (sum(distinct sub.est_cost) - sum(distinct sub.act_cost)) < 0 then
          (sum(distinct sub.est_cost) - sum(distinct sub.act_cost))
        else
           0
    end)
    --
    from blablabla

    Не пускайте бразильских футболистов к компьютеру!

    guest, 12 Марта 2009

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

    −873.4

    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
    SELECT BE.SORT as SORT,BE.ID as ID,DATE_FORMAT(BE.TIMESTAMP_X, '%d.%m.%Y %H:%i:%s') as TIMESTAMP_X,BE.MODIFIED_BY as
     MODIFIED_BY,DATE_FORMAT(BE.DATE_CREATE, '%d.%m.%Y %H:%i:%s') as DATE_CREATE,BE.CREATED_BY as CREATED_BY,BE.IBLOCK_ID as
     IBLOCK_ID,BE.IBLOCK_SECTION_ID as IBLOCK_SECTION_ID,BE.ACTIVE as ACTIVE,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_FROM)>0,
     DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y')) as ACTIVE_FROM,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_TO)>0, DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y')) as
     ACTIVE_TO,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_FROM)>0, DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y %H:%i:%s'),
     DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y')) as DATE_ACTIVE_FROM,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_TO)>0, DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y')) as DATE_ACTIVE_TO,BE.NAME as NAME,BE.PREVIEW_PICTURE as 
     PREVIEW_PICTURE,BE.PREVIEW_TEXT as PREVIEW_TEXT,BE.PREVIEW_TEXT_TYPE as PREVIEW_TEXT_TYPE,BE.DETAIL_PICTURE as
     DETAIL_PICTURE,BE.DETAIL_TEXT as DETAIL_TEXT,BE.DETAIL_TEXT_TYPE as DETAIL_TEXT_TYPE,BE.SEARCHABLE_CONTENT as
     SEARCHABLE_CONTENT,BE.WF_STATUS_ID as WF_STATUS_ID,BE.WF_PARENT_ELEMENT_ID as WF_PARENT_ELEMENT_ID,BE.WF_NEW as WF_NEW,if (BE.WF_DATE_LOCK is null, 'green', if(DATE_ADD(BE.WF_DATE_LOCK, interval 60 MINUTE)<now(), 'green', if(BE.WF_LOCKED_BY=0, 'yellow', 'red'))) as LOCK_STATUS,BE.WF_LOCKED_BY as WF_LOCKED_BY,DATE_FORMAT(BE.WF_DATE_LOCK, '%d.%m.%Y %H:%i:%s') as
     WF_DATE_LOCK,BE.WF_COMMENTS as WF_COMMENTS,BE.IN_SECTIONS as IN_SECTIONS,BE.SHOW_COUNTER as SHOW_COUNTER,BE.SHOW_COUNTER_START as
     SHOW_COUNTER_START,BE.CODE as CODE,BE.TAGS as TAGS,BE.XML_ID as XML_ID,BE.XML_ID as EXTERNAL_ID,BE.TMP_ID as
     TMP_ID,concat('(',U.LOGIN,') ',ifnull(U.NAME,''),' ',ifnull(U.LAST_NAME,'')) as USER_NAME,concat('(',UL.LOGIN,') ',ifnull(UL.NAME,''),' ',ifnull(UL.LAST_NAME,'')) as LOCKED_USER_NAME,concat('(',UC.LOGIN,') ',ifnull(UC.NAME,''),' ',ifnull(UC.LAST_NAME,'')) as CREATED_USER_NAME,L.DIR as LANG_DIR,B.LID as LID,B.IBLOCK_TYPE_ID as IBLOCK_TYPE_ID,B.CODE as
     IBLOCK_CODE,B.NAME as IBLOCK_NAME,B.XML_ID as IBLOCK_EXTERNAL_ID,B.DETAIL_PAGE_URL as DETAIL_PAGE_URL,B.LIST_PAGE_URL as
     LIST_PAGE_URL FROM b_iblock B INNER JOIN b_lang L ON B.LID=L.LID INNER JOIN b_iblock_element BE ON BE.IBLOCK_ID = B.ID INNER JOIN b_iblock_property FP1 ON FP1.IBLOCK_ID=B.ID AND FP1.CODE='DAY' INNER JOIN b_iblock_element_property FPV1 ON
     FP1.ID=FPV1.IBLOCK_PROPERTY_ID AND FPV1.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property_enum FPEN1 ON FP1.ID = FPEN1.PROPERTY_ID AND FPV1.VALUE_ENUM=FPEN1.ID INNER JOIN b_iblock_property FP2 ON FP2.IBLOCK_ID=B.ID AND FP2.CODE='MONTH' INNER JOIN
     b_iblock_element_property FPV2 ON FP2.ID=FPV2.IBLOCK_PROPERTY_ID AND FPV2.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property_enum FPEN2 ON FP2.ID = FPEN2.PROPERTY_ID AND FPV2.VALUE_ENUM=FPEN2.ID LEFT JOIN b_user U ON U.ID=BE.MODIFIED_BY LEFT JOIN b_user UL ON
     UL.ID=BE.WF_LOCKED_BY LEFT JOIN b_user UC ON UC.ID=BE.CREATED_BY WHERE 1=1 AND B.ID IN (0,72) AND ( (BE.WF_STATUS_ID=1 AND
     BE.WF_PARENT_ELEMENT_ID IS NULL) ) AND ((((BE.IBLOCK_ID = '72')))) AND (((BE.ACTIVE_TO >= now() OR BE.ACTIVE_TO IS NULL) AND
     (BE.ACTIVE_FROM <= now() OR BE.ACTIVE_FROM IS NULL))) AND ((((BE.ACTIVE='Y')))) AND (BE.IN_SECTIONS ='N' ) AND ((((FPEN1.VALUE LIKE
     '-1')))) AND ((((FPEN2.VALUE LIKE 'Март')))) ORDER BY BE.SORT asc

    Вот что бывает когда человека заменет скрипт, причем написаные тупым человеком, ORM рулить.

    guest, 12 Марта 2009

    Комментарии (12)
  5. SQL / Говнокод #698

    −852.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    UPDATE DKNDRECTMPL SET
        TARGET = IIF(OPERATION IN (0, 1, 3, 4, 5), 0, 1),
        ACT = CASE OPERATION
              WHEN 0 THEN 0
              WHEN 1 THEN 1
          WHEN 2 THEN 1
          WHEN 3 THEN 1
          WHEN 4 THEN 1
          WHEN 5 THEN 3
              END;

    Это Firebird если чё.

    guest, 12 Марта 2009

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

    −854.7

    1. 1
    2. 2
    UPDATE CARD SET STATE = (STATE - 1) * (-1);
    //таким экзотическим способом инвертируем значения 0/1, чтобы не подцеплять лишних UDF

    SQL-инвертор

    guest, 12 Марта 2009

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

    +173.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $h_month = date("m");
    $h_day = date("d");
    $h_year = date("Y");
    $h_hour = date("H");
    $h_minute = date("i");
    
    $history = mysql_query("insert into history values('','$h_month','$h_day','$h_year','$h_hour','$h_minute','$total_open','$beat','$wins','$tie','$can_change_up','$can_change_down','$cannot_win','$t_adjusted_gain','$t_adjusted_loss','$t_dollar_amount')");

    вот так вот человек хранит дату в БД =)

    guest, 12 Марта 2009

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

    +990.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    bool CUser::IsFavorite(const CGuid &guid)
    {
     ASSERT(this);
     if(!this )
      return false;
    ...
    }

    guest, 12 Марта 2009

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

    +144.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // в посредине кода сайта http://mdist.metallizdeliya.ru/en/info/programmes/academic_programmes/introduction.html 
    <meta content="Word.Document" name="ProgId">
    <meta content="Microsoft Word 12" name="Generator">
    <meta content="Microsoft Word 12" name="Originator">
    
    <link href="file:///C:%5CUsers%5Cgeneral%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List" />
    <link href="file:///C:%5CUsers%5Cgeneral%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData" />

    Из кода сайта http://mdist.metallizdeliya.ru/en/info/programmes/academic_programmes/introduction.html

    guest, 11 Марта 2009

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

    +135.5

    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
    class PliggMailer{
    
    	var $subject = '';
    	var $body = '';
    	var $from = '';
    	var $to = '';
    
    	function PliggMailer($subj = '', $body = '', $from = '', $to = '', $cc = '', $bcc = ''){
    
    		if($subj != ''){$this->subject = $subj;}
    		if($body != ''){$this->body = $body;}
    		if($from != ''){$this->from = $from;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    		if(!is_array($to)){$to[] = $to;}
    		if(count($to) == 0){$this->to = $to;}
    
    	}

    Блоговый движок pligg жжот.

    guest, 11 Марта 2009

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