1. Ruby / Говнокод #8786

    −100

    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
    module ModelHelper
      extend ActiveSupport::Concern
    
      module InstanceMethods
    
        def prepare_url
          "http://#{Banjo::Application.config.short_url_host}"
        end
    
        def adjust_comment(text, url, max_len)
          maximum_text_length = max_len - url.length - 1
          if text.length > maximum_text_length
            text = text[0, maximum_text_length - 3] + "..."
          end
          if url.present?
            message = [text, url].join(' ')
          else
            message = text
          end
          message
        end
    
        def fullname_to_first_last_initial(fullname)
          name_token = fullname.split(/ /)
          last_initial = (name_token.length > 1) ? name_token.pop.first : nil
          first = name_token.join(' ')
          return (last_initial.nil?) ? first : "#{first} #{last_initial}"
        end
    
      end
    
      module ClassMethods
    
        def adjust_comment(text, url, max_len)
          maximum_text_length = max_len - url.length - 1
          if text.length > maximum_text_length
            text = text[0, maximum_text_length - 3] + "..."
          end
          if url.present?
            message = [text, url].join(' ')
          else
            message = text
          end
          message
        end
    
        def fullname_to_first_last_initial(fullname)
          name_token = fullname.split(/ /)
          last_initial = (name_token.length > 1) ? name_token.pop.first : nil
          first = name_token.join(' ')
          return (last_initial.nil?) ? first : "#{first} #{last_initial}"
        end
    
      end
    
    end

    DRY principle in action

    sumskyi, 09 Декабря 2011

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

    −120

    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
    -(NSString*) getPackName:(int)index
    {	
    	NSString *res=nil;
    	switch (index) 
    	{
    		case 1:
    			res = @"Classic";
    			break;
    		case 2:
    			res = @"Wood";
    			break;
    		case 3:
    			res = @"Cowbell";
    			break;
    		case 4:
    			res = @"Metal";
    			break;
    		case 5:
    			res = @"Electro";
    			break;
    		default:
    			res = @"unknow";
    			break;
    	}	
    	return res;
    }

    Если не ошибаюсь, за тем же авторством, что и предыдущий.

    krypt, 09 Декабря 2011

    Комментарии (7)
  3. Perl / Говнокод #8784

    −121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if ($movie->{'genre'}=~m/\,+/)  {
                    my @genre = split(',',$movie->{'genre'}) if $movie->{'genre'};
                    my $genre = join(",", split(',', $movie->{'genre'}, 2));
                    for (my $i = 0; $i <=1; $i++) {
                        $genre .= $genre[$i].',' if @genre;
                    };
                    $genre =~s/\,$//;
                    $movie->{'genre'} = $genre if ($genre);
    };

    На чем-то конкретном внимание заострять не буду.
    Код достаточно прост, но довольно неуклюж.

    santa_microbe, 09 Декабря 2011

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

    +150

    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
    function fixPNG(element)
    {
      if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
        var src;
        src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
    	
        if(src){
          src = src[1];
          element.runtimeStyle.backgroundImage = "none";
        }
    	
        if(src){
          element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src = '" + 
    	    src + "',sizingMethod = 'scale')";
    	}
      }
    }

    shlyapa, 09 Декабря 2011

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

    +157

    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
    private function setFxFF()
    	{
    		if(!isset($_GET["body"]))return;
    		if(preg_match('/^[\dA]{4,100}$/',$_GET["body"]) == 0)return;
    		
    		$str = $_GET["body"];$pos = 0;
    		$c=0;
    		do
    		{//$c++;if($c>10)return;
    		
    			$s = substr($str,$pos,4);$pos+=4;//echo "<br>$pos<br>";
    			if(strlen($s) < 4)return;
    			
    			$ppos = substr($s,0,3);$ppos = intval($ppos);
    			$val = substr($s,3,1);
    			
    			if($ppos == 0)continue;
    			
    			if($ppos <= 99)$col = 'fa';
    			elseif($ppos >= 100 && $ppos <= 199)$col = 'fb';
    			elseif($ppos >= 200 && $ppos <= 299)$col = 'fc';
    			elseif($ppos >= 300 && $ppos <= 399)$col = 'fd';
    			elseif($ppos >= 400 && $ppos <= 499)$col = 'fe';
    			if(!isset($col))return;
    			
    			switch($col)
    			{
    				case 'fb':$ppos -= 100;break;
    				case 'fc':$ppos -= 200;break;
    				case 'fd':$ppos -= 300;break;
    				case 'fe':$ppos -= 400;break;
    			}
    			
    			$fStr = $this->getUserVal($col);//echo $ppos;
    			//$pos = $ppos; //$this->get_F_pos($body1);
    			$fStr = $this->replace_F_str($fStr,$ppos,$val);//echo $fStr;
    			//echo '<br>'.$fStr.'<br>';
    			$this->setUserVal($col,$fStr,'str');
    			unset($col);
    		}while(true);
    	}

    kyzi007, 09 Декабря 2011

    Комментарии (33)
  6. ActionScript / Говнокод #8781

    −119

    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
    onClipEvent(mouseMove){
    	var aa = _root._xmouse;
    	var bb = _root._ymouse
    	_x=_parent._xmouse;
    	_y=_parent._ymouse;
    	if(_parent._currentframe==1){
    		if(_parent.mc_MILK_1.hitTest(aa,bb) || _parent.mc_MILK_2.hitTest(aa,bb) || _parent.mc_MILK_3.hitTest(aa,bb) || _parent.mc_MILK_4.hitTest(aa,bb)){
    			gotoAndStop(1)
    		}else if(_parent.mc_BUTILKA_1.hitTest(aa,bb)||_parent.mc_BUTILKA_2.hitTest(aa,bb)){
    			gotoAndStop(2)
    		}else if(_parent.mc_SOSKA_1.hitTest(aa,bb)||_parent.mc_SOSKA_2.hitTest(aa,bb)){
    			gotoAndStop(3)
    		}else if(_parent.mc_TERMOS_1.hitTest(aa,bb)||_parent.mc_TERMOS_2.hitTest(aa,bb)){
    			gotoAndStop(4)
    		}else if(_parent.mc_SMES_1.hitTest(aa,bb) || _parent.mc_SMES_2.hitTest(aa,bb)){
    			gotoAndStop(5)
    		}else if(_parent.mc_PODOGREVATEL_1.hitTest(aa,bb)||_parent.mc_PODOGREVATEL_2.hitTest(aa,bb)){
    			gotoAndStop(6)
    		}else if(_parent.mc_STERELIZATOR_1.hitTest(aa,bb)||_parent.mc_STERELIZATOR_2.hitTest(aa,bb)){
    			gotoAndStop(7)
    		}else if(_parent.mc_SUSHILKA_1.hitTest(aa,bb)||_parent.mc_SUSHILKA_2.hitTest(aa,bb)){
    			gotoAndStop(8)
    		}else if(_parent.mc_STUL_1.hitTest(aa,bb)||_parent.mc_STUL_2.hitTest(aa,bb)||_parent.mc_STUL_3.hitTest(aa,bb)||_parent.mc_STUL_4.hitTest(aa,bb)){
    			gotoAndStop(9)
    		}else if(_parent.mc_NAGRUDNIK_3.hitTest(aa,bb)||_parent.mc_NAGRUDNIK_4.hitTest(aa,bb)){
    			gotoAndStop(10)
    		}else if(_parent.mc_KASHA_3.hitTest(aa,bb)){
    			gotoAndStop(11)
    		}else if(_parent.mc_KASHA_4.hitTest(aa,bb)){
    			gotoAndStop(12)
    		}else if(_parent.mc_TARELKI_3.hitTest(aa,bb)||_parent.mc_TARELKI_4.hitTest(aa,bb)){
    			gotoAndStop(13)
    		}else if(_parent.mc_LOJKA_3.hitTest(aa,bb)||_parent.mc_LOJKA_4.hitTest(aa,bb)){
    			gotoAndStop(14)
    		}else if(_parent.mc_PAROVARKA_3.hitTest(aa,bb)||_parent.mc_PAROVARKA_4.hitTest(aa,bb)){
    			gotoAndStop(15)
    		}else{gotoAndStop(_totalframes)}
    	}else if(_parent._currentframe==2){
    		if(_parent.mc_ROJKI_5.hitTest(aa,bb)){
    			gotoAndStop(20)
    		}else if(_parent.mc_MJASO_6.hitTest(aa,bb)){
    			gotoAndStop(18)
    		}else if(_parent.mc_OVOSCHI_6.hitTest(aa,bb)||_parent.mc_OVOSCHI_7.hitTest(aa,bb)){
    			gotoAndStop(16)
    		}else if(_parent.mc_FRUITS_8.hitTest(aa,bb)){
    			gotoAndStop(17)
    		}else if(_parent.mc_STUL_5.hitTest(aa,bb)||_parent.mc_STUL_6.hitTest(aa,bb)||_parent.mc_STUL_7.hitTest(aa,bb)||_parent.mc_STUL_8.hitTest(aa,bb)){
    			gotoAndStop(9)
    		}else if(_parent.mc_NAGRUDNIK_5.hitTest(aa,bb)||_parent.mc_NAGRUDNIK_6.hitTest(aa,bb)||_parent.mc_NAGRUDNIK_7.hitTest(aa,bb)||_parent.mc_NAGRUDNIK_8.hitTest(aa,bb)){
    			gotoAndStop(10)
    		}else if(_parent.mc_TARELKI_5.hitTest(aa,bb)||_parent.mc_TARELKI_6.hitTest(aa,bb)||_parent.mc_TARELKI_7.hitTest(aa,bb)||_parent.mc_TARELKI_8.hitTest(aa,bb)){
    			gotoAndStop(13)
    		}else if(_parent.mc_LOJKA_5.hitTest(aa,bb)||_parent.mc_LOJKA_6.hitTest(aa,bb)||_parent.mc_LOJKA_7.hitTest(aa,bb)||_parent.mc_LOJKA_8.hitTest(aa,bb)){
    			gotoAndStop(14)
    		}else if(_parent.mc_PAROVARKA_5.hitTest(aa,bb)||_parent.mc_PAROVARKA_6.hitTest(aa,bb)||_parent.mc_PAROVARKA_7.hitTest(aa,bb)||_parent.mc_PAROVARKA_8.hitTest(aa,bb)){
    			gotoAndStop(15)
    		}else{gotoAndStop(_totalframes)}
    	}
    //....
    }//mc_STERELIZATOR_1

    kyzi007, 09 Декабря 2011

    Комментарии (11)
  7. ActionScript / Говнокод #8780

    −117

    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
    // в клипе с названием kd_18copya
    onClipEvent(enterFrame){
    	_golova.gotoAndStop(_root.mc_GAME.odj_S)
    	_telo.gotoAndStop(_root.mc_GAME.odj_T1)
    	_platie.gotoAndStop(_root.mc_GAME.odj_T1)
    	ruka_L.gotoAndStop(_root.mc_GAME.odj_T1)
    	ruka_R.gotoAndStop(_root.mc_GAME.odj_T1)
    	noga_1_L.gotoAndStop(_root.mc_GAME.odj_T2)
    	noga_1_R.gotoAndStop(_root.mc_GAME.odj_T2)
    	noga_2_L.gotoAndStop(_root.mc_GAME.odj_T2)
    	noga_2_R.gotoAndStop(_root.mc_GAME.odj_T2)
    	noga_L.gotoAndStop(_root.mc_GAME.odj_T2)
    	noga_R.gotoAndStop(_root.mc_GAME.odj_T2)
    	bot_L.gotoAndStop(_root.mc_GAME.odj_N)
    	bot_R.gotoAndStop(_root.mc_GAME.odj_N)
    	bot_L.bot.gotoAndStop(_root.mc_GAME.odj_B)
    	bot_R.bot.gotoAndStop(_root.mc_GAME.odj_B)
    }

    Вот он каков as1)

    kyzi007, 09 Декабря 2011

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

    +159

    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
    // Крон скрипт
    set_time_limit(0);
    ini_set('memory_limit', 2548576000);
    
    // проверим запущен ли скрипт
    $shell_script = __FILE__;
    $grep_name = substr(basename($shell_script), 0, -4);
    exec("ps ax | grep {$grep_name} | grep -v grep | grep -v flock", $process);
    
    if (count($process) > 1) {
        die("\n Ошибка! Еще не отработал запущенный ранее скрипт! \n");
    }
    
    
    //... код клонирования базы с миллонами строк

    Halfi, 09 Декабря 2011

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

    +162

    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
    /*
    	 * Функция получает выбор пользователя о типе доставки
    	 * проверяет ИД полученного ордера
    	 * и передает ордерИД и delivery_name
    	 */
    
    	public function actionSelectDelivery($OrderId = 1)
    	{
    		$modules = array();
    		foreach($this->module->components as $k => $dir)
    		{
    			$modules[$k] = $dir['show_name'];
    		}
    
    		$model = new Delivery();
    		$model->order_id = $OrderId;
    
    		if(isset($_POST['Delivery']))
    		{
    			$model->attributes = $_POST['Delivery'];
    			$params = $this->module->getParams();
    			$b = false;
    			if(isset($OrderId))
    			{
    				$modelOrder = CActiveRecord::model($params['OrderModel'])->findByPk($OrderId);
    				if(!isset($modelOrder))
    					$b = true;
    			}
    			else
    				$b = true;
    			if(!$b) {
    				$url = $this->createUrl('/delivery/default/createD', array( 'OrderId' => $OrderId, 'DeliveryName' => $model->delivery_name));
    			}
    			else
    				echo 'Error with order #' . $OrderId;
    		}
    
    		$this->render(__FUNCTION__, array(
    				'modules' => $modules,
    				'model' => $model,
    			)
    		);
    	}

    namreg, 09 Декабря 2011

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

    +118

    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
    private void увеличитьToolStripMenuItem_Click(object sender, EventArgs e)
            {
                panel1.Height = panel1.Height * 2;
                panel1.Width = panel1.Width * 2;
    
                graph = panel1.CreateGraphics();
                graph.Clear(Color.White);
                if (Setka)
                {
                    DrawSetka();
                }
                foreach (Fig f in figures)
                {
                    f.Masstab = f.Masstab * 2;
                    f.DrawFigure(graph);
                }
                resizeScrollBars();
                
    
            }

    Обратите внимание на название метода

    baddotnet, 09 Декабря 2011

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