Кресты / Говнокод #2142 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
std::string basic::_gettime(time_t t)
    {
        string res;
        string tt;
        //must be Wdy, DD-Mon-YYYY HH:MM:SS GMT
        struct tm *tm_res;
        tm_res=gmtime(&t);
        switch(tm_res->tm_wday)
        {
            case 0:
                res+="Sun";
                break;
            case 1:
                res+="Mon";
                break;
            case 2:
                res+="Tue";
                break;
            case 3:
                res+="Wed";
                break;
            case 4:
                res+="Thu";
                break;
            case 5:
                res+="Fri";
                break;
            case 6:
                res+="Sat";
                break;
            default:
                throw "Internal error: cgi_app::_gettime(): Day num>6!";
        }
        res+=", ";
        tt=itoa(tm_res->tm_mday);
        if(tt.length()==1)
            tt="0"+tt;
        res+=tt;
        res+="-";
        switch(tm_res->tm_mon)
        {
            case 0:
                res+="Jan";
                break;
            case 1:
                res+="Feb";
                break;
            case 2:
                res+="Mar";
                break;
            case 3:
                res+="Apr";
                break;
            case 4:
                res+="May";
                break;
            case 5:
                res+="Jun";
                break;
            case 6:
                res+="Jul";
                break;
            case 7:
                res+="Aug";
                break;
            case 8:
                res+="Sep";
                break;
            case 9:
                res+="Oct";
                break;
            case 10:
                res+="Nov";
                break;
            case 11:
                res+="Dec";
                break;
            default:
                throw "Internal error: cgi_app::_gettime(): Month num>11!";
        }
        res+="-";
        tt=itoa(tm_res->tm_year+1900);
        res+=tt;
        res+=" ";
        tt=itoa(tm_res->tm_hour);
        if(tt.length()==1)
            tt="0"+tt;
        res+=tt;
        res+=":";
        tt=itoa(tm_res->tm_min);
        if(tt.length()==1)
            tt="0"+tt;
        res+=tt;
        res+=":";
        tt=itoa(tm_res->tm_sec);
        if(tt.length()==1)
            tt="0"+tt;
        res+=tt;
        res+=" GMT";
}

Делаю класс для работы с CGI. Сначала хотел использовать какое-нибудь готовое решение, но ничего подходящего не нашел. По общей концепции понравилась библиотека "CGI C++ Library v0.30a". До тех пор, пока не посмотрел исходники более внимательно... Это функция, которая формирует строку для поля заголовка HTTP "Last-Modified".

Ez-Presso Ez-Presso, (Updated )

Комментарии (6, +6)

Кресты / Говнокод #2140 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
if(p) {
     if (p->m_String[0] == 0) {
         strcpy("foo", p->m_String);
      }
      DrawText(hdc, p->m_String, strlen(p->m_String), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}

и такие веселые куски попадаются в официальном примере написания плагинов на сайте Mozilla
пруф линк - http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/plugin.cpp - строка 750

Coach Coach, (Updated )

Комментарии (20, +20)

Кресты / Говнокод #2139 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
#if 0
  n = NPN_GetStringIdentifier("prompt");

  NPVariant vars[3];
  STRINGZ_TO_NPVARIANT("foo", vars[0]);
  STRINGZ_TO_NPVARIANT("bar", vars[1]);
  STRINGZ_TO_NPVARIANT("foof", vars[2]);
  NPN_Invoke(sWindowObj, n, vars, 3, &rval);
  if (NPVARIANT_IS_STRING(rval)) {
   printf ("prompt returned '%s'\n", NPVARIANT_TO_STRING(rval).utf8characters);
  }

   NPN_ReleaseVariantValue(&rval);
#endif

и это официальный пример написания плагина с сайта Mozilla
пруф линк - http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/plugin.cpp - строка 564

Coach Coach, (Updated )

Комментарии (16, +16)

"PHP" / Говнокод #2138 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
class employee extends company {
    .....
}

На самом деле, это больше бы подошло в раздел "ООП", но раз уж такого нет, то пощу в PHP. Вообще, весь проект, в котором приходится разбираться - редкое дерьмо, но этот ляп меня умилил :)

IHateBidloKod IHateBidloKod, (Updated )

Комментарии (12, +12)

