1. JavaScript / Говнокод #17151

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    # coffee script
    d = 1 - Math.pow(d,n) * Math.pow((1/d -1),n)
    
    // java script
    d = 1 - Math.pow(d, n) * Math.pow(1 / d(-1), n);

    почему не любят кофескрипт, выпуск -дцатьпервый. потому что нельзя просто скопипастить формулу и не поймать Uncaught TypeError: number is not a function

    makc3d, 22 Ноября 2014

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

    +139

    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
    SGELISTENTRY *sgeListAdd(SGELIST *l, const char *id, void *data) {
       SGELISTENTRY *ret;
    
       sgeNew(ret, SGELISTENTRY);
       l->numberOfEntries++;
       if (l!=NULL) {
          ret->prev=l->last;
       } else {
          ret->prev=NULL;
       }
       if (l!=NULL && l->last!=NULL) {
          l->last->next=ret;
       }
       ret->next=NULL;
       ret->id=strdup(id);
       ret->data=data;
    
       if (l==NULL) return ret;
    
       if (l->first==NULL) l->first=ret;
       l->last=ret;
    
       return ret;
    }

    Эх, проверяй, не проверяй, один хрен все грохнется при l==NULL

    Pythoner, 21 Ноября 2014

    Комментарии (54)
  3. PHP / Говнокод #17149

    +160

    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
    /**
    * @param array $input
    * @return array
    * @throws Exception
    */
    protected function makeParams($input)
    {
        if (!is_array($input))
        {
            throw new \Exception('argument should be array');
        }
    
        $params = array();
    
        foreach ($input as $k=>$v)
        {
            $params[] = $v;
        }
    
        return $params;
    }

    свой array_values, с блекджеком и экзепшенами

    heyzea1, 21 Ноября 2014

    Комментарии (62)
  4. JavaScript / Говнокод #17148

    +154

    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
    if ((new Date(2014, 0, 1)).getHours() != 0 || new Date(2015, 0, 7).getHours() != 0) {
      // Переопределяем конструктор
      Date = (function (NativeDate) {
        var NewDate = function (Y, M, D, h, m, s, ms) {
          var length = arguments.length;
          var date = length === 1 && String(Y) === Y ? // isString(Y)
              new NativeDate(NewDate.parse(Y)) :
                  length >= 7 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m, s, ms)) :
                  length >= 6 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m, s)) :
                  length >= 5 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m)) :
                  length >= 4 ? new NativeDate(NativeDate.UTC(Y, M, D, h)) :
                  length >= 3 ? new NativeDate(NativeDate.UTC(Y, M, D)) :
                  length >= 2 ? new NativeDate(NativeDate.UTC(Y, M)) :
                  length >= 1 ? new NativeDate(Y) :
              new NativeDate();
          if (length == 0) {
            date = new NativeDate(+date - date.getTimezoneOffset() * 60000);
          }
          date.constructor = NewDate;
          return this instanceof NativeDate ? date : date.toString();
        };
    
        if (NativeDate.now) {
          NewDate.now = function () {
            return new NewDate().getTime();
          };
        }
        if (NativeDate.UTC) {
          NewDate._UTC = NativeDate.UTC;
          NewDate.UTC = function (Y, M, D, h, m, s, ms) {
            var _date = new NewDate(NewDate._UTC.apply(this, arguments));
            return +_date - _date.getTimezoneOffset() * 60000;
          };
        }
        NewDate.prototype = NativeDate.prototype;
        NewDate.prototype.constructor = NewDate;

    И так далее, "фикс" для кривых таймзон в JS на винде http://habrahabr.ru/post/243685/

    asavartsov, 21 Ноября 2014

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

    +159

    1. 1
    2. 2
    3. 3
    static function beforeIblockElementAddOrUpdateResetResponseAuthor($fields){
        ...
    }

    n1ce22rus, 21 Ноября 2014

    Комментарии (97)
  6. PHP / Говнокод #17145

    +160

    1. 1
    echo 'some string'."\n";

    )))

    GoodTalkBot, 20 Ноября 2014

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

    +131

    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
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    namespace CA1
    {
        class Program
        {
            static void Main()
            {
                int buffer;
                int Cout = 0;
                string line;
                System.IO.StreamReader file = new System.IO.StreamReader("file.txt");
                while ((line = file.ReadLine()) != null)
                {
                    buffer = Convert.ToInt32(line);
                    if(buffer > 0)
                    {
                        if(buffer / 2 > 5 && buffer / 2 < 49.5)
                        {
                            Cout++;
                        }
                    }
    
                    if (buffer < 0)
                    {
                        if (buffer / 2 < - 5 && buffer / 2 > - 49.5)
                        {
                            Cout++;
                        }
                    }
                }
                Console.WriteLine(Cout);
                Console.ReadLine();
            }
        }
    }

    Вычисление количества цифр в числе

    LightningAtom, 20 Ноября 2014

    Комментарии (138)
  8. Perl / Говнокод #17143

    −366

    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
    sub rotate {
        my ($filename, $max_entries) = @_;
        $max_entries //= 10; # TODO: make infinity available
    
        return if (! -f $filename);
    
        my ($name, $dir, $suffix) = fileparse($filename, qr/\.[^.]*$/);
    
        my %old_files = ();
        my $shift_max = 0; # maximum number of file that is going to be rotated
        my $glob = File::Spec->catfile($dir, $name . '.*' . $suffix);
        for my $file (glob qq/"$glob"/) {
            my ($number) = $file =~ /\.(\d+)\Q$suffix\E$/;
    
            $old_files{$number} = $file if (defined $number);
            $shift_max++ while (exists $old_files{$shift_max + 1});
        }
    
        $shift_max = $max_entries - 1 if ($shift_max >= $max_entries);
        # how many files to remove from the end
        my $to_remove = scalar(keys %old_files) - $max_entries;
    
        # rename and unlink
        for my $number (sort { $b <=> $a } keys %old_files) {
            my $file = $old_files{$number};
    
            if ($to_remove-- > 0) {
                print "## DEBUG: unlink $file\n";
                unlink($file)
                    or croak('Cannot unlink ' . $file);
            } elsif ($number <= $shift_max) {
                my $new_name = File::Spec->catfile($dir, $name . '.' . ($number + 1) . $suffix);
                print "## DEBUG: rename $file -> $new_name\n";
                rename($file, $new_name)
                    or croak('Cannot rename ' . $file . ' to ' . $new_name);
            }
        }
    
        my $new_name = File::Spec->catfile($dir, $name . '.1' . $suffix);
        print "## DEBUG: rename $filename -> $new_name\n";
        rename($filename, $new_name)
            or croak('Cannot rename ' . $filename . ' to ' . $new_name);
    }

    Продолжаем парад велосипедов. Сделал ротацию бекап-архивов :-{

    Elvenfighter, 20 Ноября 2014

    Комментарии (12)
  9. C# / Говнокод #17142

    +135

    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
    public void SelectStep(int stepNumber)
    {
        //1.HTTPCore
        //2.find cat
        //3find p.cat
        //4.find products
        //5.parse products info
        //6.save
        //7.complete
        if (stepNumber != 1) ((Label)(this.panel.Controls.Cast<Control>()
            .First(c => c.TabIndex == stepNumber - 1))).ForeColor = Color.Black;
        ((Label)(this.panel.Controls.Cast<Control>()
            .First(c => c.TabIndex == stepNumber))).ForeColor = Color.Red;
        if (stepNumber == 6)
        {
            labelStatusSecondLine.ForeColor = Color.Black;
            labelStatusFirstLine.Text = "Готово."; buttonStart.Enabled = buttonRefreshCats.Enabled = true; timer.Stop();
        }
        if (stepNumber == 7)
        {
            labelStatusSecondLine.Text = "Обновление категорий...";
        }
    }

    Досталось в наследство. Слегка переписано мной (ранее у всех лейблов были имена вроде "label1" – к лейблам аффтар обращался по распарсенным оттуда цифрам).

    pushistayapodmyshka, 20 Ноября 2014

    Комментарии (17)
  10. JavaScript / Говнокод #17141

    +171

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var obj=document.getElementsByClassName('check-distr');
    var a=0;
    for(i=0; i < obj.length; i++) {
    a=a+1;
    }

    без комментариев:)
    Нашел такое вот, судя по аннотации чел уже уволился и разделить сие не с кем, говнокожу сюда)))

    Patapon, 20 Ноября 2014

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