1. bash / Говнокод #6222

    −131

    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
    #!/bin/bash
    
    ######################################################################################
    #
    #	Write a bash script that obtains active processes for the current user, 
    #	breaks them into chains and prints all unique chains containing 3 or more 
    #	PIDs in the following format:
    #		PID1:PID2:PID3:…:PIDn
    #		PID:PID:PID:…:PID
    #		…
    #	So that each next PID is a parent of the previous PID, the first PID in 
    #	each chain does not have children and the last PID in each chain 
    #	does not have parent.
    #
    ######################################################################################
    
    TEMPFILE="/tmp/$0$$"				# file needs to save the process list
    						# it's really needed to divide columns
    						# generated 'ps'
    						
    # parameters:
    # 	-H 	- sorts the list as process forest (it lets to find connection between child and parent faster)
    #	-o	- sets the output format
    #	"%p %P" - thow columns in output: PID and PPID
    #	-u	- sets username
    #	`whoami` - get the current user name
    ps -H -o "%p %P" -u `whoami` > $TEMPFILE
    PIDLIST=(`awk '/[0-9]/ {print $1}' $TEMPFILE`)	# make an array using the first column
    PPIDLIST=(`awk '/[0-9]/ {print $2}' $TEMPFILE`)	# 	and the second
    
    SIZE=${#PIDLIST[*]}
    K=0
    # bypassing the forest using stack which emulates LINKS array. K is the pointer to stack's top
    for (( i=0; i<$SIZE; i++ ))
    do
        if [[ $K = 0 || ${PPIDLIST[$i]} = ${LINKS[$K-1]} ]]	# new tree or new edge in the tree.
        then
            LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
            K=`expr $K + 1`
        else 					# the chain is complete.
    	if [[ $K > 2 ]]				# enough size to print the chain
    	then				# reversed formatted output the chain
    	    echo ${LINKS[*]} | awk '{ printf $NF; for (i = NF-1; i > 0; --i) printf ":"$i}'
    	    echo
    	fi
            until [[ $K == 0 || ${PPIDLIST[$i]} == ${LINKS[$K-1]} ]]
            do 					# deleting elements from stack until find a
        						#	parent or tree is end
        	    unset LINKS[$K-1]
        	    K=`expr $K - 1`
            done
    	LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
    	K=`expr $K + 1`
        fi
    done
    
    rm -rf $TEMPFILE				# removing temp file

    cahekm, 05 Апреля 2011

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

    −116

    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
    -(BOOL) checkIsDeleted:(Transactions*)target
    {
        if (target.transactionType == TransactionTypeTransfer)
        {
            if (target.cashFlow && target.cashFlow.isDeleted && target.secondCashFlow && target.secondCashFlow.isDeleted)
                return YES;
            return NO;
        }
        else
            if (target.cashFlow && target.cashFlow.isDeleted)
                return YES;
        return NO;
    }

    Классика )))

    Tika-Z, 05 Апреля 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $query = 'SELECT `views` FROM `'.PREFIX.'_newsi` WHERE `id` = '.$item["id"];			
    $result = $kernel->runSQL($query);
    $count;
    if (mysql_num_rows($result)) {
        $count = mysql_result($result,"views");				
        $query = 'UPDATE `'.PREFIX.'_newsi` SET `views` = "'.++$count.'" WHERE `id` ='.$item["id"];
        $kernel->runSQL($query);
    }

    Увеличиваем счетчик количества просмотров новости

    gorky, 05 Апреля 2011

    Комментарии (12)
  4. PHP / Говнокод #6219

    +165

    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
    $month[1] = “Январ”;
    $month[2] = “Феврал”;
    $month[3] = “Март”;
    $month[4] = “Апрел”;
    $month[5] = “Ма”;
    $month[6] = “Июн”;
    $month[7] = “Июл”;
    $month[8] = “Август”;
    $month[9] = “Сентябр”;
    $month[10] = “Октябр”;
    $month[11] = “Декабр”;
    $month[12] = “Январ”;
    
    $day[0] = “Воскресенье”;
    $day[1] = “Понедельник”;
    $day[2] = “Вторник”;
    $day[3] = “Среда”;
    $day[4] = “Четверг”;
    $day[5] = “Пятница”;
    $day[6] = “Суббота”;
    
    $dnum = date(”w”);
    $mnum = date(”n”);
    $daym = date(”d”);
    $year = date(”Y”);
    
    $textday = $day[$dnum];
    $monthm = $month[$mnum];
    
    if ($mnum==3||$mnum==8) {
        $k=”а”;
    }
    else {
        $k=”я”;
    }
    
    echo “Сегодня: $textday, $daym $monthm$k $year г.”;

    Отсюда: http://flashripper.net/2007/10/24/delaem-vyvod-daty-na-php.html

    Anonym, 05 Апреля 2011

    Комментарии (15)
  5. SQL / Говнокод #6218

    −858

    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
    create or replace function t8() returns integer as $$
    declare
        rec record;
    begin
        for rec in select * from purchase loop
          update purchase set amount=(
                  select book.cost*purchase.quantity*(1-customer.discount/100.0)
                  from purchase, book, customer
                  where purchase.id=rec.id and
                      book.id=purchase.book and
                      customer.id=purchase.customer
          )
          where purchase.id=rec.id;
        end loop;
    
        return 1;
    end;
    $$ language plpgsql;
    
    select t8();

    прочно засевшие в голове алгоритмические языки

    ilardm, 04 Апреля 2011

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

    −110

    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
    Public Class Decoder
        Dim arr_en() As String = {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "?", "@"}
        Dim arr_ua() As String = {"й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "ъ", "ф", "ы", "в", "а", "п", "р", "о", "л", "д", "ж", "є", "я", "ч", "с", "м", "и", "т", "ь", "б", "ю", ".", ",", "'"}
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox2.Clear()
    
            Dim t As Char
            Dim ch As Char
            Dim vv As String
    
            For Each vv In TextBox1.Lines
                For Each t In vv
                    For i As Integer = 0 To arr_en.Count - 1
                        ch = arr_en.GetValue(i)
                        If t = ch Then
                            t = arr_ua.GetValue(i)
                            Exit For
                        End If
                    Next
                    TextBox2.Text = TextBox2.Text & t
                Next
                TextBox2.Text = TextBox2.Text & vbCrLf
            Next
        End Sub
    End Class

    Декодер с английской раскладки за 5 минут.

    undiscovered, 04 Апреля 2011

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

    +146

    1. 1
    background-repeat: no-repeat no-repeat;

    css css

    happy_me, 04 Апреля 2011

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

    +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
    if(($n=func_num_args())>1)
    		{
    			$args=func_get_args();
    			if($n===2)
    				$object=new $type($args[1]);
    			else if($n===3)
    				$object=new $type($args[1],$args[2]);
    			else if($n===4)
    				$object=new $type($args[1],$args[2],$args[3]);
    			else
    			{
    				unset($args[0]);
    				$class=new ReflectionClass($type);
    				// Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
    				// $object=$class->newInstanceArgs($args);
    				$object=call_user_func_array(array($class,'newInstance'),$args);
    			}
    		}

    yii :)

    manyrus, 04 Апреля 2011

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

    +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
    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
    function addRowToTable(){
     
     var tBody = document.getElementById("table_"+currentLocator).getElementsByTagName("TBODY")[0];
     var row = document.createElement("TR");
     tBody.appendChild(row);
     for (i=1;i<=6;i++){
      var td = document.createElement("TD"); 
      if (i==1){
       td.className="locatorTxt";
      } else {
       td.className="locatorDtlTxt";
      }
      td.innerHTML=" ";
      if ( i==2 ){
       td.innerHTML=CollectionsUtils.getSelectedItem(selectCollectorId);
       td.name = prefNameAsg+currentLocator;
      } else if (i==3) {
       td.innerHTML=ControlUtils.getValueById(percentId)+"%";
       td.name=prefPercentAsg+currentLocator;
      } else if ( i== 4) {
       td.name=prefJobAsg+currentLocator;
      } else if ( i==5 ) {
       td.name=prefPercentChg+currentLocator;
       td.innerHTML=ControlUtils.getValueById(percentId)+"%";
      } else if ( i==6 ) {
       td.name=prefJobChg+currentLocator;
      }
      row.appendChild(td);
     }
     recalulateTable( prefPercentAsg, prefJobAsg, "");
     recalulateTable( prefPercentChg, prefJobChg, "");
    }

    tr00_gr1m_doomster, 04 Апреля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $is_active = true;
           try
            {
                $is_active = $this->getIsActive($this->pk_id, true);
            }
            catch (DBModelException $e)
            {
                $is_active = false;
            }

    Довольно хитрый способ проверить является ли объект новым или уже присутствует в базе (название переменной, кстати, тоже крутое).
    Если объект новый, то при обращении к this->pk_id будет брошен DbModelException, который бросается при доступе к несуществующим свойствам объекта. Подразумевается, что несохранённый в базе объект не имеет первичного ключа.

    ilovephp, 04 Апреля 2011

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