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

    +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
    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
    xlApp = new Excel.Application();
                try
                {
                    xlApp.Workbooks.Add(Type.Missing);
    
                    xlApp.Interactive = false;
                    xlApp.EnableEvents = false;
    
                    xlSheet = (Excel.Worksheet)xlApp.Sheets[1];
                    xlSheet.Name = "Данные";
    
                    DataTable dt = GetData();
    
                    int collInd = 0;
                    int rowInd = 0;
                    string data = "";
    
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        data = dt.Columns[i].ColumnName.ToString();
                        xlSheet.Cells[1, i + 1] = data;
    
                        xlSheetRange = xlSheet.get_Range("A1:Z1", Type.Missing);
    
                        xlSheetRange.WrapText = true;
                        xlSheetRange.Font.Bold = true;
                    }
    
                    for (rowInd = 0; rowInd < dt.Rows.Count; rowInd++)
                    {
                        for (collInd = 0; collInd < dt.Columns.Count; collInd++)
                        {
                            data = dt.Rows[rowInd].ItemArray[collInd].ToString();
                            xlSheet.Cells[rowInd + 2, collInd + 1] = data;
                        }
                    }
    
                    xlSheetRange = xlSheet.UsedRange;
    
                    xlSheetRange.Columns.AutoFit();
                    xlSheetRange.Rows.AutoFit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    xlApp.Visible = true;
    
                    xlApp.Interactive = true;
                    xlApp.ScreenUpdating = true;
                    xlApp.UserControl = true;
    
                    releaseObject(xlSheetRange);
                    releaseObject(xlSheet);
                    releaseObject(xlApp);
                }

    orozov, 04 Апреля 2014

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

    +65

    1. 1
    2. 2
    3. 3
    4. 4
    Graphics2D g = ...;
    String str = "Some string";
    FontRenderContext frc = g.getFontRenderContext();
    double height = g.getFont().createGlyphVector(frc, str).getPixelBounds(null, 0, 0).getHeight();

    Мне нужно было узнать точную высоту строки, которую я рисую на объекте Image. Спасибо stackoverflow за то, что он есть, по-моему, до этого способа просто невозможно догадаться, даже копая документацию, за несколько часов...

    evg_ever, 03 Апреля 2014

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

    +152

    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
    $manufacturer_id = JRequest::getInt('manufacturer_id');
                $label_id = JRequest::getInt('label_id');
                $vendor_id = JRequest::getInt('vendor_id');
               
                $view_name = "cart";
                $view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
                $view = $this->getView($view_name, getDocumentType(), '', $view_config);
                        if ($category->category_template=="") $category->category_template="default";
                $view->setLayout("category_".$category->category_template);        
         
                $jshopConfig->count_products_to_page = $category->products_page;
         
                $context = "jshoping.list.front.product";
                $contextfilter = "jshoping.list.front.product.cat.".$category_id;
                $orderby = $mainframe->getUserStateFromRequest( $context.'orderby', 'orderby', $jshopConfig->product_sorting_direction, 'int');
                $order = $mainframe->getUserStateFromRequest( $context.'order', 'order', $jshopConfig->product_sorting, 'int');
                $limit = $mainframe->getUserStateFromRequest( $context.'limit', 'limit', $category->products_page, 'int');
                if (!$limit) $limit = $category->products_page;
                $limitstart = JRequest::getInt('limitstart');
         
                $orderbyq = getQuerySortDirection($order, $orderby);
                $image_sort_dir = getImgSortDirection($order, $orderby);
                $field_order = $jshopConfig->sorting_products_field_select[$order];
                $filters = getBuildFilterListProduct($contextfilter, array("categorys"));
                $orderfield = $jshopConfig->category_sorting==1 ? "ordering" : "name";
                $sub_categories = $category->getChildCategories($orderfield, 'asc', $publish = 1);
                $dispatcher->trigger( 'onBeforeDisplayCategory', array(&$category, &$sub_categories) );
         
                if ($category->meta_title=="") $category->meta_title = $category->name;
                setMetaData($category->meta_title, $category->meta_keyword, $category->meta_description);
               
                $total = $category->getCountProducts($filters);
                $action = xhtmlUrl($_SERVER['REQUEST_URI']);
                       
                        $dispatcher->trigger('onBeforeFixLimitstartDisplayProductList', array(&$limitstart, &$total, 'category'));
                if ($limitstart>=$total) $limitstart = 0;
         
                $products = $category->getProducts($filters, $field_order, $orderbyq, $limitstart, $limit);
                        addLinkToProducts($products, $category_id);
         
                jimport('joomla.html.pagination');
                $pagination = new JPagination($total, $limitstart, $limit);
                $pagenav = $pagination->getPagesLinks();
               
                foreach($jshopConfig->sorting_products_name_select as $key=>$value){
                    $sorts[] = JHTML::_('select.option', $key, $value, 'sort_id', 'sort_value' );
                }
         
                insertValueInArray($category->products_page, $jshopConfig->count_product_select); //insert category count
                foreach ($jshopConfig->count_product_select as $key => $value){
                    $product_count[] = JHTML::_('select.option',$key, $value, 'count_id', 'count_value' );
                }
                $sorting_sel = JHTML::_('select.genericlist', $sorts, 'order', 'class = "inputbox" size = "1" onchange = "submitListProductFilters()"','sort_id', 'sort_value', $order );
                $product_count_sel = JHTML::_('select.genericlist', $product_count, 'limit', 'class = "inputbox" size = "1" onchange = "submitListProductFilters()"','count_id', 'count_value', $limit );
               
                $_review = JTable::getInstance('review', 'jshop');
                $allow_review = $_review->getAllowReview();
               
                if (!$category->category_ordertype) $category->category_ordertype = 1;
               
                $manufacuturers_sel = '';
                if ($jshopConfig->show_product_list_filters){
                    $filter_manufactures = $category->getManufacturers();
                    $first_manufacturer = array();
                    $first_manufacturer[] = JHTML::_('select.option', 0, _JSHOP_ALL, 'id', 'name');
                    if (isset($filters['manufacturers'][0])){
                        $active_manufacturer = $filters['manufacturers'][0];            
                    }else{
                        $active_manufacturer = 0;
                    }
                    $manufacuturers_sel = JHTML::_('select.genericlist', array_merge($first_manufacturer, $filter_manufactures), 'manufacturers[]', 'class = "inputbox" onchange = "submitListProductFilters()"','id', 'name', $active_manufacturer);
                }
                $display_list_products = (count($products)>0 || willBeUseFilter($filters));
         
                $dispatcher->trigger('onBeforeDisplayProductList', array(&$products));
                $view->assign('config', $jshopConfig);
                $view->assign('template_block_list_product', "cart/list_products.php");
                $view->assign('template_block_form_filter', "cart/form_filters.php");
                $view->assign('template_block_pagination', "cart/block_pagination.php");
                $view->assign('path_image_sorting_dir', $jshopConfig->live_path.'images/'.$image_sort_dir);
                $view->assign('filter_show_category', 0);
                $view->assign('display_pagination', $pagenav!="");
                $view->assign('rows', $products);
                $view->assign('count_product_to_row', $category->products_row);
                $view->assign('filters', $filters);
                $view->assign('display_list_products', $display_list_products);
                $view->assign('shippinginfo', SEFLink($jshopConfig->shippinginfourl,1));
                $view->display();

    Все это (пришлось еще отрезать строк 30) нужно таскать за собой для вывода списка товаров в нестандартном месте. При этом оно лежит в контроллере.
    Полный код: http://pastebin.com/jTj83ZpE
    (joomshopping)

    attn, 03 Апреля 2014

    Комментарии (2)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)