1. Java / Говнокод #15659

    +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
    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
    // -1 esli NotFound, snachala massiv potom element
    	static int najtiElementVMassive(Object massiv,Object element){
    		if(massiv instanceof int[]) {
    			for(int i=0; i<((int[])massiv).length; ++i)
    				if(((int[])massiv)[i]==(int)element)
    					return i;
    		} else if(massiv instanceof byte[]) {
    			for(int i=0; i<((byte[])massiv).length; ++i)
    				if(((byte[])massiv)[i]==(byte)element)
    					return i;
    		} else if(massiv instanceof boolean[]) {
    			for(int i=0; i<((boolean[])massiv).length; ++i)
    				if(((boolean[])massiv)[i]==(boolean)element)
    					return i;
    		} else if(massiv instanceof char[]) {
    			for(int i=0; i<((char[])massiv).length; ++i)
    				if(((char[])massiv)[i]==(char)element)
    					return i;
    		} else if(massiv instanceof float[]) {
    			for(int i=0; i<((float[])massiv).length; ++i)
    				if(((float[])massiv)[i]==(float)element)
    					return i;
    		} else if(massiv instanceof double[]) {
    			for(int i=0; i<((double[])massiv).length; ++i)
    				if(((double[])massiv)[i]==(double)element)
    					return i;
    		} else if(massiv instanceof short[]) {
    			for(int i=0; i<((short[])massiv).length; ++i)
    				if(((short[])massiv)[i]==(short)element)
    					return i;
    		} else if(massiv instanceof long[]) {
    			for(int i=0; i<((long[])massiv).length; ++i)
    				if(((long[])massiv)[i]==(long)element)
    					return i;
    		} else {
    			try {
    				for(int i=0; i<((Object[])massiv).length; ++i)
    					if(sravnitMassivi(((Object[])massiv)[i],element))
    						return i;
    			} catch (Exception e) {
    				for(int i=0; i<((Object[])massiv).length; ++i)
    					if((((Object[])massiv)[i]).equals(element))
    						return i;
    			}
    		}
    		
    		return -1;
    	}
    	
    	
    	static boolean sravnitMassivi(Object massiv1,Object massiv2) {
    		try {
    			if((((Object[])massiv1)).length!=(((Object[])massiv2)).length) return false;
    			boolean ravni=true;
    			for(int i=0; i<(((Object[])massiv1)).length; ++i) 
    				ravni=ravni&&sravnitMassivi((((Object[])massiv1))[i],(((Object[])massiv2))[i]);
    			return ravni;
    		} catch (Exception e) {
    			if(massiv1 instanceof int[]) {
    				return Arrays.equals((int[])massiv1,(int[])massiv2);
    			} else if(massiv1 instanceof byte[]) {
    				return Arrays.equals((byte[])massiv1,(byte[])massiv2);
    			} else if(massiv1 instanceof boolean[]) {
    				return Arrays.equals((boolean[])massiv1,(boolean[])massiv2);
    			} else if(massiv1 instanceof char[]) {
    				return Arrays.equals((char[])massiv1,(char[])massiv2);
    			} else if(massiv1 instanceof float[]) {
    				return Arrays.equals((float[])massiv1,(float[])massiv2);
    			} else if(massiv1 instanceof double[]) {
    				return Arrays.equals((double[])massiv1,(double[])massiv2);
    			} else if(massiv1 instanceof short[]) {
    				return Arrays.equals((short[])massiv1,(short[])massiv2);
    			} else if(massiv1 instanceof long[]) {
    				return Arrays.equals((long[])massiv1,(long[])massiv2);
    			} else {
    				return massiv1.equals(massiv2);
    			}
    		}
    	}

    поиск элемента в массиве
    http://ideone.com/iqNA7l

    GovnoGovno, 03 Апреля 2014

    Комментарии (17)
  2. Pascal / Говнокод #15658

    +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
    procedure tproxythread.execute;
    var
      doc: IHtmlDocument2;
      temp,parsed:string;
      v:olevariant;
      i:integer;
    begin
      coinitialize(nil);
      try
        for i:=0 to links.count -1 do
        begin
          temp:=http.LoadContent(links[i]);
          Doc:=coHTMLDocument.Create as IHTMLDocument2;
          V:=VarArrayCreate([0,0], varVariant);
          V[0]:=temp;
          Doc.Write(PSafeArray(TVarData(v).VArray));
          reg.InputString:=doc.body.outerText;
          if reg.Exec then
          repeat
            parsed:= reg.Match [0];
            proxy.add(parsed);
          until not reg.ExecNext;
        end;
      finally
        couninitialize;
      end;
    end;

    Вы все еще парсите webbrowser-ом? Тогда мы идем к вам!..

    Stertor, 03 Апреля 2014

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

    +73

    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
    private void CopyFiles(String dirName) {
    	InputStream is = this.getClass().getResourceAsStream(
    			"/18.xslt");
    	OutputStream os;
    	try {
    		os = new FileOutputStream(dirName + "/18.xslt");
    		byte[] buffer = new byte[4096];
    		int length;
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02.tif");
    		os = new FileOutputStream(dirName + "/13_02.tif");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream("/13_02.xslt");
    		os = new FileOutputStream(dirName + "/13_02.xslt");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02_t.tif");
    		os = new FileOutputStream(dirName + "/13_02_t.tif");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02_t.xslt");
    		os = new FileOutputStream(dirName + "/13_02_t.xslt");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    	} catch (FileNotFoundException e1) {
    		e1.printStackTrace();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    }

    evg_ever, 03 Апреля 2014

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

    +140

    1. 1
    $('img.avatar').attr("src", "http://upload.wikimedia.org/wikipedia/commons/a/a4/Human_penis_2_by_Yiyi1394.jpg")

    = http://prntscr.com/36l35i

    gost, 03 Апреля 2014

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

    −403

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    - (void)setButtonVisible:(bool)buttonVisible
    {
        if(isIpad)
        {
            id(*superSuperButtonVisible)(id, SEL, ...) = [[[self superclass] superclass] instanceMethodForSelector:@selector(setButtonVisible:)];
            superSuperButtonVisible(self, _cmd, buttonVisible);
        }
        else
        {
            [super setButtonVisible:buttonVisible];
        }
    }

    Угу, нет тут множественного наследования. Приходится наследоваться по очереди, а потом вызывать функции через одного.

    tirinox, 03 Апреля 2014

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

    +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
    private static class MyStatefulActor extends DefaultActor {
          protected void act() {
            loop(new Runnable() {
              public void run() {
                react(new MessagingRunnable<String>(this) {
                  protected void doRun(final String msg) {
                    System.out.println("Stage #0: " + msg);
                    react(new MessagingRunnable<Double>() {
                      protected void doRun(final Double msg) {
                        System.out.println("  Stage #1: " + msg);
                        react(new MessagingRunnable<List<Integer>>() {
                          protected void doRun(final List<Integer> msg) {
                            System.out.println("    Stage #2: " + msg + "\n");
                          }
                      });
                    }
                  });
                }
              });
            }
          });
        }
      }
    }

    laMer007, 03 Апреля 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    for (var i = 0; i < $('a').length; i++)
    {
        $('a')[i].click();
    }

    gost, 03 Апреля 2014

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

    −408

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    BOOL classDescendsFromClass(Class classA, Class classB)
    {
        while(classA)
        {
            if(classA == classB) return YES;
            classA = class_getSuperclass(classA);
        }
        
        return NO;
    }

    Why not just use isSubclassOfClass: ?

    ivandjeferov, 02 Апреля 2014

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

    +78

    1. 1
    2. 2
    3. 3
    wb.getApplication().run(macro, null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null);

    Использование библиотеки для взаимодействия с мелкософтовскими COM-объектами

    evg_ever, 02 Апреля 2014

    Комментарии (142)
  10. 1C / Говнокод #15648

    −163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    ВЫБОР
      КОГДА ПеремещениеТоваровТовары.ЕдиницаИзмерения = ПеремещениеТоваровТовары.Номенклатура.ЕдиницаХраненияОстатков
       ТОГДА ПеремещениеТоваровТовары.Количество * ПеремещениеТоваровТовары.Номенклатура.ЕдиницаХраненияОстатков.Коэффициент * ПеремещениеТоваровТовары.Номенклатура.бит_п_МассаНетто
      КОГДА ПеремещениеТоваровТовары.ЕдиницаИзмерения = ПеремещениеТоваровТовары.Номенклатура.ЕдиницаДляОтчетов
       ТОГДА ПеремещениеТоваровТовары.Количество * ПеремещениеТоваровТовары.Номенклатура.ЕдиницаДляОтчетов.Коэффициент * ПеремещениеТоваровТовары.Номенклатура.бит_п_МассаНетто
      КОГДА ПеремещениеТоваровТовары.ЕдиницаИзмерения = ПеремещениеТоваровТовары.Номенклатура.ЕдиницаИзмеренияМест
       ТОГДА ПеремещениеТоваровТовары.Количество * ПеремещениеТоваровТовары.Номенклатура.ЕдиницаИзмеренияМест.Коэффициент * ПеремещениеТоваровТовары.Номенклатура.бит_п_МассаНетто
      КОГДА ПеремещениеТоваровТовары.ЕдиницаИзмерения = ПеремещениеТоваровТовары.Номенклатура.бит_п_ЕдиницаПаллет
       ТОГДА ПеремещениеТоваровТовары.Количество * ПеремещениеТоваровТовары.Номенклатура.бит_п_ЕдиницаПаллет.Коэффициент * ПеремещениеТоваровТовары.Номенклатура.бит_п_МассаНетто
    КОНЕЦ

    iMoxa, 02 Апреля 2014

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