1. Ruby / Говнокод #7104

    −104

    1. 1
    <%= !!@case[:img] ? image_tag(@case[:img]) : "" %>

    pavel_so, 29 Июня 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    //...
    	$fileinattachments = $root_directory.$filepath.$fileid.'_'.$filename;
    	if(!file($fileinattachments)) $fileinattachments = $root_directory.$filepath.$fileid."_".$filename
    //...
    ?>

    Много думал. Код из незабвенной vTiger CRM.

    mr.The, 29 Июня 2011

    Комментарии (4)
  3. bash / Говнокод #7102

    −130

    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
    Request() { 
     Info "Добро пожаловать в VKSearch $sys_version!"
     Info "Загрузка списка треков..."
     vkapi_signature=$(echo -n "${vkapi_id}api_id=1696393count=${cfg_search_count}method=audio.searchq=${query}test_mode=1v=2.0${vkapi_secret}"|md5sum|awk '{print $1}')
     wget "http://api.vkontakte.ru/api.php?api_id=1696393&count=${cfg_search_count}&v=2.0&method=audio.search&sig=${vkapi_signature}&test_mode=1&q=$query" -qO "${sys_temp}/vksearch.out"
     found=$(cat ${sys_temp}/vksearch.out | sed -ne 's,<count>\([^<]*\)</count>,\1,p'|sed 's/^[ \t]*//')
    
     error_msg="$(cat ${sys_temp}/vksearch.out | sed -n 's|<error_msg>\(.*\)</error_msg>|\1|p'|sed 's/^[ \t]*//'|head -n1 )"
     error_code="$(cat ${sys_temp}/vksearch.out | sed -n 's|<error_code>\(.*\)</error_code>|\1|p'|sed 's/^[ \t]*//'|head -n1)"
     [ -n "$error_msg" ] && Info "Ошибка: $error_msg (Код $error_code)" die
     
     song_count=$(cat ${sys_temp}/vksearch.out | grep '<url>'|wc -l )
     [ $song_count -eq 0 ] && Info "По запросу ${query} не найдено ни одного трека..." die || Info "По запросу ${query} найдено ${found} композиций. Обработка первых ${song_count}."
    }
    
    Parse() { 
     OLD_IFS=$IFS
     IFS=$'\n'
     song_urls=( `cat ${sys_temp}/vksearch.out | sed -n 's|<url>\(.*\)</url>|\1|p'|sed 's/^[ \t]*//' ` )
     song_artists=( `cat ${sys_temp}/vksearch.out | sed -n 's|<artist>\(.*\)</artist>|\1|p'|sed 's/^[ \t]*//' ` )
     song_titles=( `cat ${sys_temp}/vksearch.out | sed -n 's|<title>\(.*\)</title>|\1|p'|sed 's/^  //' ` )
     song_durations=( `cat ${sys_temp}/vksearch.out |sed -n 's|<duration>\(.*\)</duration>|\1|p'|sed 's/^[ \t]*//' ` )
     song_counts=$(( ${#song_urls[@]} - 1 ))
     IFS=$OLD_IFS
    }
    
    RemoveDoubles() {
     rm ${sys_temp}/vksearch.pars* 2>&-
     Info "Начинаю удаление треков с одинаковой длительностью..."
     for i in `seq 0 $song_counts`
     do
      echo "<1>${song_durations[$i]}<2>${song_artists[$i]}<3>${song_titles[$i]}<4>${song_urls[$i]}<5>" >> ${sys_temp}/vksearch.parsing 
     done
     cat ${sys_temp}/vksearch.parsing | sort -n | uniq -w 6 > ${sys_temp}/vksearch.parsed
     cat ${sys_temp}/vksearch.parsing | sort -n | uniq -w 6 -d > ${sys_temp}/vksearch.doubles
     OLD_IFS=$IFS
     IFS=$'\n'
     song_urls=( `cat ${sys_temp}/vksearch.parsed |sed -ne 's,.*<4>\([^<]*\)<5>.*,\1,p' ` )
     song_artists=( `cat ${sys_temp}/vksearch.parsed |sed -ne 's,.*<2>\([^<]*\)<3>.*,\1,p' ` )
     song_titles=( `cat ${sys_temp}/vksearch.parsed | sed -ne 's,.*<3>\([^<]*\)<4>.*,\1,p' ` )
     song_durations=( `cat ${sys_temp}/vksearch.parsed |sed -ne 's,.*<1>\([^<]*\)<2>.*,\1,p' ` )
     song_counts=$(( ${#song_urls[@]} - 1 ))
     IFS=$OLD_IFS
     Info "В плейлисте осталось ${#song_urls[@]} треков." 
    }

    парочка функций из моего проекта VKSearch - поиск и сохранение музыки ВКонтакте на shell... -_-

    snoopcatt, 29 Июня 2011

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

    +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
    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
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    unit HRTimer;
     
    interface
     
    uses Windows;
     
    type
      // --------------------- Класс - высокоточный таймер -------------------------
      THRTimer = class(TObject)
        constructor Create;
        function StartTimer: Boolean; // Обнуление таймера
        function ReadTimer: Double;   // Чтение значения таймера в миллисекундах
      private
        StartTime: Double;
        ClockRate: Double;
      public
        Exists: Boolean;    // Флаг успешного создания таймера
      end;
     
    var
      Timer: THRTimer; // Глобальая переменная. Создаётся при запуске программы
     
    { Фукнция высокоточной задержки.
     Delphi:
       Синтаксис: function HRDelay(const Milliseconds: Double): Double;
       Milliseconds: Double - задержка в миллисекундах (может быть дробной)
       Результат функции - фактически произошедшая задержка с погрешностью.
       Пример вызова функции: X:= HRDelay(100.0); или HRDelay(100.0);
     
     C++Builder:
       Синтаксис: double HRDelay(const double Milliseconds);
       Double Milliseconds - задержка в миллисекундах (может быть дробной)
       Результат функции - фактически произошедшая задержка с погрешностью.
       Пример вызова функции: double X = HRDelay(100.0); или HRDelay(100.0);}
    function HRDelay(const Milliseconds: Double): Double;
     
    implementation
     
    function HRDelay(const Milliseconds: Double): Double;
    begin
      Timer.StartTimer();
      repeat
        Result:= Timer.ReadTimer();
      until Result >= Milliseconds;
    end;
     
    { THRTimer }
     
    constructor THRTimer.Create;
    var
      QW: LARGE_INTEGER;
    begin
      inherited Create;
      Exists := QueryPerformanceFrequency(Int64(QW));
      ClockRate := QW.QuadPart;
    end;
     
    function THRTimer.StartTimer: Boolean;
    var
      QW: LARGE_INTEGER;
    begin
      Result := QueryPerformanceCounter(Int64(QW));
      StartTime := QW.QuadPart;
    end;
     
    function THRTimer.ReadTimer: Double;
    var
      ET: LARGE_INTEGER;
    begin
      QueryPerformanceCounter(Int64(ET));
      Result := 1000.0 * (ET.QuadPart - StartTime) / ClockRate;
    end;
     
    initialization
      Timer:= THRTimer.Create();
     
    finalization
      Timer.Free();
     
    end.

    классический шайзберг посреди майских роз (ну почти розы)

    bugmenot, 29 Июня 2011

    Комментарии (91)
  5. bash / Говнокод #7100

    −144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #! /bin/sh
    
    # some code
    
    daemon1="/usr/home/daemon1.sh"
    daemon2="/home/daemon2.sh"
    
    # some code with variables

    Скрипт на BSD. Хомяк находится в /usr/home, а /home симлинк на него

    Elvenfighter, 29 Июня 2011

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

    +147

    1. 1
    date('d ', time()+3600*4);

    vdmodule, 28 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private function _fileExists($file)
    {
        if(file_exists(self::FILE_PATH . $file)) {
            return true;
        }
        return false;
    }

    Нашел в одном из проектов.

    cartman, 28 Июня 2011

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

    +181

    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
    #include "iostream"
    using namespace std;
    
    enum {MaxFucktorial=13};
    static int fucks[MaxFucktorial+1];
    
    template<const int ValuePosition, const int Value>
    struct initFuckedValue
    {
    	enum {CurrentValue=Value*ValuePosition};
    	static void fuckUp(void)
    	{
    		fucks[ValuePosition]=CurrentValue;
    		initFuckedValue<ValuePosition+1, CurrentValue>::fuckUp();
    	};
    };
    template<const int Value>
    struct initFuckedValue<MaxFucktorial, Value>
    {
    	static void fuckUp(void){};
    };
    void InitFucks(void)
    {
    	fucks[0]=1;
    	initFuckedValue<1,1>::fuckUp();
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	cout<<"Введите аргумент факториала: "<<endl;
    	InitFucks();
    	int fuckArg=0;
    	cin>>fuckArg;
    	cout<<"Начинаем считать факториал..."<<endl
    	<<"Подсчёт факториала успешно завершён. ОК."<<endl
    	<<"Результат: "<<fucks[fuckArg]<<endl;
    	cin>>fuckArg;
    	return 0;
    }

    Решил запостить всё. Жемчужена.

    Мой знакомый, молодой преподаватель-аспирант из института пришёл однажды расстроенный. Спрашиваю у него: "Что случилось?"
    -- "Один мой первокурсник, когда я дал ему задание посчитать факториал через рекурсию принёс мне какую-то непонятную компилирующуюся галиматью. И считает она уж слишком быстро... Это какая-то программа обманка. Вообщем я ему поставил 2."

    Да, это лаба. ^_^

    Говногость, 28 Июня 2011

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

    +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
    $get = dbcom('SELECT * FROM downloads ORDER BY views DESC;');
    			$i = 1;
    			while($row = mysql_fetch_array($get))
    			{
    				if($i == 1)
    				{
    					$p['v'] = $row['views'];
    				}
    				if($row['reports'] != 0)
    				{
    					$t['rep']++;
    				}
    				$t['dl'] += $row['views'];
    				$i = 0;
    			}

    DDLCMS is a COMMERCIAL grade content management system for DDL site owners.
    при 400к записях в downloads немножно все в ОЗУ не помещалось.

    peinguin, 28 Июня 2011

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

    +89

    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
    // qsort.inc:
    procedure SortRow(var A: array of T);
    
      procedure sort(l,r: integer);
      var
        i,j: integer;
        x,y: T;
      begin
        i := l;
        j := r;
        x := a[random(r-l+1)+l];
        repeat
          while LESS(a[i],x) do inc(i);
          while LESS(x,a[j]) do dec(j);
          if i<=j then begin
            y    := a[i];
            a[i] := a[j];
            a[j] := y;
            inc(i);
            dec(j);
          end;
        until i>=j;
        if l<j then sort(l,j);
        if i<r then sort(i,r);
      end;
    
    begin
      Sort(Low(A), High(A));
    end;
    
    // unit1.pas
      T = TPoint;
      function LESS(const a,b: T): boolean;
      begin
        result := a.x<b.x;
      end;
      {$I qsort.inc}
    
    var 
      a: array of TPoint;
    begin  
      ...
      SortRow(a);
      ...
    end;

    Я использую шаблоны в Дельфи-7 ололо.

    TarasB, 28 Июня 2011

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