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

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // Real itemid is "contained" in public itemid in a bit tricky way. The formula is:
    
    public_itemid = itemid * 256 + anum
    
    // Quite easy, isn't it? Except where to get that anum. anum is some number assigned when you create a new post in LJ.
    
    // But in fact, you don't need it. Because it is always less than 256, we can avoid searching for it, and just use simple Math to find itemid.
    
    $anum = $public_itemid - floor($public_itemid / 256) * 256;
    $itemid = ($public_itemid - $anum) / 256;

    Прекрасный подход, то место, где вордпресс и ЖЖ сошлись воедино.

    http://drumrock.skipitnow.org/livejournal-tools/itemid/

    Fike, 10 Ноября 2014

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

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    qdev_id, iops = _update_device_iops(instance, device_for_change)
    try:
    	qemu.volumes.set_io_throttle(controller.qemu(), qdev_id, iops)
    except Exception as e:
    	# Check if we turn off this instance? just a moment ago.
    	if "'NoneType' object has no attribute 'connected'" in e:
    		LOG.warning("kemu process seems to be killed")
    	else:
    		raise

    Метод set_io_throttle не бросает exception.
    Мы так проверяем,есть ли connection к qemu или нет.

    gmmephisto, 30 Октября 2014

    Комментарии (1)
  4. Куча / Говнокод #16990

    +126

    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
    .cat_mid a{
    color: #ffa10e !important;
    }
    .cat_mid {
    padding: 0 10px;
    display: inline-block;
    font-family: georgia, "times new roman", times, serif;
    font-weight: normal;
    font-size: 14px;
    height: 64px !important;
    overflow: hidden;
    margin-bottom: -3px !important;
    padding: 10px 10px 0;
    }
    .cat_hid {
    color: #bc843f;
    padding: 0 10px;
    text-align: left; 
    z-index: 100;
    position: relative;
    display: none;
    }
    .cat_hid.not{
    display: block !important;
    padding: 8px 10px 19px;
    }
    .cat_hid.not.price{
    height: 25px;
    padding: 12px 10px 17px;
    }

    css

    UncaughtException, 30 Октября 2014

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

    +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
    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
    $(function() {
    			$('#diametr').on('change', function() {
    				window.location = '/catalog/<?=$arResult['SECTION']['CODE']?>/'+this.value+'/';
    			});
    			
    			$('#type_s').on('change', function() {
    				$('#size_s').find('option:enabled').prop("disabled", true);
    				$('#size_s').find('option[data-prop-material='+$(this).find('option:selected').data('propMaterial')+']').prop("disabled", false).first().prop("selected", true);
    				$('#size_s').trigger('change')
    			});
    			
    			$('#type_p').on('change', function() {
    				$('#size_p').find('option:enabled').prop("disabled", true);
    				$('#size_p').find('option[data-prop-type='+$(this).find('option:selected').data('propType')+']').prop("disabled", false).first().prop("selected", true);
    				$('#size_p').trigger('change')
    			});
    			
    			
    			$(document)
    				.on('change', '#size_s, #size_p', function() {
    					
    					$('#selected_prop').val('csone_19_'+$(this).find('option:selected').data('propId'));
    				})
    				.on('click', '.but_sita', function() {
    					console.log($(this).parent().find('select').first());
    					$(this).parent().find('select').first().trigger('change');
    				});
    			$('.but_sita').last().trigger('click');
    			
    			$('#additional_spoiler').on('click', function(e) {
    				e.preventDefault();
    				$('#additional').fadeIn();
    			});
    		});

    UncaughtException, 29 Октября 2014

    Комментарии (1)
  6. VisualBasic / Говнокод #16928

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Public m_Values As Hashtable    
    
    Public Function GetSensorType(p_SensorType As SensorType) As SensorValue
            For Each de As DictionaryEntry In m_Values
                If CType(de.Key, SensorType) = p_SensorType Then
                    Return de.Value
                End If
            Next
            Return Nothing
     End Function

    Отличный пример работы с Hashtable!

    IlyaS, 24 Октября 2014

    Комментарии (1)
  7. C# / Говнокод #16921

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    //#if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
    if (Selection.activeGameObject != null)
    control = (IControl)Selection.activeGameObject.GetComponent("IControl");
    //#endif

    принял код от юнити юниора

    sladkijBubaleh, 23 Октября 2014

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

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    bool result = false;
    if (xmlString != null)
    {
       result = reportService.SaveQ360Report(questionnaireId, xmlString, publishReport);
       UpdateCurrentReportModel(questionnaireId, reportService);
    }
    // string errorMessage;
    if (result == false)
       result = true; //because model is not changed
    return Json(new { Success = result, ErrorMessage = DisplayLabels.InvalidModelError });

    sharpman, 23 Октября 2014

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

    +159

    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
    <script>
    	$(function() {
    		$('#current').load('current.php');
    	}
    </script>
    
    // Тем временем в current.php :
    <?
    $result = ... ; // данные как-то вытаскиваются из базы
    ob_start();?>
    <table><?
    foreach($result as $res) {?>
    <tr><td><?=$res[0]?></td><td><?=$res[1]?></td><td><?=$res[2]?></td></tr>
    <?}?>
    </table>
    <?$table = ob_get_clean();?>
    <script>
              $('#current').empty();
              $('#current').append('<?=str_replace(array("\r","\n"),"",$table)?>'); 
    </script>

    Извиняюсь за возможные опечатки: сократил, чтобы оставить только самую мякотку.

    clauclauclau, 23 Октября 2014

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach (array(167, 163) as $low_rise_apartment_id)
    {
            $arParams["SEARCH_DATA"]["articletype"][] = $low_rise_apartment_id;
    }
                
    $arParams["SEARCH_DATA"]["articletype"] = array_unique($arParams["SEARCH_DATA"]["articletype"]);

    solnatus, 22 Октября 2014

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

    +154

    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
    <?php if( !empty($documents[4]) ):?>
                    <hr>
                    <h3>Выполняемые работы</h3>
                    <table class="b-transparent-table">
    
                        <?php foreach ($documents[4] as  $file_name => $text): ?>
    
                            <tr>
                                <td class ="td_big">
                                    <h6><?= $text;?></h6>
                                </td>
                                <td>
                                    <a href="<?= $dir.$passport['reforma_id'].DIRECTORY_SEPARATOR."4".DIRECTORY_SEPARATOR.$file_name;?>">скачать</a>
                                </td>
                            </tr>
    
                        <?php endforeach; ?>
                    </table>
                <?php endif;?>

    магический документ 4. В файле откуда взят код есть также документ 5.

    memclutter, 20 Октября 2014

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