1. JavaScript / Говнокод #16310

    +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
    jQuery(document).ready(function(){
        jQuery('#administratifs .accessElement').each(function(){
            #foreach($user in $users)
                #set($function = $user.getProperty('fonction').getValue())
                if(jQuery(this).attr('id')== "accessElement_$user.getNumber()"){
                    jQuery(this).find('.selectFunction option').filter(function() {
                    return jQuery(this).text() == "$function";
                    }).prop('selected', true);
                }
            #end
        })
    
        jQuery('#administratifs .disableClass').attr('disabled', 'disabled');
    
    })

    тут еще velocity

    iofjuupasli, 11 Июля 2014

    Комментарии (0)
  2. bash / Говнокод #16308

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    exit_status=0
    
    # blah-blah
    
    for process in "service1 service2 service3"; do
        # blah-blah
    
        $process || \
            exit_status=`expr "${exit_status}" \| 1` 
    done
    
    exit $exit_status

    В раздел "джависты пишут шелл-скрипты"

    Elvenfighter, 11 Июля 2014

    Комментарии (0)
  3. JavaScript / Говнокод #16307

    +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
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    /*.slimNotificationBar {
     left : 60px;
     right: 100px;
    }*/
    var sText = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.";
    
    function displayListener(oEvent) {
        var bShow = oEvent.getParameter("show");
    
        if (bShow) {
            /*
             * Now the application can decide how to display the bar. It can be maximized, default, minimized (please see NotificationBarStatus) 
             */
            var sStatus = sap.ui.ux3.NotificationBarStatus.Default;
            oNotiBar1.setVisibleStatus(sStatus);
        } else {
            var sStatus = sap.ui.ux3.NotificationBarStatus.None;
            oNotiBar1.setVisibleStatus(sStatus);
        }
    };
    
    var now = (new Date()).toUTCString();
    var oMessage = new sap.ui.core.Message({
        text : sText,
        timestamp : now
    });
    
    var oNotifier = new sap.ui.ux3.Notifier({
        title : "The first Notifier"
    });
    oNotifier.addMessage(oMessage);
    
    var oNotiBar1 = new sap.ui.ux3.NotificationBar({
        display : displayListener,
        visibleStatus : "None",
        resizeEnabled : false
    });
    oNotiBar1.addStyleClass("sapUiNotificationBarDemokit");
    oNotiBar1.addStyleClass("slimNotificationBar");
    oNotiBar1.addNotifier(oNotifier);
    oNotiBar1.placeAt("sample1");

    Решил для нужд одного проекта ознакомиться с официальной документацией к OpenUI5 от весьма известной фирмы SAP. Полдня моей жизни убиты без всякой пользы. Больше примеров того, как НЕ надо писать код на JS, здесь: https://openui5.hana.ondemand.com/#content/Controls/index.html
    ExtJS использовать не могу по лицензионным соображениям, остаётся смотреть в сторону qooxdoo и YUI...

    dunmaksim, 11 Июля 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    string Item = dtTemp.Rows[a].ItemArray[0] != null
                                        ? !String.IsNullOrEmpty(dtTemp.Rows[a].ItemArray[0].ToString())
                                            ? dtTemp.Rows[a].ItemArray[0].ToString().Trim()
                                            : ""
                                         : "";

    ну а как иначе?

    gudus, 11 Июля 2014

    Комментарии (3)
  5. Куча / Говнокод #16305

    +138

    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
    Викиучебник по хаскелю такой викиучебник
    
    Задание - написать frequency — функция, возвращающая список пар (символ, частота). Каждая пара определяет атом из заданного списка и частоту его вхождения в этот список.
    
    Решение 
    
    frequency :: [a] -> [(a : Integer)]
    frequency l = f [] l
    
    f :: [a] -> [a] -> [(a : Integer)]
    f l []    = l
    f l (h:t) = f (corrector h l) t
    
    corrector :: a -> [a] -> [(a : Integer)]
    corrector a []      = [(a : 1)]
    corrector a (a:n):t = (a : (n + 1)) : t
    corrector a h:t     = h : (corrector a t)
    
    Логика-то верна, но код тупо не скомпилится. И как тут быть нубцу? 
    
    
    
    Задание - Описать следующие классы типов. При необходимости воспользоваться механизмом наследования классов.
    Show — класс, объекты экземпляров которого могут быть выведены на экран.
    
    Думаю что-то мегасложное, сделать самому руками show
    
    Решение 
     
    class Show a where
      show :: a -> String
    
    /-*)

    Викиучебник по хаскелю такой викиучебник

    kegdan, 11 Июля 2014

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

    +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
    21. 21
    22. 22
    <?endif?></ul><?endif;?><?endif;?><ul id="gnb-section-help" class="gnb-menu"><?if(isset($group['HelpGroup'])):?>
            <?for($i=0;$i<count($group['HelpGroup']);$i++):?>
            <?$groupItem = $group['HelpGroup'][$i]?>
            <?if(!$groupItem->IsItemList):?>
            <li><a target="_blank" href="<?=$groupItem->Href?>"><?=$groupItem->Content?></a></li>
            <?else:?>
            <li class="gnb-dropdown">
              <a href="#" class="btn gnb-dropdown-toggle-link">
                <?if(isset($groupItem->Content) && $groupItem->Content != ""):?><span class="gnb-dropdown-toggle-text"><?=$groupItem->Content?></span><?endif?></a><a href="#" class="btn gnb-dropdown-toggle"><i>▾</i></a>
              <ul class="gnb-dropdown-menu">
                <?if(isset($groupItem->ItemList)):?>
                <?for($i=0;$i<count($groupItem->ItemList->Item);$i++):?>
                <?$subItem = $groupItem->ItemList->Item[$i]?>
                <li><a target="_blank" href="<?=$subItem->Href?>"><?=$subItem->Content?></a></li>
                <?endfor?>
                <?endif?>
              </ul>
            </li>
            <?endif?>
            <?endfor?>
            <?endif?>
          </ul>

    Встретил в одном из проектов.
    Долго думал к какому языку отнести это дело, решил, что всё же PHP.

    Не пишите так никогда, это как минимум, нечитаемо.

    johny, 11 Июля 2014

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

    +157

    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
    $pogoda = file_get_contents('http://export.yandex.ru/weather/');
        preg_match('/<weather_type>(.*?)<\/weather_type>/i',$pogoda,$type);
        preg_match('/<dampness>(.*?)<\/dampness>/i',$pogoda,$vlaga);
        preg_match('/<temperature>(.*?)<\/temperature>/i',$pogoda,$temp);
        preg_match('/<image2>(.*?)<\/image2>/i',$pogoda,$img2);
        preg_match('/<pressure>(.*?)<\/pressure>/i',$pogoda,$press);
        $imgp = substr($img2[1], 24);
    
    $vivod = "<img align=\"top\" src=\"//img.yandex.net$imgp\" alt=\"$type[1]\" />$temp[1] °C
        $type[1]<br />
        Влажность: $vlaga[1] %<br />
        Давление: $press[1] мм рт.ст.";
        echo $vivod;

    Парсинг XML от Яндекс-погоды. Только хардкор!

    huitator, 10 Июля 2014

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

    +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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    for ( var i in data){
                data[i].id = data[i].id.toString();
                if (tree.l0[data[i].id] == undefined){
                    tree.l0[data[i].id] = data[i];           
                }            
                if (data[i].children){
                    for (var j in data[i].children){
                        data[i].children[j].id = data[i].children[j].id.toString();
                        if ( tree.l1[data[i].children[j].id] == undefined && tree.l2[data[i].children[j].id] == undefined){
                            tree.l1[data[i].children[j].id] = data[i].children[j];    
                        }
                        if (data[i].children[j].children){
                            for (var z in data[i].children[j].children){
                                data[i].children[j].children[z].id = data[i].children[j].children[z].id.toString();
                                if (tree.l2[data[i].children[j].children[z].id] == undefined){
                                    tree.l2[data[i].children[j].children[z].id] = data[i].children[j].children[z];
                                }
                            }
                        }
                    }
                }
            }

    Вот с таким кодом приходится работать... [продолжение]

    monstrodev, 10 Июля 2014

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

    +158

    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
    for ( var i in data){
                flat_data.push(data[i]);       
                if (data[i].children){
                    for (var j in data[i].children){
                        flat_data.push(data[i].children[j]);
                        if (data[i].children[j].children){
                            for (var z in data[i].children[j].children){
                                flat_data.push(data[i].children[j].children[z]);
                            }
                        }
                    }
                }
            }

    Вот с таким кодом приходится работать...

    monstrodev, 10 Июля 2014

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

    +156

    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
    while ($this->tariffs_model->getCarsCheckedByTariff($user_id, $tariff_info[0]['id']) > $tariff_info[0]['cars_count'])
    {
    	$cars = $this->tariffs_model->getCarsChecked($tariff_info[0]['id'], $user_id);
    	if ($cars)
    	{
    		//удаляем одну объяву
    		$this->tariffs_model->delCarChecked($cars[0]);
    		$this->sms_model->removeSmsByCarId($cars[0]);
    	}
    }
    
    /*-=-=-=-=-=-=-=-=-=-=-=-=- реализация ф-ций -=-=-=-=-=-=-=-=-=-=-=-=-*/
    
    /**
     * Получаем кол-во реально отмеченых объявлений
     * @param int $user_id
     * @param int $tariff_id
     */
    function getCarsCheckedByTariff($user_id, $tariff_id)
    {
    	$query = "SELECT COUNT(*) as count FROM tariffs_cars_checked WHERE car_id IN
    		(SELECT id FROM a2_cars WHERE user = ? AND expire_date >= ?) AND tariff_id = ?";
    	$result = $this->db->query($query, array($user_id, MYSQL_CURDATE, $tariff_id));
    
    	//echo $this->db->last_query();
    
    	if ($result && $result->num_rows() == 1)
    	{
    		return $result->row()->count;
    	}
    	else
    	{
    		return null;
    	}
    }
    
    /**
     * Список ID отмеченных объявлений по тарифу пользователя
     *
     * @param Int $tariff_id
     * @return Array[]
     * @author КОЕ-КТО 21.12.2009 12:35
     * @uses Controller::Profile
     */
    function getCarsChecked($tariff_id, $user_id)
    {
    	$this->db->select('tariffs_cars_checked.car_id')->from('tariffs_cars_checked')
    	->join('a2_cars', 'a2_cars.id = tariffs_cars_checked.car_id', 'inner')
    	->where(array('tariffs_cars_checked.tariff_id' => intval($tariff_id), 'a2_cars.user' => intval($user_id)));
    
    	$result = $this->db->get();
    	if ($result && $result->num_rows() > 0)
    	{
    		$cars = array();
    		foreach ($result->result_array() as $row)
    		{
    			$cars[] = $row['car_id'];
    		}
    		return $cars;
    	}
    	else
    	{
    		return null;
    	}
    }

    Удаляем объявления скопом!

    smail01, 10 Июля 2014

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