1. Pascal / Говнокод #16191

    +86

    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
    function IsMemoryCommitByAdress(const AAddress: Pointer): Boolean;
    var
      MemoryInfo: TMemoryBasicInformation;
    begin
      Result := False;
      if not Assigned(AAddress) then
      Exit;
      VirtualQuery(AAddress, MemoryInfo, SizeOf(MemoryInfo));
      Result := MemoryInfo.State and MEM_COMMIT <> 0;
    end;
    
    function IsPointerToVMT(const APointer: Pointer): Boolean;
      var
      VMTPointer, VMTPointerSelf: Pointer;
    begin
      Result := False;
      if not IsMemoryCommitByAdress(APointer) then
      Exit;
      VMTPointer := APointer;
      VMTPointerSelf := Pointer(Integer(VMTPointer) + vmtSelfPtr);
      if not IsMemoryCommitByAdress(VMTPointer) then
      Exit;
      if not IsMemoryCommitByAdress(VMTPointerSelf) then
      Exit;
      if not IsMemoryCommitByAdress(PPointer(VMTPointerSelf)^) then
      Exit;
      Result := PPointer(VMTPointerSelf)^ = VMTPointer;
    end;
    
    function IsBadptr(apointer:pointer):boolean;
    begin
      Result := IsMemoryCommitByAdress(APointer) and IsPointerToVMT(PPointer(APointer)^);
    end;

    Функция, для определения качества указателя, в ситуации "один объект - несколько указателей".
    Гк в том, что нет надежности - это все равно, что юзать IsBadReadPtr и аналогичные.

    Почему-то никто не пытается использовать операторы is и as (я узнал о них благодаря Тарасу, спасибо ему), чтобы сравнить качество приведения.

    brutushafens, 19 Июня 2014

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

    +138

    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
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    bool ExcludeCase4(int iDepth)
            {
                MyNodeType pN = mPath[iDepth];
                if (pN != null)
                    if (pN.AuxField.bRed) return false;
    
                MyNodeType pP = mPath[iDepth - 1];
                    if (!pP.AuxField.bRed) return false;
    
                MyNodeType pS;
    
                if (LeftSon(iDepth))
                    pS = pP.pRight;
                else
                    pS = pP.pLeft;
    
                if (pS == null)
                {
                    pP.AuxField.bRed = false;
                    iDepthBad = -1;
                    return true;
                }
    
                if (pS.AuxField.bRed) return false;
    
                MyNodeType pSL = pS.pLeft;
                if (pSL != null)
                    if (pSL.AuxField.bRed) return false;
    
                MyNodeType pSR = pS.pRight;
                if (pSR != null)
                    if (pSR.AuxField.bRed) return false;
    
                pS.AuxField.bRed = true;
                pP.AuxField.bRed = false;
    
                iDepthBad = -1;
                
                return true;
    // Дерево стало хорошим. Корректировать больше не надо.
            }
    
            bool ExcludeCase6(int iDepth)
            {
                MyNodeType pN, pP, pS;
                bool bLeft, bRedP;
    
                pN = mPath[iDepth];
                if (pN != null)
                if (pN.AuxField.bRed) return false;
    
                pP = mPath[iDepth - 1];
                bRedP = pP.AuxField.bRed;
    
                bLeft = LeftSon(iDepth);
    
                if (bLeft)
                    pS = pP.pRight;
                else
                    pS = pP.pLeft;
    
                if (pS == null) return false;
                if (pS.AuxField.bRed) return false;
    
                MyNodeType pSL, pSR, p2, p3;
    
                pSL = pS.pLeft;
                pSR = pS.pRight;
    
                if (bLeft)
                {
                    if (pSR == null || pSR != null && !pSR.AuxField.bRed)
                    {
                        if (pSL == null) return false;
                        if (!pSL.AuxField.bRed) return false;
    // Сюда попали => это Случай 5.
    
                        p2 = pSL.pRight;
                        pSL.pRight = pS;
                        pS.pLeft = p2;
                        pSL.AuxField.bRed = false;
                        pS.AuxField.bRed = true;
    
                        pP.pRight = pSL;
                        pSR = pS;
                        pS = pSL;
                    }
                    else
                    if (!pSR.AuxField.bRed) return false;
    
    // Сюда попали => это Случай 6.
    
               ,......}

    кусочек красно-черного дерева, необходимый, но не достаточный

    lavrov, 18 Июня 2014

    Комментарии (4)
  3. Java / Говнокод #16189

    +87

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public BarrierAssessment(int id, Client client, int homephone, int mobile, int email, int transport, int licence, boolean notInWorkForce, boolean unpaidWork, boolean cdeProgram, boolean notWorkingBut, int paidWork, 
    String employerOcc, String reason, int highlevel, String further, int stableAccomodation, int loneParent, int livingWith, int policeProblems, int courtPending, int preventFrom, int medical, int drugTest, int currentBusy, 
    String scurrentBusy, String reasonForNotGettingJob, int startTomorrow, String jobGoals, int currentResume, int canvasLetter, int referees, int interviewClothing, String otherBarriers, int ec, LastModified lastModified, 
    Date datestamp, Date bupdated, String disabilityBarriers, Date licenceDueToExpire, Date licenceDueBack, String currentSkills, String possibleSkills) {
     
    ...
     
    }

    Мать всех конструкторов!

    Meegoo, 18 Июня 2014

    Комментарии (25)
  4. Java / Говнокод #16188

    +74

    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
    import java.io.*;
    import java.util.*;
    
    public class Solution
    {
        public static void main(String[] args) throws Exception
          { Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            int z = scanner.nextInt();
            if (a < b && a < c && a < z)
            {  if (b < c && b < z)
                {if (c < z)
                    {System.out.println(z + " " + c + " " + b + " " + a);}
                    else
                    {System.out.println(c + " " + z + " " + b + " " + a);} }
                else if (c < b && c < z)
                { if (b < z)
                    {System.out.println(z + " " + b + " " + c + " " + a);}
                    else
                    {System.out.println(b + " " + z + " " + c + " " + a);} }
                else if (z < c && z < b)
                { if (c < b)
                    {System.out.println(b + " " + c + " " + z + " " + a);}
                    else
                    {System.out.println(c + " " + b + " " + z + " " + a);} } }
            else if (b < a && b < c && b < z)
            { if (a < c && a < z)
                { if (c < z)
                    {System.out.println(z + " " + c + " " + a + " " + b);}
                    else
                    {System.out.println(c + " " + z + " " + a + " " + b);} }
                else if (c < a && c < z)
                { if (a < z)
                    {System.out.println(z + " " + a + " " + c + " " + b);}
                    else
                    {System.out.println(a + " " + z + " " + c + " " + b);} }
                else if (z < a && z < c)
                { if (a < c)
                    {System.out.println(c + " " + a + " " + z + " " + b);}
                    else
                    {System.out.println(a + " " + c + " " + z + " " + b);} } }
            else if (c < a && c < b && c < z)
            { if (a < b && a < z)
                { if (b < z)
                    {System.out.println(z + " " + b + " " + a + " " + c);}
                    else
                    {System.out.println(b + " " + z + " " + a + " " + c);} }
                else if (b < a && b < z)
                { if (a < z)
                    {System.out.println(z + " " + a + " " + b + " " + c);}
                    else
                    {System.out.println(a + " " + z + " " + b + " " + c);} }
                else if (z < a && z < b)
                { if (a < b)
                    {System.out.println(b + " " + a + " " + z + " " + c);}
                    else
                    {System.out.println(a + " " + b + " " + z + " " + c);} } }
            else if (z < a && z < b && z < c)
            { if (a < c && a < b)
                { if (c < b)
                    {System.out.println(b + " " + c + " " + a + " " + z);}
                    else
                    {System.out.println(c + " " + b + " " + a + " " + z);} }
                else if (c < a && c < b)
                { if (a < b)
                    {System.out.println(b + " " + a + " " + c + " " + z);}
                    else
                    {System.out.println(a + " " + b + " " + c + " " + z);} }
                else if (b < a && b < c)
                {
                    if (a < c)
                    {System.out.println(c + " " + a + " " + b + " " + z);}
                    else
                    {System.out.println(a + " " + c + " " + b + " " + z);} } }
    }
    }

    Ня!

    dagonlaf, 18 Июня 2014

    Комментарии (4)
  5. C# / Говнокод #16187

    +136

    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
    static string[] ArrayFuller(string pathToFile)
            {
    
                int rr = 0;
                StreamReader sr=new StreamReader(pathToFile);
                while(!sr.EndOfStream){
                sr.ReadLine();
                rr++;
                }
                StreamReader sr2 = new StreamReader(pathToFile);
                string[] arrayBox = new string[rr];
                for (int i = 0; i < rr; i++)
                {
                    arrayBox[i] = Convert.ToString(sr2.ReadLine());
                }
                sr2.Close();
                return arrayBox;
            }

    vladb9582, 18 Июня 2014

    Комментарии (6)
  6. Java / Говнокод #16186

    +79

    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
    public Long getRecordCount() {
            long result = 0;
            if(pfrFile != null){
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРСВ1() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_СВ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ_НАЧИНАЯ_С_2012_ГОДА() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_СВ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ_НАЧИНАЯ_С_2013_ГОДА() != null){
                    result++;
                }
    ...
            return result;
    }

    :D

    skobets, 18 Июня 2014

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    /**
     * Some UI hacks for JRuby Facet
     */
    public class NiiChAVOUtil { 
    }

    Слова лишнии

    vistall, 18 Июня 2014

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

    +133

    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
    string parser(string chto, string chem)
                {
                    int dlina = chem.Length;
                    int kol = chto.Length;
                    string ret = null;
                    int shet = 0;
                    int r = 0;
                    int nom = 0;
                    for (int i = 0; i < kol; i++)
                    {
                        if (chto[i] == chem[0] && shet == 0)
                        {
                            for (int j = i; j < dlina + i; j++)
                            {
                                if (chto[j] == chem[r])
                                {
                                    r++;
                                    shet++;
                                    nom = j;
                                }
    
                            }
                            if (shet != dlina)
                            {
                                shet = 0;
                                r = 0;
                                nom = 0;
                            }
                        }
                    }
                    int schet = nom + 3;
                    while (chto[schet] != '<')
                    {
                        ret += chto[schet];
                        schet++;
                    }
                    return ret;
                }

    Функция для парсинга подстроки

    vladb9582, 18 Июня 2014

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

    +156

    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
    if ((int)($basket->summ/1000) > 999)
        {
          $price_all = substr_replace($basket->summ," ",1,0);
          $price_all = substr_replace($price_all," ",5,0);
        }
        elseif ((int)($basket->summ/1000) > 99)
        {
          $price_all = substr_replace($basket->summ," ",3,0);
        }
        elseif ((int)($basket->summ/1000) > 9)
        {
          $price_all = substr_replace($basket->summ," ",2,0);
        }
        elseif ((int)($basket->summ/1000) < 9 && (int)($basket->summ/1000) > 0)
        {
          $price_all = substr_replace($basket->summ," ",1,0);
        }
        elseif ((int)($basket->summ/1000) == 0)
        {
          $price_all = $basket->summ;
        }

    Вот так вот у нас на офисе коллега форматировал цену...

    Mayhemalexf, 18 Июня 2014

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

    +91

    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
    for li:=LL-2 downto 1 do
            begin
              ag:=ml_(a[li], m_(gen(len(a[li]), 1, 1), a[li]) );
    
                cp(
                  b[li],
                  ml_(
                    ml(
                      t(W[li]),
                      from2(b[li+1], li <> LL-2)
                    )
                    ,
                    ag
                  )
                );
            end;

    Функциональное программирование в императивном стиле.

    icune, 18 Июня 2014

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