1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #7655

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function utf8win1251($s){
      $out=""; $c1=""; $byte2=false;
      for ($c=0;$c<strlen($s);$c++){
        $i=ord($s[$c]); if ($i<=127) $out.=$s[$c];
        if ($byte2) { $new_c2=($c1&3)*64+($i&63); $new_c1=($c1>>2)&5;
          $new_i=$new_c1*256+$new_c2;
          if ($new_i==1025) $out_i=168; else
          if ($new_i==1105) $out_i=184; else $out_i=$new_i-848;
          $out.=chr($out_i); $byte2=false; }
        if (($i>>5)==6) {$c1=$i;$byte2=true; } }
     return $out; }

    Я ничо не понял, но это круто.

    http://letopisi.ru/index.php/Знаете-ли-что%3F_скрипт

    7ion, 25 Августа 2011

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

    −104

    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
    def entities(model, params = {})
            @entities                 ||= {}
            @entities[model]    ||= []
    
            if @entities[model].blank? or parameters_changed?(model, params)
              @entities[model]  = []
              include           = params[:include]  || nil
              group             = params[:group]    || nil
              order             = params[:order]    || nil
              page              = params[:page]     || nil
              entity_ids        = []
              model_role        = nil
              model_class       = model.to_s.classify.constantize
    
              if self.has_role_for?(model_class)
                self.roles_for(model_class).uniq.each do |role|
                  if role.authorizable_id.blank?
                    raise "Authorization problem! Found more than one #{model_class} model permission!" unless model_role.blank?
                    model_role = role.name
                    next
                  end
    
                  if !role.authorizable_id.blank? && MerchantRole::MERCHANT_ROLES.include?(role.name)
                    entity_ids << role.authorizable.id
                  end
                end
    
                if entity_ids.blank? and MerchantRole::MERCHANT_ROLES.include?(model_role)
                  #WARNING! RECURSION! EVIL!
                  if MerchantRole.has_entity_parent?(model)
                    parent_model    = MerchantRole.entity_parent(model)
                    parent_entities = self.entities(parent_model)
                    unless parent_entities.blank?
                      _params = {
                        :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`#{parent_model.to_s.singularize}_id` IN (?)", parent_entities.map(&:id)]),
                        :include => include,
                        :order => order,
                        :group => group
                      }
                      _params.merge!(:page => page) if params.keys.include?(:page)
                      if block_given?
                        (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                          yield o
                        end
                      else
                        @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                      end
                    end
                  else
                    _params = {
                      :conditions => conditions_and_parameters(params, nil),
                      :include => include,
                      :order => order,
                      :group => group
                    }
                    _params.merge!(:page => page) if params.keys.include?(:page)
       
                    if block_given?    #Find only merchants associated with the reseller or all merchants if we are no reseller.
                      (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                        yield o
                      end
                    else
                      @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                    end
                  end
                else
                  _params = { :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`id` IN (?)", entity_ids]),
                                       :include => include,
                                       :order => order,
                                       :group => group }
                   _params.merge!(:page => page) if params.keys.include?(:page)
                   if block_given?
                     model_class.each(_params) do |o|
                       yield o
                     end
                   else
                     @entities[model] = model_class.send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                   end
                 end
               end
            end
         entities[@model]
       end

    This method does the following (you guessed it, right?):

    #Fetch entities for which we have a read permission.
    #This is now it should work:
    #1. : If we don't have any role on the model, we won't get anything.
    #2a.: Check roles we have for whole model. If no role for whole model we can only fetch instances we have assigned.
    #2b.: Check all instances we have a role for and store them.
    #3a.: We have roles for instances -> Goto(#7)
    #3b.: We have no instance roles but have a role for the whole model.
    #4. : Check recusively if we have roles fro a parent model (channels -> merchants).
    #5a.: If we have a parent role and got parent entities returned we only fetch instances belonging to the parent entities.
    #6a.: If we have a parent role and got no entities back, then we won't get anything since we are not supposed to.
    #7. : Get all instances based on our reseller or globally for the system.

    emilpetkov, 25 Августа 2011

    Комментарии (6)
  4. PHP / Говнокод #7633

    +155

    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
    function otherString($str,$style)
    {
    	$str=trim($str);
    	switch($style)
    	{
    		case 1: $str=strip_tags($str); $str=str_replace("\n",'<br />',$str); break;
    		case 2:  break;
    		case 3: $str=strip_tags($str); $str=str_replace("\n",'',$str); $str=str_replace('<br />',"\n",$str); break;
    		case 4: $str=ereg_replace('(mailto:|mailto|http://|http:/|http:|http|ftp://|ftp:/|ftp:|ftp)','',$str);break;
    		case 5: $str=stripslashes($str); break;
    		case 6: $str=stripslashes($str); $str=strip_tags($str); break;
    		case 7: $str=strip_tags($str); break;
    	}
    	return $str;
    }

    web-based cms

    odmin, 24 Августа 2011

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    if(totalWidth1Part!=totalWidth2Part){
    		if(totalWidth1Part>totalWidth2Part){
    			if((totalWidth1Part - totalWidth2Part)>60){
    				if((totalWidth1Part - totalWidth2Part)>180){

    ...

    akopichin, 24 Августа 2011

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

    −132

    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
    found_files() 
    { 
     if [ "$DAY_CONF" = 'all_last' ]; then 
     files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep -v `date "$DATE_PREFIX"` ) 
     fi 
     
     if [ "$DAY_CONF" = 'last' ]; then 
     if [ "`date +%d`" -eq '01' ]; then 
     case "`date +%m`" in 
     02|04|06|09|11 ) 
     need_date=31; 
     ;; 
     03 ) 
     if [ -n "$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep `date +%Y0229` )" ]; then need_date=29; else need_date=28; fi; 
     ;; 
     * ) 
     need_date=30; 
     ;; 
     esac 
     if [ "`date +%m`" -eq '01' ]; then 
     need_month=12 
     need_date=31 
     need_year=$(( `date +%Y` - 1 )) 
     files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep "$need_year$need_month$need_date" ) 
     else 
     need_month=$((`date +%m` - 1 )) 
     files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | egrep `date ${DATE_PREFIX%%%m*}[0]*$need_month$need_date` ) 
     fi 
     else 
     need_date=$((`date +%d` - 1)) 
     files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | egrep `date ${DATE_PREFIX%%%d*}[0]*$need_date` ) 
     fi 
     fi 
     
     if [ "$DAY_CONF" = 'today' ]; then 
     files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep `date "$DATE_PREFIX"` ) 
     fi 
     echo $files 
    }

    Замечательная функция поиска файлов "за вчера". Находит файлы не только "за вчера".
    Автор неизвестен.

    SadKo, 23 Августа 2011

    Комментарии (6)
  7. Python / Говнокод #7568

    −85

    1. 1
    (1 if not i%2 else 2)

    Fai, 17 Августа 2011

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

    −116

    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
    BOOL levelClosed = YES;
    if (indexPath.row == 0)
    {
    	levelClosed = NO;
    }
    else
    {
    	iPadLevelDescriptor *prevLvlDescription = [levels objectAtIndex:(indexPath.row-1)];
    	scoresObject *prevLevelScoresObject = [ScoresTableUIViewController loadScoresForLevel:[[prevLvlDescription properties] objectForKey:kiPadLevelName]];
    	if (prevLevelScoresObject != nil)
    		levelClosed = ![prevLevelScoresObject completed];
    }
    levelClosed = NO;
    [cell setClosed:lvlClosed];

    Закрыт ли уровень?..

    1101_debian, 17 Августа 2011

    Комментарии (6)
  9. Python / Говнокод #7540

    −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
    # -*- coding: utf-8 -*-
    from Tkinter import *
    import time
    import random
    import os
    def init(): #Инициалиазия, переменная root, задаём размеры окна
    	global root, widthmin, widthmax, heightmin, heightmax, geometry
    	widthmin = 400 
    	widthmax = 400
    	heightmin = 400
    	heightmax = 400
    	geometry = str(widthmax) + 'x' + str(heightmax)
    	root = Tk()
    	root.geometry(geometry)
    	root.minsize(width=widthmin,height=heightmin)
    	root.maxsize(width=widthmax,height=heightmax)
    	menu()
    	root.mainloop()
            
    def menu(): #Меню игры. С любовью, кэп
    	global btSingle, btMulti, btSetting, btQuit
    	btSingle = Button(root, text="Singleplayer", command=singleplayer)
    	btSingle.pack(padx=15,pady=15)
    	btMulti = Button(root, text="Multiplayer", command=multiplayer)
    	btMulti.pack(padx=15,pady=15)
    	btSettings = Button(root, text="Settings", command=settings)
    	btSettings.pack(padx=15,pady=15)
    	btQuit = Button(root, text="Quit", command=quit)
    	btQuit.pack(padx=15,pady=15)
    	
    
    def singleplayer(): #Функции синглплеера
        global root #Удалить после заполнения функции более полезной хренью
    
    def multiplayer(): #Функции мультплеера
    	global root #Удалить после заполнения функции более полезной хренью
    
    def settings(): #Настройки
    	global root #Удалить после заполнения функции более полезной хренью
    	
    def quit(): #Выход из игры
    	root.destroy ()
    
    init()

    Burst_in, 13 Августа 2011

    Комментарии (6)
  10. Python / Говнокод #7519

    −92

    1. 1
    2. 2
    intToStr = { x:'%s'%x for x in range(-1000, 1000) }
    intToStr[-543]   # <- '-543'

    ЭТО ПИТОН!!!

    Fai, 11 Августа 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (isset($pp1)) mysql_query("UPDATE ".$prefix."_users SET pp1='$pp1' WHERE id='$user_id'");
    if (isset($pp2)) mysql_query("UPDATE ".$prefix."_users SET pp2='$pp2' WHERE id='$user_id'");
    if (isset($pp3)) mysql_query("UPDATE ".$prefix."_users SET pp3='$pp3' WHERE id='$user_id'");
    if (isset($pp4)) mysql_query("UPDATE ".$prefix."_users SET pp3='$pp4' WHERE id='$user_id'");
    if (isset($pp5)) mysql_query("UPDATE ".$prefix."_users SET pp3='$pp5' WHERE id='$user_id'");
    if (isset($pp6)) mysql_query("UPDATE ".$prefix."_users SET pp3='$pp6' WHERE id='$user_id'");
    if (isset($pp7)) mysql_query("UPDATE ".$prefix."_users SET pp3='$pp7' WHERE id='$user_id'");
    ...

    В бесконечность и далее!

    invision70, 07 Августа 2011

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