1. Лучший говнокод

    В номинации:
    За время:
  2. Pascal / Говнокод #13216

    +129

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function stringreplaceall(text, byt, mot: string): string;
    var
      plats: integer;
    begin
      while pos(byt, text) > 0 do
      begin
        plats := pos(byt, text);
        delete(text, plats, Length(byt));
        insert(mot, text, plats);
      end;
      Result := text;
    end;

    Найди десять отличий с родной дельфийской StringReplace. (trollface)

    Stertor, 23 Июня 2013

    Комментарии (2)
  3. JavaScript / Говнокод #13172

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <ul>
      <script>
      $(function(){
            $(".catalog-menu ul li a[href='/newshop/cat_id:12']").parent().addClass("active");
      });
      </script>
      <li class="active">...</li>
      <li>...</li>
    </ul>

    Переделываю один магазин, выполненный на говноcms, в менюшечке увидел это.

    nkarakin, 14 Июня 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    PUBLIC STATIC FUNCTION /* ЭТО Я НЕ КАПСОМ ПИШУ, ЭТО Я ШИФТ ДЕРЖУ */ selectFor_confirm($delivery_mode, PtrCustomSelector $order_sel)
        {
            /* ... */
        }

    Последствия пятничного deadline-кодинга ^_^

    AntonioK, 06 Июня 2013

    Комментарии (2)
  5. PHP / Говнокод #13099

    +142

    1. 1
    catch (Exception $e) {} // молча сглотнуть обиду (500 Internal Server Error или не удалось подключиться к сервису)

    sanovskiy, 04 Июня 2013

    Комментарии (2)
  6. Objective C / Говнокод #13095

    −81

    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
    - (void)setCategory:(NSDictionary *)newCategory
    {
    	id category = [newCategory retain];
    	[_category release];
    	_category = category;
    	if(_category != nil) {
    		NSString *categoryID = GetString([_category objectForKey:@"id"]);
    		const CategoryViewData *data = FindCategoryViewData(categoryID);
    		if(data == NULL)
    			goto _clearView;
    
    		UIImage *buttonImage = [UIImage imageNamed:GetCategoryIconName(categoryID)];
    		[_titleButton setImage:buttonImage forState:UIControlStateNormal];
    		NSString *buttonTitle = [NSString stringWithFormat:@"  %@ ➤", data->buttonTitle];
    		[_titleButton setTitle:buttonTitle forState:UIControlStateNormal];
    		UIImage *buttonColorImage = [UIImage imageNamed:buttonColorImageName];
    		[_titleButton setTitleColor:[UIColor colorWithPatternImage:buttonColorImage] forState:UIControlStateNormal];
    		
    		_pageControl.onImage = [UIImage imageNamed:data->pageControlOnImageName];
    		_pageControl.currentPage = 0;
    		_pageControl.numberOfPages = numberOfPages;
    		
    		_allVideosLabel.text = [NSString stringWithFormat:@"Все %@", data->allVideosTitle];
    		
    		[self adjustVideoViews];
    	}
    	else {
    _clearView:
    		[_titleButton setImage:nil forState:UIControlStateNormal];
    		[_titleButton setTitle:nil forState:UIControlStateNormal];
    		[_titleButton setTitleColor:nil forState:UIControlStateNormal];
    		
    		_pageControl.onImage = nil;
    		_pageControl.currentPage = 0;
    		_pageControl.numberOfPages = 0;
    		
    		_allVideosLabel.text = nil;
    
    		for(CategoryRowCell *cell in _videoViews) {
    			[cell removeFromSuperview];
    		}
    		self.videoViews = nil;
    		_scrollView.contentSize = CGSizeZero;
    		_scrollView.contentOffset = CGPointZero;
    		_allVideosView.frame = CGRectMake(0, 0, CGRectGetWidth(_allVideosView.frame), CGRectGetHeight(_allVideosView.frame));
    		_allVideosView.hidden = YES;
    	}
    }

    Типичная ячейка

    ArtFeel, 03 Июня 2013

    Комментарии (2)
  7. JavaScript / Говнокод #13088

    +155

    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
    --- a/src/Foo.js
    +++ b/src/Foo.js
    @@ -1,21 +1,61 @@
         var Foo = (function () {
             function Foo(productId, productSettings, overrides) {
                 var backup, loc = document.location, home;
    -            this._sdkSettings = Program.Utils.deepCopy(Take5.settings);
    +            this._sdkSettings = JSON.parse(JSON.stringify(TGH5.settings));
                 if(overrides) {
    -                this._sdkSettings = Program.Utils.copyProperties(overrides, this._sdkSettings);
    +                if('debug' in overrides) {
    +                    this._sdkSettings.debug = overrides.debug;
    +                }
    +                if('inDemoMode' in overrides) {
    +                    this._sdkSettings.inDemoMode = overrides.inDemoMode;
    +                }
    +                if('sdkHome' in overrides) {
    +                    this._sdkSettings.sdkHome = overrides.sdkHome;
    +                }
    +                if('eixtUrl' in overrides) {
    +                    this._sdkSettings.exitUrl = overrides.exitUrl;
    +                }
    +                if('ads' in overrides) {
    +                    if('preRoll' in overrides.ads) {
    +                        this._sdkSettings.ads.preRoll = overrides.ads.preRoll;
    +                    }
    +                    if('inGame' in overrides.ads) {
    +                        this._sdkSettings.ads.inGame = overrides.ads.inGame;
    +                    }
    +                    if('postRoll' in overrides.ads) {
    +                        this._sdkSettings.ads.postRoll = overrides.ads.postRoll;
    +                    }
    +                }
    +                if('reporting' in overrides) {
    +                    if(overrides.reporting instanceof Object) {
    +                        if('analyticsId' in overrides.reporting) {
    +                            this._sdkSettings.reporting.analyticsId = overrides.reporting.analyticsId;
    +                        }
    +                        if('site' in overrides.reporting) {
    +                            this._sdkSettings.reporting.site = overrides.reporting.site;
    +                        }
    +                        if('virtualPageRoot' in overrides.reporting) {
    +                            this._sdkSettings.reporting.virtualPageRoot = overrides.reporting.virtualPageRoot;
    +                        }
    +                        if('initParams' in overrides.reporting) {
    +                            this._sdkSettings.reporting.initParams = overrides.reporting.initParams;
    +                        }
    +                    } else {
    +                        this._sdkSettings.reporting = overrides.reporting;
    +                    }
    +                }
                 }

    А я сажаю алюминивые агурцы - а-а - на брезентовом поле :(
    Некоторые имена сознательно изменены дабы не посягать на копирайты и торговые знаки.

    wvxvw, 02 Июня 2013

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

    +153

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $payout_rate = isset( $transfer['draft'] ) ? ( $transfer['payout_rate'] == '' ? 0 : $transfer['payout_rate'] ) : 1;
            if( isset( $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["sum"] ) ) {
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["quantity"] += $transfer["quantity"];
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["sum"] += $transfer["perechisleno"] * $rate * $payout_rate;
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["commission"] += $transfer["udergano"] * $rate * $payout_rate;
            }
            else {
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["quantity"] = $transfer["quantity"];
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["sum"] = $transfer["perechisleno"] * $rate * $payout_rate;
                $this->_drafts[$transfer["agent"]][$transfer["id_project"]][$transfer["draft_date"]][$currencyId]["commission"] = $transfer["udergano"] * $rate * $payout_rate;
            }

    тайный культ массивов

    dimkich, 24 Мая 2013

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    .td-basket .region>.td-list .td-a>p+div>p:first-child+p,
    .td-basket .region>.td-list>div>img+div>p+p>span,
    .td-basket .region>.td-list .td-a>p+div+div>p:first-child+p,
    .td-basket .region>.td-list h2
     {
       font-size: 16px;
    }

    Ниндзя-верстак

    dsxack, 22 Мая 2013

    Комментарии (2)
  10. Ruby / Говнокод #13029

    −85

    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
    def self.process(site, object = nil, &block)
        dont_unblock = false
        block_res = true
    
        site.lock!
        if site.assets_blocked?
          dont_unblock = true
          raise Asset::BlockedException
        end
        site.assets_blocked = true
        site.save!
    
        block_res = yield if block_given?
    
        return false unless block_res
        return object.save if object
    
        true
      ensure
        site.update_attribute(:assets_blocked, false) unless dont_unblock
      end
    
      # во всех местах, где с ассетами делалось хоть что-нибудь, копипастился такой кусок:
    
          result =
          begin
            @asset = @site.assets.new
            @asset.process do
              @asset.attached = params[:file]
              @asset.folder_path = params[:path]
            end
          rescue Asset::BlockedException
            render json: { errors: [I18n.t("layout.assets.errors.assets_blocked")] } and return
          end

    По мотивам http://govnokod.ru/13027: транзакции изобретены не нами, давайте сделаем их сами!

    whitequark, 21 Мая 2013

    Комментарии (2)
  11. Си / Говнокод #12983

    +132

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/types.h>
    
    void usage(char *progname)
    {
        fprintf(stderr,"Usage: %s [-i <interval>]\n",progname);
        exit(1);
    }
    
    int main(int argc, char *argv[])
    {
        int arg;
        size_t alloc = 1000;
        uid_t userid = getuid();
    
        while ((arg = getopt(argc,argv,"")) != -1) {
            switch(arg) {
                default:
                    usage(argv[0]);
                    break;
            }
        }
    
        //const char *basecmd = "sudo turbostat -s -i 1 2>&1";
        char ghz[8];
        char *junkbuffer = malloc(sizeof(char)*1000);
        const char *basecmd = "turbostat -s -i 1 2>&1";
    
        seteuid(0);
        setuid(0);
        FILE *turboPipe = popen(basecmd,"r");
        seteuid(userid);
        setuid(userid);
    
        /* ignore first line */
        getline(&junkbuffer,&alloc,turboPipe);
        fscanf(turboPipe,"%*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",ghz);
        free(junkbuffer);
    
        fprintf(stdout,"%s\n",ghz);
        pclose(turboPipe);
    
        return 0;
    }

    Установил новый Debian на ноут. Искал инфу по Intel TurboBoost.
    Наткунлся на это
    http://technicallyliving.blogspot.com/2012/06/intel-turboboost-and-linux.html

    Улыбнул вайл-свитч. Что мешало автору обойтись без свитча?

    denis90, 09 Мая 2013

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