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

    +144

    1. 1
    sleh = UpCase(92); // просто слеш

    Просто слеш.

    bormand, 22 Мая 2015

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

    +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
    21. 21
    22. 22
    23. 23
    24. 24
    QString queryString = QString("SELECT `angle`, `heights` FROM `heights%1` WHERE `angle` / 10 ").arg(camera->cid());
    
    	if (from <= 0 || to > 360)
    	{
    		if (from <= 0) // to the right of North
    		{
    			from += 360;
    
    			qSwap<double>(from, to);
    		}
    		else if (to > 360) // to the left of North
    		{
    			to -= 360;
    
    			qSwap<double>(from, to);
    		}
    
    		from += 0.1;
    		to -= 0.1;
    
    		queryString += "NOT ";
    	}
    
    	queryString += QString("BETWEEN %1 AND %2").arg(from, 0, 'f', 1).arg(to, 0, 'f', 1);

    извращался как мог, сколько дадите по шкале от 0 до 10?

    Wexter, 22 Мая 2015

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

    +143

    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
    /* Example libCello Program */
    
    #include "Cello.h"
    
    int main(int argc, char** argv) {
    
      /* Stack objects are created using "$" */
      var int_item = $(Int, 5);
      var float_item = $(Real, 2.4);
      var string_item = $(String, "Hello");
    
      /* Heap objects are created using "new" */
      var items = new(List, int_item, float_item, string_item);
    
      /* Collections can be looped over */
      foreach (item in items) {
        /* Types are also objects */
        var type = type_of(item);
        print("Object %$ has type %$\n", item, type);
      }
    
      /* Heap objects destroyed with "delete" */
      delete(items); 
    }

    http://libcello.org/

    dxd, 22 Мая 2015

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

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private String compId(final String name) {
    		final Pattern compiled = Pattern.compile("^on([_A-Za-z0-9]+)From([_A-Za-z0-9]+)$");
    		final Matcher matcher = compiled.matcher(name);
    		return matcher.matches() ? matcher.group(2) : null;
    	}
    
    	private String compEvent(final String name) {
    		final Pattern compiled = Pattern.compile("^on([_A-Za-z0-9]+)(From([_A-Za-z0-9]+))?$");
    		final Matcher matcher = compiled.matcher(name);
    		return matcher.matches() ? matcher.group(1) : null;
    	}

    Lure Of Chaos, 22 Мая 2015

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

    +145

    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
    this.serializeParams = function(params) {                                                                 
            var serialize = [];                                                                                   
            var buildParameters = function (parameters) {                                                         
                var result = {};                                                                                  
                if(typeof parameters == "object") {                                                               
                    for(var param in parameters) {                                                                
                        if(!parameters.hasOwnProperty(param)) {                                                   
                            continue;                                                                             
                        }                                                                                         
                        result[param] = buildParameters(parameters[param]);                                       
                    }                                                                                             
                }                                                                                                 
                if(typeof parameters == "string") {                                                               
                    return parameters;                                                                            
                }                                                                                                 
                return result;                                                                                    
            };                                                                                                    
            console.log(buildParameters(params));                                                                 
            for (var param in params) {                                                                           
                if(!params.hasOwnProperty(param)) {                                                               
                    continue;                                                                                     
                }                                                                                                 
                buildParameters(params[param]);                                                                   
                serialize.push(param + '=' + params[param]);                                                      
            }                                                                                                     
            if (serialize.length === 0) {                                                                         
                return '';                                                                                        
            }                                                                                                     
            return (this.options.method === "GET" ? "?" : "") + serialize.join('&');                              
        };

    В голове выглядело все идеально а получилось что то типа
    for(var i = 0; i < 1e10; i++) { continue; } // бесполезная работа

    LarexSetch, 22 Мая 2015

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

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if((pDir = opendir(pchPath)) != NULL)
    {
        strcpy(chBuffer, pchPath);
        strcat(chBuffer, "/");
        while((pTemp == NULL) && ((pDirent = readdir(pDir)) != NULL))
        {
            if(((pChar = strstr(pDirent->d_name, Info.pchFilePrefix)) == pDirent->d_name) &&
               ((pChar = strstr(pDirent->d_name, Info.pchFileExtension)) != NULL)  &&
               (pChar[strlen(Info.pchFileExtension)] == '\0'))
            {
                sprintf(strrchr(chBuffer, '/') + 1, "%s", pDirent->d_name);

    лаконичные программисты лаконично ходят по каталогам.

    Dummy00001, 21 Мая 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    do
      { 
    ...
      } while ((strcmp(input,"") != 0)); /* till end of string */

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

    ivanria, 21 Мая 2015

    Комментарии (79)
  8. Си / Говнокод #18214

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    p_bmp280->calib_param.dig_P2 = (s16)(((
    (s16)((s8)a_data_u8[BMP280_PRESSURE_CALIB_DIG_P2_MSB]))
    << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
    | a_data_u8[BMP280_PRESSURE_CALIB_DIG_P2_LSB]);

    Требуется больше приведений

    из библиотеки для датчика давления BOSH280.
    PS s16 dig_P2;

    MiD, 21 Мая 2015

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

    +143

    1. 1
    <?php if (wp_list_categories('title_li=&echo=0&child_of='.$cat) != '<li class="cat-item-none">Рубрик нет</li>') { ?>

    Стопудово надёжное условие!

    barinbritva, 21 Мая 2015

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

    +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
    // https://github.com/zendframework/zf1/blob/master/library/Zend/Form/Element.php#L1311
    
          /**
         * Remove a single validator by name
         *
         * @param  string $name
         * @return bool
         */
        public function removeValidator($name)
        {
            // code
            return $this;
        }

    hcy321, 21 Мая 2015

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