"PHP" / Говнокод #2137 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
<? global $USER; $user_id = $USER->GetID(); ?>
        
        <?foreach($arResult["ITEMS"] as $arItem):?>
            <?if (intval($arItem['PROPERTIES']['PRIORITY_PLACEMENT']['VALUE_ENUM_ID']) > 0) $prior = true; else $prior = false; ?>
            <tr class="body_orders_list<?=(($prior)?' prior':'')?><?=$arItem['ACTIVE'] == 'Y'?'':' order-bad'?>">
                <td class="name">
                    <a class="name" href="<?=$arItem["DETAIL_PAGE_URL"];?>"><?=$arItem["NAME"];?></a>
                    <div class="description"><?=truncate($arItem["DETAIL_TEXT"], 90, "...");?></div>
                    <strong><?=GetMessage("TYPE_WORK");?>:</strong> <?=$arItem["DISPLAY_PROPERTIES"]["TYPE_OF_WORK"]["DISPLAY_VALUE"];?><br />
                    <strong><?=GetMessage("SPECIALIZATION");?>:</strong> <?=$arItem["DISPLAY_PROPERTIES"]["EXPERTISE"]["DISPLAY_VALUE"];?><br />
                    <strong><?=GetMessage("CITY");?>:</strong> <?=$arItem["DISPLAY_PROPERTIES"]["CITY"]["DISPLAY_VALUE"];?><br />
                <? if ($arItem["CREATED_BY"] == $user_id): ?>
                    <?if($arItem['ACTIVE'] == 'Y'):?>
                    <a id="element<?=$arItem['ID']?>" onclick="if(confirm('Вы уверены, что хотите снять с размещения заказ, без возможности восстановления?')){ deactivate_element(<?=$arItem['ID']?>); } return false;" href="#">Снять с размещения</a><br />
                    <a class="add_offer" href="#"><?=GetMessage("EDIT_ORDER");?></a><br /><br />
                    <a href="/services/priority.php?ord=<?=$arItem['ID']?>">Платное размещение</a>
                    <?else: echo showError('Заказ снят с размещения.'); endif;?>
                <? else: ?>
                    <a class="add_offer" href="<?=$arItem["DETAIL_PAGE_URL"];?>"><?=GetMessage("ADD_PROPOSAL");?></a>
                <? endif; ?>
                </td>
                <td class="date_create"><?=substr($arItem["DATE_CREATE"], 0, 10);?></td>
                <td class="budget"><?=$arItem["DISPLAY_PROPERTIES"]["BUDGET"]["DISPLAY_VALUE"];?> <?=(strlen($arItem["DISPLAY_PROPERTIES"]["BUDGET"]["DISPLAY_VALUE"]) > 0)?'руб.':'';?></td>
                <td class="offers"><a class="blue" href="<?=$arItem["DETAIL_PAGE_URL"];?>"><?=(strlen($arItem["PROPERTIES"]["FORUM_MESSAGE_CNT"]["VALUE"]) > 0 ? $arItem["PROPERTIES"]["FORUM_MESSAGE_CNT"]["VALUE"] : "0");?></a></td>
                <td class="employer">
                </td>
            </tr>
        <?endforeach;?>

в продолжение говна номер 2120

y6uTbIu_CMEXOM y6uTbIu_CMEXOM, (Updated )

Комментарии (2, +2)

"PHP" / Говнокод #2136 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
// генерируем 2 раз для лучшей случайности
$wpdb->get_results('SELECT id FROM ' . $table_prefix . 'another_random_quote WHERE tag="'.$tag.'" ORDER BY RAND() LIMIT 1');
$quotes = $wpdb->get_results('SELECT * FROM ' . $table_prefix . 'another_random_quote WHERE tag="'.$tag.'" ORDER BY RAND() LIMIT ' . intval($amount));

Встретил в плагине для вордпресса. Объясните, что такое лучшая случайность?

junqed junqed, (Updated )

Комментарии (7, +7)

Няшная / Говнокод #2135 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
...

// TODO: remove this godless "switch()"!
                switch(tuntype) { // TODO: Important: do as in documentation instead of reverse-ingeniering!
#define PACKET_TRY {\
                if(packet->ip_v == 4) {\
                        hl=packet->ip_hl<<2;\
                        if(hl>=sizeof(*packet))\
                                break;\
                        /* TODO: Check in RFC something about of ICMP send-back in this case */\
                        fprintf(stderr, "Got too short IP-header (%i)...\n",hl);\
                }\
                if((packet->ip_v&IPV6_VERSION_MASK) == IPV6_VERSION) {\
                        break;\
                }\
}
#define NEXT(a) tuntype=a;\
                if(tuntry>=2)\
                        goto tun_process_switch_end;\
                tuntry++;
#define CASE(a) NEXT(a);\
        case a
