1. PHP / Говнокод #13473

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if( $yandexXML==false ){
       //...
    }
    elseif( $yandexXML==true ){
       //...
    }

    не ну а вдруг как бы че

    CRRaD, 25 Июля 2013

    Комментарии (10)
  2. JavaScript / Говнокод #13472

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function check_fio() {
      var space = /^\s/;
      var fio = $("#form_fio").val();
      var fio_length = fio.length - 1;
      if (fio[fio_length].match(space)) {
        fio = fio.substring(0, fio.length - 1);
        $("#form_fio").val(fio);
        check_fio();
      }
    }

    Казалось бы, удаление пробелов в конце строки, что может быть проще.

    newmindcore, 25 Июля 2013

    Комментарии (8)
  3. Python / Говнокод #13471

    −98

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    try:
       while True:
           prices.remove(u"")
       except ValueError:
           pass

    Удаление пустых строк из списка.

    FlySnake, 24 Июля 2013

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

    +142

    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
    // main.cpp
    #include <stdio.h>
    #include <stdlib.h>
    //...
    #include "tcp.h"
    //...
    #include "tcp.c"
    //...
    int main(int argc, char ** argv)
    {
    //...
    		receive_tcp_message(sock, &tcp_msg);
    		switch(tcp_msg.type)
    		{
    #include "cases.h"
    		default:
    			break;
    		}
    //...
    }

    Имелась небольшая утилита, написанная матёрым сишником. Имелся еще меньший шаблонный проект для таких утилит, написанный на плюсах с простым makefile. Таким вот нехитрым способом этот сишник влил первое во второе. Он не пользуется makefile, т.к. обычно пишет шелл-скрипт, собирающий весь проект. А еще он знает кучу анекдотов и историй, выпить не дурак и вообще отличный дядька.

    Xom94ok, 24 Июля 2013

    Комментарии (91)
  5. Си / Говнокод #13467

    +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
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    #define max    0x08         //Max number of samples to average/filter
    #define byte unsigned char
    #define word unsigned int
    #define dword unsigned long
    
    #define FILTER 0
    #define AVG 1
    
    typedef struct  {
      word  reading[max];
      word  result[max];
    } ResultStct;
    
    
    static ResultStct x;
    static char samp = 0;//filter;
    const byte filter_mode = FILTER;
    
    extern int avg_result;
    
    void MYfilter(word input_sample) 
    {
      byte j;
      dword X;
        
    	x.reading[samp] = input_sample;
      
    	if(samp>0){
    
    		X=0;
    		for (j=0;j<=samp;j++){
    		  X += x.reading[j];
    		}
    		avg_result = (X >> 3) - 0x0200;
    		
    	} 
       
    	// Shift array of results if we hit max
    	if (samp >= max-1) {
    		for (j=0;j<max-1;j++){
    			x.result[j]  = x.result[j+1];
    			x.reading[j] = x.reading[j+1];
    		}
    		samp = max-1;
    	}
    	else 
    	{
    		samp++;
    	} //end if (i => max)

    Такой вот МОЩНЕЙШИЙ фильтр встретился в одном проекте.

    _113, 24 Июля 2013

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

    +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
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    if (IsSetPrinter)
                            {
                                if (Counter == 0)
                                {
                                    printingIsOkay = PrintDocument(letterIDsString
                                   , row.DocumentTemplateVersionID
                                   , row.DocumentTemplate
                                   , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                   , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                   , true
                                   , Counter
                                   , Counter == documentTemplateVersions.Count - 1);
                                }
                                else
                                {
                                    printingIsOkay = PrintDocument(letterIDsString
                                  , row.DocumentTemplateVersionID
                                  , row.DocumentTemplate
                                  , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                  , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                  , false
                                  , Counter
                                  , Counter == documentTemplateVersions.Count - 1);
                                }
    
                            }
                            else
                            {
                                printingIsOkay = PrintDocument(letterIDsString
                                   , row.DocumentTemplateVersionID
                                   , row.DocumentTemplate
                                   , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                   , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                   , false
                                   , Counter
                                   , Counter == documentTemplateVersions.Count - 1);
                            }

    Я бы выложил весь класс. Он весь такой. Но, думаю, вы поняли кто писал?

    kore_sar, 23 Июля 2013

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

    +147

    1. 1
    eval("document.getElementById('bmnu_rbt').onclick = function () { menu_to_left(); }");

    Без комментанриев

    kostoprav, 22 Июля 2013

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

    −101

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    @implementation NSString (toint)
    - (long long)toInt {
        if (self == nil) return 0;
        if (self.length == 0) return 0;
       return [self longLongValue];
    }
    @end

    В этом коде все прекрасно. Я просто оставлю это здесь. Джава головного мозга.

    notxcain, 22 Июля 2013

    Комментарии (18)
  9. Objective C / Говнокод #13463

    −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
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    - (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
    {
        if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
        {
            return nil;
        };
    
        NSFetchRequest *fr=[[NSFetchRequest alloc] init];
        [fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
        [fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
        [fr setIncludesPropertyValues:YES];
        NSError *err;
        NSArray *res=[context executeFetchRequest:fr error:&err];
        if (err!=nil)
        {
            NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
            return nil;
        }
        else
        {
            if ([res count]<=0)
            {
                NSLog(@"[res count]<=0");
                //NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
                return nil;
            }
            else if([res count]>1)
            {
                NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
                return nil;
            }
            else //[res count] == 1
            {
                return [res objectAtIndex:0];
            };
        };
    }

    Фетч

    stanislaw, 21 Июля 2013

    Комментарии (20)
  10. Pascal / Говнокод #13462

    +141

    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
    if x > 0 then 
    begin
    if y <= 0 then 
    begin
    if z <> 0 then 
    begin
    if x1 > 0 then 
    begin
    if y1 < 7 then 
    begin
    if z1 > 0 then 
    begin
    if z1 mod 5 = 0 then 
    begin
    if m <> 3 then 
    begin
    if n > 5 then 
    begin
    writeln('1');
    end;
    end;
    end;
    end;
    end;
    end;
    end;
    end;
    end;

    iNsectus, 21 Июля 2013

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