1. C++ / Говнокод #25634

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    std::queue<char *> outQueue2;
    std::lock_guard<std::mutex> lock(mtx);
    mtx.lock();
    if (outQueue.size() > 0) {
    std::swap(outQueue2, outQueue);
    outQueue = {};
    }
    std::lock_guard<std::mutex> unlock(mtx);

    со слов автора:
    у меня 2 исходящие очереди
    в одну соседний поток ложит
    потом приходит тик
    врубает симафор
    копирует по-бырому очередь
    и чистит её
    дальше отпускает поток
    чтобы не ждать
    пока всё отправится
    и спокойно в соседнем потоке уже начинает BYtestream...
    и всё такое
    разьве не так делают в домах парижу?

    heh1137, 22 Мая 2019

    Комментарии (68)
  2. Lua / Говнокод #25633

    +1

    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
    utf8 = {}
    function utf8.charbytes(s, i)
       -- argument defaults
       i = i or 1
       local c = string.byte(s, i)
       
       -- determine bytes needed for character, based on RFC 3629
       if c > 0 and c <= 127 then
          -- UTF8-1
          return 1
       elseif c >= 194 and c <= 223 then
          -- UTF8-2
          local c2 = string.byte(s, i + 1)
          return 2
       elseif c >= 224 and c <= 239 then
          -- UTF8-3
          local c2 = s:byte(i + 1)
          local c3 = s:byte(i + 2)
          return 3
       elseif c >= 240 and c <= 244 then
          -- UTF8-4
          local c2 = s:byte(i + 1)
          local c3 = s:byte(i + 2)
          local c4 = s:byte(i + 3)
          return 4
       end
    end
    
    function utf8.len(s)
       local pos = 1
       local bytes = string.len(s)
       local len = 0
       
       while pos <= bytes and len ~= chars do
          local c = string.byte(s,pos)
          len = len + 1
          
          pos = pos + utf8.charbytes(s, pos)
       end
       
       if chars ~= nil then
          return pos - 1
       end
       
       return len
    end
    
    print(utf8.len("Аутизм")) --6
    
    local mt = {__len = function(self) 
          local k=0
          for _,v in pairs(self) do 
            k = k+1;
            if k > 1 then  print(1) return #self end
          end
          if k==1 and type(self[1])=="string" then
            print(utf8.len(self[k]))
          end
        end};
    setmetatable(_G,{
        __index = function(self, key) return setmetatable({key},mt) end} 
      )
    t=(#Аутизм) --12

    Чот пытался - но словил хуйца.

    3oJIoTou_xyu, 22 Мая 2019

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

    +2

    1. 1
    2. 2
    3. 3
    for ($j = 0; $j < rand(2, 5); $j++) {
        // тут какой-то другой код
    }

    На каждой новой итерации rand() пересчитывается, т.е. цикл сам не знает от нуля до скольки он будет

    antosha, 22 Мая 2019

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

    0

    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
    <table class="table  table-hover" id="tab2">
    							<tr>
    								<th>Штрихкод </th>
    								<th>Имя покупателя</th>
    								<th>Штук</th>
    							</tr>					
    					
    					</table>
    
    Код ajax
    					<script>
    			$(document).ready(function() { 
    
    				$.ajax({
    					type: "POST",
    					url: 'ajax.php',
    					data : 'task=tab2',
    					dataType: "html",
    					success: function(response) {
    						$('#tab2').append(response)
    
    					}
    
    				});
    			});
    
    	</script>
    		
    file/ajax.php
    * вызов списка клиентов ws_purchase*/
    		if ($ar_clean['task'] === "tab2") { echo "string";
    				$getServices = mysqli_query($db,"
    									 SELECT  *` 
    									 FROM ws_purchase  ");
    					
    								 while($Service = mysqli_fetch_assoc($getServices)) {
    								?>
    								<tr >
    									<td><?=$Service['id_purchase'] ?></td>
    									<td><?=$Service['other_barcode'] ?></td>
    									<td><?=$Service['username'] ?></td>								
    	   							</tr>
    	   						<?}			 
    			}

    Привет, я тут вызываю таблицу из бд mysql через ajax что бы при добавление ново и записью не обновить страницу,
    данные с бд приходе но при добавление новои записи нужно обновить страницу.
    Что не так?

    *Я не сселён в ajax

    arts, 22 Мая 2019

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

    +2

    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
    switch (field.type) {
        case 'checkbox':
        case 'notification':	
            if (field.type == 'notification') {
                fieldData.element.addClass('field-notification');
                $('<span class="notification-button" data-action="notification">').text('Принять').appendTo(body).on(
                    'click', function () {
    		    _class.wrapper.removeClass('notification');
    		    _class.notification.wrapper.removeClass('notification-active');
    		    _class.fields[index - 1].changeStatus();
    		    $Mediator.fire({
                            name: 'active:filter',
    			target: _class.fields[0].filter
    		    });
                });
            }
        break;
    }

    Вдруг SWITCH не сработал)

    JudiCortes, 21 Мая 2019

    Комментарии (39)
  6. Куча / Говнокод #25629

    +25189

    1. 1
    2. 2
    3. 3
    4. 4
    Обратил внимание, что сток превратился в обычное обсуждение в чате.
    Все читают всех, оффтопят, и похер в каком треде. А также когда я проверяю новые сообщения, хожу в телеграм, потом на хуз.
    Поэтому создал бота в телеге, который фактически повторяет функционал стока + можно оставлять комменты (конечно же они будут от guest8).
    По-моему получилось охуенно.

    http://t.me/GovnokodBot
    - посылаются посты и комменты
    - работает отправка и редактирование
    - если кто-то постит ссылку на картинку или youtube, телега автоматически отображает превью - удобно
    - нужно использовать bbcode
    - markdown -> bbcode - в TODO

    guest8, 20 Мая 2019

    Комментарии (181)
  7. SQL / Говнокод #25628

    −2

    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
    SELECT country, QTY, MIN(launched)
    FROM (SELECT country, launched, COUNT(name) QTY
     FROM Classes c JOIN 
     Ships s ON c.class = s.class
     GROUP BY country,launched
     HAVING COUNT(name) = (SELECT MAX(qty) 
     FROM (SELECT country,launched,COUNT(name) qty
     FROM Classes c1 JOIN 
     Ships s1 ON c1.class = s1.class
     WHERE country = c.country
     GROUP BY country,launched
     )e
     )
     )T
    GROUP BY t.qty, t.country;

    -2 sql ex rating
    я так понял необходимо ещё как-то добавить проверку на NULL?

    5252mmr, 20 Мая 2019

    Комментарии (6)
  8. SQL / Говнокод #25627

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    select Outcomes.ship,count(*)
    from Outcomes
    where outcomes.result!='sunk'
    group by ship
    HAVING count(*)>=2
    union
    select ships.name,count(*)
    from ships
    where ships.launched!=NULL
    group by name
    HAVING count(*)>=2

    -9 sql ex...

    неверно на тренировочной

    коммент :
    парсить имя на '%NAME%' ? или как ?

    5252mmr, 20 Мая 2019

    Комментарии (1)
  9. SQL / Говнокод #25626

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    select distinct pass_in_trip.trip_no, (pass_in_trip.trip_no/5+pass_in_trip.trip_no/25+pass_in_trip.trip_no/125+pass_in_trip.trip_no/625+pass_in_trip.trip_no/3125+pass_in_trip.trip_no/15625+pass_in_trip.trip_no/78125)
    from pass_in_trip
    union
    select distinct trip.trip_no, (trip.trip_no/5+trip.trip_no/25+trip.trip_no/125+trip.trip_no/625+trip.trip_no/3125+trip.trip_no/15625+trip.trip_no/78125)
    from Trip

    -12 рейтинговое sql ex... на тренировочной что-то не так...
    наверно что-то связанное с NULL ?
    добавить проверку ?

    5252mmr, 20 Мая 2019

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

    0

    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
    select model,(CAST(substring(model, 1, 1) as int)+CAST(substring(model, 2, 1) as int)+CAST(substring(model, 3, 1) as int)+CAST(substring(model, 4, 1) as int)) as qty
    from product
    where  
    (substring(model, 1, 1) like '0' or substring(model, 1, 1) like '1' or substring(model, 1, 1) like '2' 
    or substring(model, 1, 1) like '3' or substring(model, 1, 1) like '4' or substring(model, 1, 1) like '5' 
    or substring(model, 1, 1) like '6' or substring(model, 1, 1) like '7' or substring(model, 1, 1) like '8' 
    or substring(model, 1, 1) like '9')
     AND (substring(model, 2, 1) like '0' or substring(model, 2, 1) like '1' or substring(model, 2, 1) like '2' 
     or substring(model, 2, 1) like '3' or substring(model, 2, 1) like '4' or substring(model, 2, 1) like '5' 
     or substring(model, 2, 1) like '6' or substring(model, 2, 1) like '7' or substring(model, 2, 1) like '8' 
     or substring(model, 2, 1) like '9') 
     AND (substring(model, 3, 1) like '0' or substring(model, 3, 1) like '1' or substring(model, 3, 1) like '2' 
    or substring(model, 3, 1) like '3' or substring(model, 3, 1) like '4' or substring(model, 3, 1) like '5'
     or substring(model, 3, 1) like '6' or substring(model, 3, 1) like '7' or substring(model, 3, 1) like '8' 
     or substring(model, 3, 1) like '9') 
     AND (substring(model, 4, 1) like '0' or substring(model, 4, 1) like '1' or substring(model, 4, 1) like '2'
     or substring(model, 4, 1) like '3' or substring(model, 4, 1) like '4' or substring(model, 4, 1) like '5' 
     or substring(model, 4, 1) like '6' or substring(model, 4, 1) like '7' or substring(model, 4, 1) like '8' 
     or substring(model, 4, 1) like '9')
    
    
    
    select model, 
    ASCII(SUBSTRING(model,1,1))+ 
    ASCII(SUBSTRING(model,2,1))+ 
    ASCII(SUBSTRING(model,3,1))+ 
    ASCII(SUBSTRING(model,4,1)) 
    -48*4 as qty from Product
    тоже не помогло.

    sql ex рейтинговое 4. показывает что на тренировочной что-то не правильно.
    лайк же вроде проверяет '1' как цифру а не как строку.
    любые хинты как тут

    5252mmr, 20 Мая 2019

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