tun_process_switch:
//              switch(tuntype) {
                        case TUNTYPE_NORM:              // NetBSD-like?
                                packet=(typeof(packet))ptr;
                                PACKET_TRY;
                        CASE(TUNTYPE_EXT):              // FreeBSD-like?
                                packet=(typeof(packet))((char *)ptr + 4);
                                if(s>4)
                                        if(*ptr==0x02)
                                                PACKET_TRY;
                        CASE(TUNTYPE_ETH):              // Ethernet? TODO: Implement VLAN-tagging
                                packet=(typeof(packet))((char *)ptr + sizeof(*eth));
                                eth=(typeof(eth))ptr;
                                if(!teth) {
                                        teth=alloca(sizeof(*teth));
                                        memcpy(&teth->ether_shost, &eth->ether_dhost, sizeof(teth->ether_shost));
                                        memcpy(&teth->ether_dhost, &eth->ether_shost, sizeof(teth->ether_dhost));
                                        teth->ether_type=ETHERTYPE_IP;
                                }
                                if(s>sizeof(*eth))
//                                      if((*(char *)&eth->ether_type==0x08/* not IPv4? */)||(*(char *)&eth->ether_type==0x86/* not IPv6? */))  // TODO: Implement compatibility with all protocols over ethernet
                                                PACKET_TRY;
                                NEXT(TUNTYPE_NORM);
                                goto tun_process_switch;
                        
                        default:                        
                                tuntype=TUNTYPE_NORM;
                                goto tun_process_switch;
//              }
tun_process_switch_end:
#undef CASE
#undef NEXT
#undef PACKET_TRY
                                if(tuntry<~0)
                                        tuntry=0;
                                tuntype=oldtuntype;
                                fprintf(stderr, "Got unknown packet. Flushing...\n");
                                FLUSH;  // Flush all. We don't know the length of packet with unknown type.. So, we have to flush the buffer, to probably get new packets from the start.
                                goto tun_process_while;
                }

...

"Ляпотааааа"... Очень "структурный" switch...

xaionaro xaionaro, (Updated )

Комментарии (11, +11)

"PHP" / Говнокод #2134 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
<?php 

...

$markers = array("~");
$newcode  = array("<br>");
$output = str_replace($markers, $newcode, $source);

...

?>

А вот так канадские кодеры заменяют функцию nl2br() в textarea
=)

Senya Senya, (Updated )

Комментарии (3, +3)

Кресты / Говнокод #2133 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
/*
    CANON D-SLR cameras core routine
    Property of CANON INC. 1998-2010
    
    v 1.0 made by Radja Tokamoto Goines
    v 1.1 made by Dugwin Yakioto jr.
    
    last changes: 10.11.2009
*/

#include <stdlib.h>
#include <math.h>
#include <time.h>

#include "inc/tweakfocus.h"
#include "inc/radja_filters.h"

bool do_focus(lens, camera) {
    double fp;
    time_t t;

    t = init_focus_timer(t);
    
    do {
        fp = measure_focus_point(lens);
        move_focus(lens, fp)

        if (timeout(t))
            return false;

    } while (!lens.is_focused());
    
    if (!L_LensDetected(lens))
        lens.adjust_focus(rand(10));
        
    return true;
}

rawdata * scandata(matrix, lens, camera) {
    rawdata *cr;
    double noise, aberrations;

    cr = create_cr(matrix);
    
    read_exif_info(cr->exif, lens, camera);

    prepare_everything(matrix, lens, camera);
    
    if (!do_focus(lens, camera))
        return NULL;
    else 
        beep();
      
    aberrations = pow(100 - lens.focallength, 2) * sqrt(2) + 10;

    if (L_LensDetected(lens))
        aberrations /= 2.0;
      
    scan_sensor(cr, matrix, aberrations);

    noise = matrix.iso / 100.0;
    noise *= matrix.cropfactor;

    if (camera.model == EOS1000D) {
        noise *= 1.2;
        wait_for_something();
    }

    if (camera.model != EOS7D)
        wait_for_something();
    
    if (lens.manufacture != CANON_LENS) {
        corrupt_something(cr);
        apply_random_filter(cr);
    }
    
    if (lens.model == EF_50_F1_4) {
        noise /= 1.2;
        apply_fcb(cr); //fucken cool bokeh
    }
    
    if (lens.model == CANON_L_17_40_F4) {
        blur(cr, 0.8);
        distort(cr, 40 - lens.focallength);
    }
      
    radja_filter(cr, 1.570796326794896619231321691641); //don't touch that!

    if (is_eos1d_series(camera.model))
        disable_all_spoiling(cr);
    else
        make_nice_colors(cr);
    // finally...
    apply_noise(cr, noise);    
    apply_barrel_distortion(cr, lens);
    apply_pillow_distortion(cr, lens);  
    
    return cr;
}

http://habrahabr.ru/blogs/DSLR/74958/
Исходные тексты прошивки canon eos.
Многие, наверное, уже слышали, что на днях была взломана внутренняя сеть компании Canon и в числе прочего в сеть «утёк» кусок ядра исходных текстов прошивки камер серии EOS, который я имею честь эксклюзивно опубликовать на суд общественности.
Говночитатели без ЧЮ идут в *опу.

sbb sbb, (Updated )

Комментарии (22, +22)