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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    double numberOfDays = (eventWrite.EndDate - eventWrite.StartDate).Days;
    int numberOfSteps = (int)numberOfDays / 365;
    if (numberOfDays / 365 % 4.0027397260273974 == 0)
                numberOfSteps++;

    Сколько раз повторится ежегодное событие с учётом високосного года

    SUDALV, 26 Ноября 2013

    Комментарии (47)
  2. C++ / Говнокод #14139

    +69

    1. 1
    2. 2
    #define BYTEMAX 0xFF 
    #define BYTEOVERFLOW (BYTEMAX+1)

    C++ вокруг. Интересует насколько это вменяемая практика?

    LispGovno, 26 Ноября 2013

    Комментарии (64)
  3. C# / Говнокод #14138

    +134

    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
    public bool SqlTest(string sql)
            {
                try
                {
                    if (Utils.ExecuteScalar(sql).ToString() != "8") throw new Exception("Bad result from DB!");
                }
                catch (Exception ex)
                {
                    LogService.WriteStd("CheckDBRun1: " + sql, ex);
                    Utils.SQLServerRun();
                    try
                    {
                        if (Utils.ExecuteScalar(sql).ToString() != "8") throw new Exception("Bad result from DB!");
                    }
                    catch (Exception ex2)
                    {
                        LogService.WriteStd("CheckDBRun2: " + sql, ex2);
                        return false;
                    }
                }
                return true;
            }

    taburetka, 26 Ноября 2013

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

    +135

    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
    static int
    wl_iw_get_country(
            struct net_device *dev,
            struct iw_request_info *info,
            union iwreq_data *wrqu,
            char *extra
    )
    {
    	char *ccode;
    	int current_channels;
    	
    	WL_TRACE(("%s\n", __FUNCTION__));
    
    	ccode = dhd_bus_country_get(dev);
    	if(ccode){
    		if(0 == strcmp(ccode, "Q2"))
    			current_channels = 11;
    		else if(0 == strcmp(ccode, "EU"))
    			current_channels = 13;
    		else if(0 == strcmp(ccode, "JP"))
    			current_channels = 14;
    	}
    	sprintf(extra, "Scan-Channels = %d", current_channels);
    	printk("Get Channels return %d,(country code = %s)\n",current_channels, ccode);	
    	return 0;
    }

    На этот раз отличился броадком.
    Подсказка: Пользователи с кантри-кодом RU должны СТРАДАТЬ!

    Necromant, 25 Ноября 2013

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

    +136

    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
    /*
     * Just a wifi driver hooker.
     *
     * Yongle Lai @ 2009-05-10 @ Rockchip
     */
    
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    
    MODULE_LICENSE("Dual BSD/GPL");
    
    #ifdef CONFIG_MODVERSIONS
    #define MODVERSIONS
    #include <linux/modversions.h>
    #endif 
    
    //#define OLD_WIFI_IFACE
    
    #ifdef OLD_WIFI_IFACE
    extern int mv88w8686_if_sdio_init_module(void);
    extern void mv88w8686_if_sdio_exit_module(void);
    #else
    extern int rockchip_wifi_init_module(void);
    extern void rockchip_wifi_exit_module(void);
    #endif
    
    static int wifi_launcher_init(void) 
    {
      int ret;
    
      printk("=======================================================\n");
      printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n");
      printk("=======================================================\n");
    
    #ifdef OLD_WIFI_IFACE
      ret = mv88w8686_if_sdio_init_module();
      if (ret) /* Try again */
            ret = mv88w8686_if_sdio_init_module();
    #else
      ret = rockchip_wifi_init_module();
      //if (ret) /* Try again */
      //    ret = rockchip_wifi_init_module();
    #endif
    
      return ret;
    }
    
    static void wifi_launcher_exit(void) 
    {
      printk("=======================================================\n");
      printk("== Dis-launching Wi-Fi driver! (Powered by Rockchip) ==\n");
      printk("=======================================================\n");
    
    #ifdef OLD_WIFI_IFACE
      mv88w8686_if_sdio_exit_module();
    #else
      rockchip_wifi_exit_module();
    #endif
    }
    
    module_init(wifi_launcher_init);
    module_exit(wifi_launcher_exit);

    Вот так вот, просто и незатейливо на RK3188 включается и выключается вайфай.

    Necromant, 25 Ноября 2013

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int rkwifi_set_country_code(char *code)
    {
    	sprintf(code, "%s", "EU");
    	return 0;
    }

    Где-то в сырцах драйвера вайфая от RK3188...

    Necromant, 25 Ноября 2013

    Комментарии (2)
  7. Куча / Говнокод #14134

    +131

    1. 1
    http://bolknote.ru/files/dogfight/

    Возбуждает

    Stertor, 24 Ноября 2013

    Комментарии (13)
  8. JavaScript / Говнокод #14130

    +153

    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
    App.ns.SomeClass.prototype = {
        addMessage: function(status, msg, timeDelay) {
            if (status === false || status === this.STATUS_ERROR) {
                status = this.STATUS_ERROR;
                delay = timeDelay || 5; // default delay of msg box for error is 5 seconds. 
            }
            if (!timeDelay) {
                // 1 character - 1/7 sec 
                delay = msg.length / 7;
                if ((delay < 3) && !(timeDelay)) {
                    delay = 3;
                } else if ((delay > 30) && !(timeDelay)) {
                    delay = 30;
                    }
            }
            // показываем messagebox
        }
    };

    Кручу-верчу, запутать хочу.

    Elvenfighter, 24 Ноября 2013

    Комментарии (4)
  9. Pascal / Говнокод #14129

    +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
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    procedure tnewthread.checkfiles; // процедура выполняется в потоке
    var
      i:integer;
      status:tstatus;
      ptmp:array of char;
      temp:string;
      len:integer;
      fstream:tfilestream;
    begin
      flist.Clear;
      findfiles(findpath);
      for i:=flist.Count-1 downto 0 do
      begin
        status:=s_ok;
        try
          try
            fstream:=tfilestream.Create(flist[i],fmopenread);
            fstream.Position:=0;
            setlength(ptmp,fstream.size);
            fstream.Read(pointer(ptmp)^,fstream.size);
          except
            status:=s_error;
          end;
        finally
          fstream.free;
        end;
        temp:=string(pchar(ptmp));
        temp:=stringreplace(temp,'&nbsp;',' ',[rfreplaceall]);
        temp:=stringreplace(temp,'&gt;','>',[rfreplaceall]);
        temp:=stringreplace(temp,'&nbsp;',' ',[rfreplaceall]);
        temp:=stringreplace(temp,'&lt;','<',[rfreplaceall]);
        temp:=stringreplace(temp,'&amp;','&',[rfreplaceall]);
        temp:=stringreplace(temp,'&quot;','"',[rfreplaceall]);
        temp:=stringreplace(temp,'&copy;',#169,[rfreplaceall]);
        temp:=stringreplace(temp,#10,#13#10,[rfreplaceall]);
        Len := Length(temp);
        try
          try
            fstream:=tfilestream.Create('C:\1.txt',fmcreate); // заменил в целях теста, не помогает.
            fstream.Position:=0;
              fstream.WriteBuffer(temp[1], Len); // в этом  месте поток вылетает с ошибкой "Range check error"
          except
            status:=s_error;
          end;
        finally
          fstream.free;
        end;
        if status=s_ok then
        begin
          addfileinfo(flist[i]); 
          shrecyclefile(flist[i]);
        end
        else
        begin
          adderrinfo(flist[i]); // синхронизируемся с мемо и добавляем в него красную строчку с именем файла
          shmovefile(flist[i],erroroutputpath +'\' + extractfilename(flist[i])); // перемещаем файл в директорию с файлами, при обр. которых произошла ошибка
        end;
      end;
    end;

    Процедура для обработки текстовых файлов. Имеем дремлющий поток, залоченный waitsingleobject, который будит
    таймерная функция, если в папке есть по крайней мере 1 файл. т.е. одновременно к файлам обращается 1 поток.
    При разлочивании поток немедленно начинает заполнять лист именами файлов, после чего начинает прогонять их
    через процедуру-обработчик. Но вот беда - возникает ошибка range check error. причем возникает только в доп.потоке -
    вне потока все работает нормально. Товарищи ,не подскажете, в чем лажа? (

    Stertor, 24 Ноября 2013

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

    +161

    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
    function foo(id) {
          document.getElementById('1').style.display='none';
          document.getElementById('46').style.display='none';
          document.getElementById('2').style.display='none';
          document.getElementById('53').style.display='none';
          document.getElementById('55').style.display='none';
          document.getElementById('56').style.display='none';
          document.getElementById('57').style.display='none';
          document.getElementById('58').style.display='none';
    if (document.getElementById(id).style.display == "none")
             {document.getElementById(id).style.display = "block"}
    else
             {document.getElementById(id).style.display = "none"}
    }

    Прислали с бывшей работы.
    %%Саша, я таки ушёл.%%

    хуита, 24 Ноября 2013

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