1. C++ / Говнокод #13128

    +18

    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
    word mofs[]={0,
                 31,
                 31+28,
                 31+28+31,
                 31+28+31+30,
                 31+28+31+30+31,
                 31+28+31+30+31+30,
                 31+28+31+30+31+30+31,
                 31+28+31+30+31+30+31+31,
                 31+28+31+30+31+30+31+31+30,
                 31+28+31+30+31+30+31+31+30+31,
                 31+28+31+30+31+30+31+31+30+31+30
    //          ,31+28+31+30+31+30+31+31+30+31+30+31
                };

    "Класс для работы с датами" взятый отсюда: http://yun.complife.ru/soft.htm

    bormand, 07 Июня 2013

    Комментарии (50)
  2. Perl / Говнокод #13127

    −172

    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
    sub company_stuff_add_array_elems
    {
            my $list = shift;
    
            my $count = 0;
    
            foreach ( @$list )
            {
                    $count += $_;
            }
    
            return $count;
    }

    List::Util::sum
    http://perldoc.perl.org/List/Util.html

    kainwinterheart, 07 Июня 2013

    Комментарии (20)
  3. Си / Говнокод #13126

    +114

    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
    #include <stdio.h>
         
        int main() {
            int i=5;
            switch ( 2 ) {
                case 0:
                    for (  i=0; i<10; i++ ) {
                case 1:
                    printf("A i=%d\n",i);
                case 2:
                    printf("B i*i=%d\n",i*i);
                    };
                case 3:
                    printf("done");
                    break;
            }
         
            return 0;
        }
         
        /* OUTPUT
        B i*i=25
        A i=6
        B i*i=36
        A i=7
        B i*i=49
        A i=8
        B i*i=64
        A i=9
        B i*i=81
        done
        */

    http://pastebin.com/EY3WQNzC - казехак.

    serpinski, 06 Июня 2013

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

    +69

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public static String generateName(String baseName, int length) {
        if (length < 1) {
            length = Math.abs(length);
        }
        if(length == 0){
            length = 1;
        }
        if (length > 36) {
            length = length % 36;
        }
        return baseName + "_" + UUID.randomUUID().toString().substring(0, length).replaceAll("[-]", "");
    }

    Должна была быть генерация строки заданной общей длины с пятизначным хешем в конце.

    Actine, 06 Июня 2013

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

    +70

    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
    @OnEvent("search")
    	@ReportGritter(title = "message:error", text = "message:database_error")
    	Results search() {
    		final List<Result> results = new ArrayList<Result>();
    		int count = 0;
    		final List<?> search1 = this.bands.search(this.query);
    		final String group1 = HSSearch.GROUP_BANDS;
    		if (!search1.isEmpty()) {
    			results.addAll(this.transform(search1, group1));
    			count += search1.size();
    		}
    		final List<?> search2 = this.albums.search(this.query);
    		final String group2 = HSSearch.GROUP_ALBUMS;
    		if (!search2.isEmpty()) {
    			results.addAll(this.transform(search2, group2));
    			count += search2.size();
    		}
    		final List<?> search3 = this.tracks.search(this.query);
    		final String group3 = HSSearch.GROUP_TRACKS;
    		if (!search3.isEmpty()) {
    			results.addAll(this.transform(search3, group3));
    			count += search3.size();
    		}
    		this.results.setResults(results);
    		this.results.setCount(count);
    		return this.results;
    	}
    
    	private <E> String toTitle(final E item) {
    		if (item instanceof BandEntity) {
    			return ((BandEntity) item).getTitle();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return String.format("%s (%d)", aitem.getTitle(), Integer.valueOf(aitem.getYear()));
    		}
    		if (item instanceof TrackEntity) {
    			return ((TrackEntity) item).getTitle();
    		}
    		return item.toString();
    	}
    
    	private <E> String toUrl(final E item) {
    		if (item instanceof BandEntity) {
    			final BandEntity bitem = (BandEntity) item;
    			return this.links.createPageRenderLinkWithContext(Band.class, bitem.getLetter(), bitem.getAlias())
    					.toAbsoluteURI();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, aitem.getBand().getLetter(),
    					aitem.getBand().getAlias(), aitem.getAlias()).toAbsoluteURI();
    		}
    		if (item instanceof TrackEntity) {
    			final TrackEntity titem = (TrackEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, titem.getAlbum().getBand().getLetter(),
    					titem.getAlbum().getBand().getAlias(), titem.getAlbum().getAlias()).toAbsoluteURI();
    		}
    		return this.links.createPageRenderLinkWithContext("").toAbsoluteURI();
    	}
    
    	private <E> List<Result> transform(final List<E> search, final String groupName) {
    		final ArrayList<Result> res = new ArrayList<Result>();
    		if (!search.isEmpty()) {
    			final String group = this.messages.get(groupName);
    			res.add(new Result(group));
    			for (final E item : search) {
    				res.add(new Result(group, this.toTitle(item), this.toUrl(item)));
    			}
    		}
    		return res;
    	}

    DRY in Action.
    мое домашнее творчество.

    Lure Of Chaos, 06 Июня 2013

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    changeFace($arr) {
            switch ($arr['custtype']) {
                    case 2: $facetype = 'Ф'; break; //Физическое
                    case 1: $facetype = 'Ю'; break; //Юридическое лицо
                    default: $facetype = ' '; break;
            }
            return $facetype;
    }

    В этом смысле лицо - "person"

    DIX315, 06 Июня 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    PUBLIC STATIC FUNCTION /* ЭТО Я НЕ КАПСОМ ПИШУ, ЭТО Я ШИФТ ДЕРЖУ */ selectFor_confirm($delivery_mode, PtrCustomSelector $order_sel)
        {
            /* ... */
        }

    Последствия пятничного deadline-кодинга ^_^

    AntonioK, 06 Июня 2013

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

    +152

    1. 1
    2. 2
    // maybe even strtolower($value)?
    $bool = ($value && ($value !== 'false') && ($value !== 'null'));

    А разгадка одна — безблагодатность^w кривой JSON.

    AntonioK, 06 Июня 2013

    Комментарии (0)
  9. C++ / Говнокод #13120

    +8

    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
    void Cluster::CloseConnection()
    {
        m_Connection->close();
        if (!m_Connection->IsOK())
            throw ConnectionError(m_Connection->LastError());
    }
    
    void ClusterGroup::RemoveCluster(int iIndex)
    {
        Cluster *pSubCluster = m_SubClusters->At[i];
        pSubCluster->CloseConnection();
        delete pSubCluster;
        m_SubClusters->SetAt(i, NULL);
    }

    И потекло...

    Lavir_the_Whiolet, 06 Июня 2013

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $currurl = str_replace(" ", '', $this->helper('core/url')->getCurrentUrl());
    if (strpos($currurl, 'index.php/')) {
        $currurl = str_replace('index.php/', '', $currurl);
    } else if (strpos($currurl, '/index.php')) {
        $currurl = str_replace('index.php', '', $currurl);
    }
    $url_suffix = (substr($currurl, strlen(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB))));
    <?php if (strlen($url_suffix) <= 0) : #not homepage ?>
    ...

    Magento. Увидел в template, код одной английской компании.

    crook, 06 Июня 2013

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