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

    +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
    procedure TMyTr.Execute; // метод потока; эта процедура выполняется в отдельном потоке.
    var
    s,resp,ip,port:string;
    cw,i:integer;
    begin
      http:=TIdHTTP.Create(nil);
      cw:=getnumberproxy;
      while cw<form1.Memo1.Lines.Count do 
      begin
        s:=form1.Memo1.Lines[cw];
        i := Pos(':',s);
        IP := Copy(s,1,i-1);
        PORT := Copy(s,i+1,Length(s));
        try
          http.ProxyParams.ProxyServer:=ip;
          http.ProxyParams.ProxyPort:=StrToInt(port);
          http.ReadTimeout:=Form1.SpinEdit2.Value*1000;
          resp:=http.Get('http://ya.ru/');
          if pos('ya.ru',resp)<>0 then
          form1.Memo2.Lines.Add(ip+':'+port);
          except
            end;
          cw:=getnumberproxy;
          checked:=checked+1;
          end;
      http.Free;
    
    end;

    Вот так живут Америка с Европой; что интересно, ни поток ни форма ни разу не заглючили.

    Stertor, 23 Июня 2013

    Комментарии (17)
  2. Pascal / Говнокод #13216

    +129

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function stringreplaceall(text, byt, mot: string): string;
    var
      plats: integer;
    begin
      while pos(byt, text) > 0 do
      begin
        plats := pos(byt, text);
        delete(text, plats, Length(byt));
        insert(mot, text, plats);
      end;
      Result := text;
    end;

    Найди десять отличий с родной дельфийской StringReplace. (trollface)

    Stertor, 23 Июня 2013

    Комментарии (2)
  3. Pascal / Говнокод #13215

    +107

    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
    function FindPathInPath(path1: string; path2: string): Boolean;
    var
      lst: TStringlist;
      i, l: integer;
    begin
      lst := TStringlist.Create;
      // ----------------------------------------------
      path1 := stringreplaceall(path1, '/', '\');
      path1 := stringreplaceall(path1, '\\', '\');
      // ----------------------------------------------
       path2 := stringreplaceall(path2, '\', '');
       path2 := stringreplaceall(path2, '/', '');
       path2 := stringreplaceall(path2, '"', '');
       path2 := stringreplaceall(path2, '<', '');
       path2 := stringreplaceall(path2, '>', '');
       path2 := stringreplaceall(path2, '?', '');
       path2 := stringreplaceall(path2, '|', '');
       path2 := stringreplaceall(path2, ':', '');
       path2 := stringreplaceall(path2, '*', '');
      // ----------------------------------------------
      for i := 2 to CountString(path1, '\') + 1 do
      begin
        lst.Add(StringField(path1, '\', i));
      end;
      for l := 0 to lst.Count - 1 do
      begin
        if lstrcmpi(pchar(lst[l]), pchar(path2)) = 0 then
        begin
          FindPathInPath := True;
          break;
      end;
      end;
      lst.Free;
      FindPathInPath := false;
      exit;
    end;

    Функция для поиска названий подпапок в файловых путях.
    Трудно судить г..нокод ли это, но так как я все же использовал более изящное решение, то быть посему...

    Stertor, 23 Июня 2013

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

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var
        FormMeh: TFormMeh;
        x,y,len:integer;
          x2,y2:integer;
          x3,y3:integer;
          x0,y0, y20:integer;
          xa , ya : integer;
          v1 , v2 : integer;
        x1,y1,ar,dar:integer;
        anim:integer;

    Глобальные переменные отныне РАЗРЕШЕНЫ. Утверждаю, подпись моя.

    Stertor, 23 Июня 2013

    Комментарии (17)
  5. PHP / Говнокод #13213

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    $useAliasMap = $ctx->getOption('cache_alias_map', false) && array_key_exists($uri, $ctx->aliasMap);
    if ($useAliasMap && array_key_exists($uri, $ctx->aliasMap)) {
                        $resourceId = (integer) $ctx->aliasMap[$uri];
    }

    Видимо array_key_exists у разработчика только на второй раз срабатывает

    Agel_Nash, 22 Июня 2013

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

    +150

    1. 1
    2. 2
    3. 3
    if (!empty ($src) && !array_key_exists($src, $this->loadedjscripts)) {
                if (isset ($this->loadedjscripts[$src]))
                    return;

    Если ключа нет, то проверяем не null ли значение в массиве по этому индексу.

    Agel_Nash, 22 Июня 2013

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public function __isset($name) {
            return ($this->getOption(xPDO::OPT_HYDRATE_FIELDS) && array_key_exists($name, $this->_fields) && isset($this->_fields[$name]))
                || ($this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS)
                    && ((array_key_exists($name, $this->_composites) && isset($this->_composites[$name]))
                    || (array_key_exists($name, $this->_aggregates) && isset($this->_aggregates[$name]))));
        }

    ORM обертка одного очень популярного движка

    Agel_Nash, 22 Июня 2013

    Комментарии (11)
  8. Pascal / Говнокод #13210

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function IPP (var i: integer): integer;
    begin
      Result := i;
      Inc(i);
    end;

    TarasB, 21 Июня 2013

    Комментарии (36)
  9. Python / Говнокод #13209

    −102

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    a=[1,2,3,1,2,1,4]
     
    for i in a:
        if i is 1:
            zzz=222
        else:
            print zzz

    http://ideone.com/nhqqRU
    Сегодня весь день чинил странный баг, смысл которого сводится вот к такой синтетки.
    Притом если условие не выполниться на первой итерации http://ideone.com/G3Uf7V , то будет эксепшен.

    хуита, 21 Июня 2013

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

    +16

    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
    // Lock the write mutex, to provide consistency of data                                                                                            
    #define LOCK                                                                   \                                                                   
        if (_ugb) {                                                                \                                                                   
            if (pthread_mutex_lock(&_write_mutex) == EINVAL)                       \                                                                   
                ASSERT(0);                                                         \                                                                   
        }                                                                                                                                              
    // Unlock write mutex when data sent                                                                                                               
    #define UNLOCK                                                                 \                                                                   
        if (_ugb) {                                                                \                                                                   
            if (pthread_mutex_unlock(&_write_mutex) == EINVAL)                     \                                                                   
                ASSERT(0);                                                         \                                                                   
        } 
    
    // Пример использования
    
    void socket::add_var(uint16_t code, const void *buffer, uint32_t length)                                                                          
    {                                                                                                                                                  
        LOCK
        try                                                                                                                                       
        {                                                                                                                                              
            DEBUG_I(Vblock, "Sending code 0x%X of size 0x%X\n", code, length);                                                                         
            send(&code, sizeof(code));                                                                                                                 
            send(&length, sizeof(length));                                                                                                             
            send(buffer, length);                                                                                                                      
        }                                                                                                                                              
        catch (const error & ve)                                                                                                                       
        {                                                                                                                                              
            UNLOCK                                                                                                                                     
            DEBUG_E(Vblock, "Caught an exception!\n");                                                                                                 
            throw;                                                                                                                                     
        }                                                                                                                                              
        catch (...)                                                                                                                                    
        {                                                                                                                                              
            UNLOCK                                                                                                                                     
        }                                                                                                                                              
        UNLOCK                                                                                                                                         
    }

    OK_BOOST_LOCK_A_MUTEX

    roman-kashitsyn, 21 Июня 2013

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