1. Pascal / Говнокод #4776

    +94

    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
    function WindowProc(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM ): LRESULT; stdcall;
    type
      Item = record
        szItemNr: array[0..8] of char;
        szItem: array[0..32] of char;
        szItemDescription: array[0..32] of char;
      end;
    var
      ListColumn: LV_COLUMN;
      ListItem: LV_ITEM;
    begin
      // In case of Msg ...
      case Msg of
        WM_CREATE: // Create?
        begin
          // Create list
          ListView := CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, '', WS_VISIBLE Or WS_CHILD Or LVS_REPORT Or LVS_SHOWSELALWAYS,
                                     10, 10, 524, 300, Wnd, 0, hInstance, nil);
          ListView_SetExtendedListViewStyle(ListView, LVS_EX_FULLROWSELECT Or LVS_EX_GRIDLINES);
          // Filling list columns
          with ListColumn do begin
            mask := LVCF_FMT Or LVCF_WIDTH Or LVCF_TEXT Or LVCF_SUBITEM;
            fmt := LVCFMT_LEFT;
    
            iSubItem := 0;
            cx := 200;
            pszText := 'File name';
            ListView_InsertColumn(ListView, 0, ListColumn);
    
            iSubItem := 1;
            cx := 250;
            pszText := 'Folder path';
            ListView_InsertColumn(ListView, 1, ListColumn);
    
            iSubItem := 2;
            cx := 70;
            pszText := 'File size';
            ListView_InsertColumn(ListView, 2, ListColumn);
          end;
    
          with ListItem do begin
            mask := LVIF_TEXT;
            iItem := 1;
            iSubItem := 1;
            pszText := PChar('test');
            cchTextMax := SizeOf(PChar('test')) + 1;
          end;
          ListView_InsertItem(ListView, ListItem);
          ListView_SetItemText(ListView, 1, 1, PChar('Hello world!'));
    
          // Create static text, progress bar and buttons
          StaticText := CreateWindowEx(0, 'Static', '', WS_CHILD Or WS_VISIBLE Or SS_CENTER,
                                       10, 310, 524, 16, Wnd, ID_StaticText, hInstance, 0);
          ProgressBar := CreateWindowEx(0, PROGRESS_CLASS, nil, WS_CHILD Or WS_VISIBLE Or PBS_SMOOTH,
                                        9, 326, 525, 17, Wnd, ID_ProgressBar, hInstance, nil);
          Button_Start := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Start', BS_DEFPUSHBUTTON Or WS_VISIBLE Or WS_CHILD,
                                   150, 350, 70, 25, Wnd, ID_Button_Start, hInstance, nil );
          Button_Pause := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Pause', WS_VISIBLE Or WS_CHILD Or WS_DISABLED,
                                   230, 350, 70, 25, Wnd, ID_Button_Pause, hInstance, nil );
          Button_Stop := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Stop', WS_VISIBLE Or WS_CHILD Or WS_DISABLED,
                                   310, 350, 70, 25, Wnd, ID_Button_Stop, hInstance, nil );
        end;
    
        WM_DESTROY: // Closing?
        begin
          PostQuitMessage(0);
          Result := 0;
          Exit;  // Bye.
        end;
    
        WM_COMMAND: // Any command?
        case LoWord(wParam) of
            // ....................................
        end;
    end;

    Пристрелите меня кто-нибудь. Или объясните, как работает этот волшебный listview %)

    iloveYou, 28 Ноября 2010

    Комментарии (30)
  2. Java / Говнокод #4775

    +67

    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
    package bytestring;
    
    public class Main {
    
        public static void main(String[] args) {
            String source = new String("A ya sdelal etu hren s perevorotom stroki s ispolzovaniem bayta");
            byte bytes[] = source.getBytes();
    
            bytes = reverse(bytes);
    
            String destination = new String(bytes);
            System.out.println(destination);
        }
    
        private static void switchBytes(byte[] array, int a, int b) {
            byte t = array[a];
            array[a] = array[b];
            array[b] = t;
        }
    
        public static byte[] reverse(byte[] bytes) {
            int i, j;
            int first, last;
            int length = bytes.length;
    
            //Переворачиваем всю строку
            for(i = 0; i < length / 2; i++)
                switchBytes(bytes, i, length - i - 1);
    
            //Переворачиваем каждое слово строки
            first = 0;
            for(i = 1; i <= length; i++)
                if(i == length || bytes[i] == ' ') {
                    last = i - 1;
                    for(j = first; j <= first + (last - first) / 2; j++)
                        switchBytes(bytes, j, first + last - j);
                    first = i + 1;
                }
            
            return bytes;
        }
    }

    hedgecrab, 28 Ноября 2010

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int count(int a)
    {
        int cnt=0;
        while(a)
        {
             ++cnt;
        }
        return cnt;
    }

    Ф-ция для подсчета количества знаков числа. Взято с www.cyberforum.ru

    psina-from-ua, 28 Ноября 2010

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

    +68

    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
    package bytestring;
    
    public class Main {
    
        public static void main(String[] args) {
            String source = new String("A ya sdelal etu hren s perevorotom stroki s ispolzovaniem bayta");
    
            byte bytes[] = source.getBytes();
    
            ////////////////////////////////////////////////////////////////////////
    
            int i, j;
            int length, first, last;
            byte a;
    
            length = bytes.length;
    
            //Переворачиваем всю строку
            for(i = 0; i < length / 2; i++) {
                a = bytes[i];
                bytes[i] = bytes[length - i - 1];
                bytes[length - i - 1] = a;
            }
    
            //Переворачиваем каждое слово строки
            first = 0;
            for(i = 1; i <= length; i++)
                if(i == length || bytes[i] == ' ') {
                    last = i - 1;
                    for(j = first; j <= first + (last - first) / 2; j++) {
                        a = bytes[j];
                        bytes[j] = bytes[first + last - j];
                        bytes[first + last - j] = a;
                    }
                    first = i + 1;
                }
    
            ////////////////////////////////////////////////////////////////////////
    
            char destination[] = new char[bytes.length];
            for(i = 0; i < bytes.length; i++)
                destination[i] = (char) bytes[i];
    
            System.out.println(String.copyValueOf(destination));
        }
    }

    hedgecrab, 28 Ноября 2010

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

    +147

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <algorithm>
    #include <vector>
    #include <string>
    
    #define N 5
    #define TSK "durak"
    
    using namespace std;
    
    int m[N];
    
    int main(void){
      freopen(TSK".in",  "rt", stdin);
      freopen(TSK".out", "wt", stdout);
    
      scanf("%d%d%d%d", &m[0], &m[1], &m[2], &m[3]);
    
      sort(m, m + 4);
    
      int ans(0);
    
      for(int i = 1; i < 4; i++){
        if(m[i] == m[i-1] && m[i] != 0)
          ans++;
      }
    
      printf("%d\n", ans);
    
      return 0;
    }

    MadMag, 27 Ноября 2010

    Комментарии (3)
  6. Java / Говнокод #4771

    +78

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static String toWritten(int i) {
            return Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) > 4 ?
                "объектов" :
                Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) > 1 ?
                    "объекта" :
                    Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) == 1 ?
                        "объект":
                        "объектов";
        }

    функция для вывода подобного:
    1 объект
    156 оъектов
    итд.

    danilissimus, 27 Ноября 2010

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

    +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
    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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    // TODO: use Virtual memory instead of heap!
    #ifndef __CHUNK_H__
    #define __CHUNK_H__
    #include <windows.h>
    #include "../JuceLibraryCode/JuceHeader.h"
    
    class Chunk {
    
    public:
    	enum CHUNK_DIRECTION {CHUNK_UNKNOWN = 0, CHUNK_IN, CHUNK_OUT};
    	Chunk (DWORD ChunkSize, WORD id, CHUNK_DIRECTION chunkDirection);
    	~Chunk ();
    	// override
    	virtual void eventChunkIsEmpty () { 
    		Logger::outputDebugString(T("empty")); 
    	}
    	virtual void eventChunkIsFull () {
    		Logger::outputDebugString(T("full"));
    	}
    	virtual void eventChunkOverrun () {
    		Logger::outputDebugString(T("overrun"));
    	}
    	DWORD getData (WORD *data, DWORD size) {
    		if (data == 0) return 0;
    		if (cs.tryEnter ()) { // if it's true, we locked.. (TODO: check, i'm not sure about that)
    			if (((size + nReadCounter) > nWriteCounter) || size == 0) { cs.exit(); return 0; }
    			memcpy (data, pBuffer + nReadCounter, size*sizeof(WORD));
    			nReadCounter += size;
    			if (nReadCounter == nWriteCounter) { eventChunkIsEmpty() ; nWriteCounter = 0; nReadCounter = 0; }
    			cs.exit ();
    			return size;
    		}
    		return 0;
    	}
    	DWORD putData (WORD *data, DWORD size) {
    		if (data == 0) return 0;
    		if (cs.tryEnter ()) { // if it's true, we locked.. (TODO: check, i'm not sure about that)
    			if ((size + nWriteCounter) > nSize) { eventChunkOverrun(); cs.exit (); return 0; }
    			memcpy (pBuffer + nWriteCounter, data, size*sizeof(WORD));
    			nWriteCounter += size;
    			if (nWriteCounter == nSize ) eventChunkIsFull();
    			cs.exit ();
    			return size;
    		}
    		return 0;
    	}
    	inline DWORD getSize () {
    		return nSize;
    	}
    	// TODO: add check for nWriteCounter?
    	inline bool setSize (DWORD ChunkSize) {
    		if (bExchangeIsActive) return false;
    		nSize   = ChunkSize;
    		// TODO: add result check.
    		pBuffer = (WORD*) realloc ((void*)pBuffer, ChunkSize*sizeof(WORD));
    		if (pBuffer) return true;
    		return false;
    	}
    	inline DWORD getReadCounter () { return nReadCounter; }
    	inline DWORD getWriteCounter () { return nWriteCounter; }
    	juce_UseDebuggingNewOperator
    protected:
    	bool            bExchangeIsActive;
    	CHUNK_DIRECTION cdDirection;
    	DWORD           nSize;
    	DWORD           nWriteCounter;
    	DWORD           nReadCounter;
    	WORD            nChunkId;
    	WORD           *pBuffer;
    	CriticalSection cs;
    };
    #endif
    // EOF
    #include "Chunk.h"
    Chunk::Chunk (DWORD ChunkSize, WORD id, CHUNK_DIRECTION chunkDirection) {
    	bExchangeIsActive = false;
    	cdDirection       = chunkDirection;
    	nSize             = ChunkSize;
    	nWriteCounter     = 0;
    	nReadCounter      = 0;
    	nChunkId          = id;
    	pBuffer           = (WORD*) malloc (ChunkSize*sizeof(WORD));
    	zeromem (pBuffer, ChunkSize*sizeof(WORD));
    }
    Chunk::~Chunk () {
    	if (pBuffer) free (pBuffer);
    }
    // EOF

    Посвящается всем изобретателям велосипедов и просто неудачникам.. :(

    neudachnik, 27 Ноября 2010

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

    +168

    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
    function cleanUrl( $url ){
    	
    	$new_url = str_replace( " ", "-", $url );
    	$new_url = str_replace( "/", "-", $new_url );
    	$new_url = str_replace( "--", "-", $new_url );
    	$new_url = str_split( $new_url );
    	$new_url = preg_grep( "<[A-Za-z0-9-_]+>", $new_url );
    	$new_url = trim( implode( $new_url ) );
    	$new_url = strtolower($new_url);
    	
    	// Was still getting cases of double hyphens
    	$new_url = str_replace( "--", "-", $new_url );
    	
    	return $new_url;
    	
    }// end function - cleanUrl

    Спасаю "Говнокод.ру" пехапе шедевром.

    Yurik, 27 Ноября 2010

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

    +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
    33. 33
    34. 34
    35. 35
    void CVC6_SampleCodeDlg::OnButtonSaveframe() 
    {
    	// TODO: Add your control notification handler code here
    	SYSTEMTIME lpSysTime;
    	GetLocalTime(&lpSysTime);
    
    	long Dims = SafeArrayGetDim(pvBuffer.parray);
    	if(Dims != 1)
    		return;
    
    	char *pbuf = (char*)malloc(m_FrameSize);
    	char *pfinal = pbuf;
    	for(long i=0;i<m_FrameSize;i++)
    	{
    		SafeArrayGetElement(pvBuffer.parray, &i, pfinal++);
    	}
    	
    	FILE* fSaveFile;
    	CString saveName;
    	if(m_vportsdk.GetGetStreamType() == 1)
    		saveName.Format(".//%d%d%d_%d%d%d.mpg4",lpSysTime.wYear, lpSysTime.wMonth, lpSysTime.wDay,
    			lpSysTime.wHour, lpSysTime.wMinute, lpSysTime.wSecond);
    	else if(m_vportsdk.GetGetStreamType() == 2)
    		saveName.Format(".//%d%d%d_%d%d%d.jpg",lpSysTime.wYear, lpSysTime.wMonth, lpSysTime.wDay,
    			lpSysTime.wHour, lpSysTime.wMinute, lpSysTime.wSecond);
    
    	if((fSaveFile = fopen((LPCTSTR)saveName,"wb"))!=NULL)
    	{
    		fwrite(pbuf, 1, m_FrameSize, fSaveFile);
    		fclose(fSaveFile);
    	}
    	SafeArrayUnaccessData(pvBuffer.parray);
    	delete pbuf;
    	pbuf = NULL;
    }

    VPort ActiveX SDK PLUS от Moxa
    часть 5. Хватит пока :)

    absolut, 27 Ноября 2010

    Комментарии (12)
  10. C++ / Говнокод #4767

    +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
    void CVC6_SampleCodeDlg::OnButtonSetpreset() 
    {
    	// TODO: Add your control notification handler code here
    	CComboBox *pCombobox = (CComboBox *) GetDlgItem(IDC_COMBO_PRESETNAME);
    	CString strPresetName;
    	GetDlgItem(IDC_EDIT_PRESETNAME)->GetWindowText(strPresetName);
    	if(strPresetName != "")
    		m_vportsdk.SavePresetPosition(strPresetName, (pCombobox->GetCurSel()+1));
    	else{
    		GetDlgItem(IDC_COMBO_PRESETNAME)->GetWindowText(strPresetName);
    		m_vportsdk.SavePresetPosition(strPresetName, (pCombobox->GetCurSel()+1));
    	}
    }

    VPort ActiveX SDK PLUS от Moxa
    часть 4

    absolut, 27 Ноября 2010

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