1. C# / Говнокод #17326

    +98

    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
    class CSVSave
    {
        char separator = ';';
        
        public void SaveCSV(string pathfile, IEnumerable<Product> list )
        {
            using (var sw = new StreamWriter(pathfile, false, Encoding.GetEncoding(1251)))
            {
                foreach (var prod in list)
                {
                    string line =
                        prod.Manufacturer + separator +
                        prod.Name + separator +
                        prod.Type + separator +
                        prod.Url + separator +
                        prod.Imgurl + separator +
                        prod.Sex + separator +
                        prod.Volume + separator +
                        prod.Box + separator +
                        prod.Price + separator +
                        prod.availability + separator +
                        prod.Desk;
    
                    if ((prod.Family != null) || (prod.QuantityPurchased != null) || (prod.Application != null) || (prod.Flavornotes != null) || (prod.Production != null)) line += separator;
                    if (prod.QuantityPurchased != null) line += prod.QuantityPurchased + separator;
                    if (prod.Family != null) line += prod.QuantityPurchased + separator;
                    if (prod.Production != null) line += prod.QuantityPurchased + separator;
                    if (prod.Application != null) line += prod.QuantityPurchased + separator;
                    if (prod.Flavornotes != null) line += prod.QuantityPurchased + separator;
    
                    line=line.Trim(separator);
    
                    sw.WriteLine(line);
                }
                sw.Close();
            }
        }
    }

    pushistayapodmyshka, 17 Декабря 2014

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

    +133

    1. 1
    2. 2
    3. 3
    BaseIndexerObjectType type;
    <...>
    var searchType = (SearchEntity)Enum.Parse(typeof(SearchEntity), type.ToString());

    Наткнулся на просторах рабочего кода. Конвертируем один енум в другой.

    Yuuri, 17 Декабря 2014

    Комментарии (0)
  3. Pascal / Говнокод #17324

    +88

    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
    procedure sr(var q, w: string; j, k: integer);
    begin
      for j := 1 to 100 do
      begin
        if ord(q[j]) - ord(w[j]) > 0 then begin for k := 1 to pos(' ', q) do write(q[k]);exit; end
        else if ord(q[j]) - ord(w[j]) < 0 then begin for k := 1 to pos(' ', w) do write(w[k]);exit; end;
      end;
      for k := 1 to pos(' ', w) do write(w[k]);
    end;
     
    procedure sr2(var q, w, e, r: string; j, k, p: integer);
    begin
      for j := 1 to 101 do
      begin
        if ord(q[j]) - ord(w[j]) > 0 then begin r := q;break; end
        else if ord(q[j]) - ord(w[j]) < 0 then begin r := w;break;end;
        inc(p);
      end;
      if p>100 then r:=w;
      for j := 1 to 100 do
      begin
        IF E[J]=' ' Then break;
        if ord(e[j]) - ord(r[j]) > 0 then begin for k := 1 to pos(' ', e) do write(e[k]);exit; end
        else if ord(e[j]) - ord(r[j]) < 0 then begin for k := 1 to pos(' ', r) do write(r[k]);exit; end;
      end;
      for k := 1 to pos(' ', r) do write(r[k]);
    end;
     
    var
      st, a, b, c, rd: string;
      i, s: integer;
     
    begin
      assign(input, 'input.txt'); reset(input);
      assign(output, 'output.txt'); rewrite(output);
      read(st);
      for i := 1 to 102
      do
      begin
        a := a + ' ';
        b := b + ' ';
        c := c + ' ';
      end;
      for i := 1 to length(st) do
        if st[i] = ' ' then inc(s)
        else
          case s of
            0: a[i] := st[i];
            1: b[i - pos(' ', a)] := st[i];
            2: c[i - pos(' ', a) - pos(' ', b)] := st[i];
          end;
      if (a=b) and (b=c) then for i := 1 to pos(' ', a) do write(a[i])
      else if (pos(' ', a) > pos(' ', b)) and (pos(' ', a) > pos(' ', c)) then for i := 1 to pos(' ', a) do write(a[i])
      else if (pos(' ', b) > pos(' ', a)) and (pos(' ', b) > pos(' ', c)) then for i := 1 to pos(' ', b) do write(b[i])
      else if (pos(' ', c) > pos(' ', b)) and (pos(' ', c) > pos(' ', a)) then for i := 1 to pos(' ', c) do write(c[i])
      else if (pos(' ', a) = pos(' ', b)) and (pos(' ', b) = pos(' ', c)) then sr2(a, b, c, rd, 0, 0, 0)
      else if pos(' ', a) = pos(' ', b) then sr(a, b, 0, 0)
      else if pos(' ', c) = pos(' ', b) then sr(c, b, 0, 0)
      else if pos(' ', a) = pos(' ', c) then sr(a, c, 0, 0);
    end.

    Выбор максимума из 3 целых длинных чисел

    AndreyZ, 17 Декабря 2014

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

    +210

    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
    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
    /*
          _31 - числа  начинаются с _
          _Math_sin - глобальные функции тоже
          $abcd - строки начинаются с $ 
          /\ - символ лямбда. Easter egg:можно писать и / для краткости
          САХАР:
           args = arguments
          _ = args[0]     
    */
    
    log("========CALCULATOR EXAMPLE========");
    //*
    handler= makeHandler(chainer());
    var calc = prox(
        {   //imports
            print:function(x){log(x); return x;}
            ,add:function(a,b){ return a+b;}
            ,set:function(x,y){ return y;}
            ,fma:function(a,b,c){
                return a*b+c;
            }        
        }
    );
    calc
        .set[0]
        .add[2]
        .print //2
        .fma[10][5]
        .print //25
        
        .add._3
        .String
        .add._1111
        .print //281111
        
        ._Math_min._1
        ._Math_max._1000
        .print //100
        
        .String
        ._Math_log10
        .add["$ pow 10"]
        .print //3 pow 10
    ;
    //*/
    handler= makeHandler(chainer());
    var linq = prox(
        {   //imports
            set     :function(inner,y){ return y;}
            ,print  :function(x){log(x); return x;}
            ,map    :function(arr,y){ return arr.map(y)}
            ,filter :function(arr,y){ return arr.filter(y)}
            ,sort   :function(arr,comparator){ return arr.sort(comparator)}
            //Imperatii
            ,IF     :function(context,condition,trueBranch,falseBranch){
                return (condition(context)) ? trueBranch(context) : falseBranch(context);
            }
        }
    );
    
    linq
        .set    ["[5,2,1,3,4]"]
        .print//[5, 2, 1, 3, 4]
        .map    ["/\ _ * 3"]
        .print//[15, 6, 3, 9, 12]   
        .filter ["/\ log('filter='+args[0]),args[0]>5"] //несколько операторов в лямбде.
        .print//[6, 9, 12, 15]
        .sort   ["/\ args[0]-args[1]"]
        .map    ["/\ _ - 6"]
        .print//[0, 3, 6, 9]
        .map    ["/\ 2>_ ? 1 : _ * args.callee(_-1)"]   //анонимная рекурсия и факториал
        .print//[1, 6, 720, 362880]
        
        //имперации
        .filter ["/\ _>100"]
        .IF ["/\ _.length===0"][ 
            "/\ log('array is EMPTY!'), _" 
        ][ 
            "/\ log('Not empty:',_), []"         
        ]    //"Not empty:" [720, 362880]
        .IF ["/\ _.length===0"][ 
            "/\ log('EMPTY!'), ['empty','replacement']" 
        ][ 
            "/\ log(_), _"         
        ].print//['empty','replacement']
           
    ;

    Такой вот DSL на свойствах javascript.
    Осторожно! Все трюки выполнены профессионалами. Не пытайтесь повторить это на работе.
    http://jsfiddle.net/y5og4o9q/1/

    3.14159265, 15 Декабря 2014

    Комментарии (18)
  5. Куча / Говнокод #17322

    +125

    1. 1
    http://faculty.knox.edu/dbunde/teaching/chapel/

    Тарасу должно понравится: Паскаль со скобочками, даже begin и then есть.

    wvxvw, 15 Декабря 2014

    Комментарии (0)
  6. JavaScript / Говнокод #17321

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    if(upass==uname || upass=='1234' || upass=='12345' || upass=='123456' || upass=='654321' || upass=='pikabu' || upass=='password' || upass=='qwerty' || upass=='qazwsx') {
    			$('#'+upass2_id+'_err').html('Пароль не должен быть слишком простым или совпадать с логином');
    			errCnt++;
    }

    смотрел исходный код по правой кнопки - сайт pikabu.ru

    marik_v, 15 Декабря 2014

    Комментарии (8)
  7. Java / Говнокод #17320

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static long inFuture(final long time, final long current, final int period) {
            long newtime = current;
            while (newtime < current) {
                newtime += period;
            }
            return newtime;
        }

    я сегодня продуктивен )
    на этот раз...
    последовательный инкремент = )

    Lure Of Chaos, 15 Декабря 2014

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

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public final class DefaultConfig extends TTConfig {
        public DefaultConfig(final int whole, final int pause, final int warn) {
            super(60, 10, 3);
        }
    }

    конфига и ее стандартный вариант (подходящий в 99,9% случаев)

    Lure Of Chaos, 15 Декабря 2014

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

    −165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    update #tmpTours1 set pricelink = ('<a target="_blank" title="Прайс-лист на ближайшие заезды" href="../pricelist/Complex.aspx?country=' + ltrim(str(cnkey)) + '&tour=' + ltrim(str(tourkey)) + '&dateFrom=' + dbo.mwFirstTourDate(tlkey) + '">' + ltrim(str(tourprice)) + ' ' + tourrate + '</a>')
      
     set @sql = N'select * from #tmpTours1 where tourprice is not null and quota <> case ' + ltrim(str(@quotaYes)) + ' when -1 then -10 else 0 end '
     if len(@sort) > 0
      set @sql = @sql + ' order by ' + @sort
    	print @sql
     exec sp_executesql @sql

    Хранимочки по 1000 строк подобного кода.

    tablecell, 15 Декабря 2014

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

    +158

    1. 1
    2. 2
    3. 3
    foreach chat->getParticipants() as user 
    { if user->getName() == 'Nikita' then marina->need(user) endif 
    endforeach

    valery_selitsky, 15 Декабря 2014

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