1. JavaScript / Говнокод #23998

    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
    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
    import React, { Component } from 'react';
    import { View, Text } from 'react-native';
    import { Provider } from 'react-redux';
    
    import Store from './src/Store';
    import { Header, CryptoContainer, ControlPanel, Homepage } from './src/components';
    import Drawer from 'react-native-drawer';
    
    import {
      Scene,
      Router,
      Actions,
      Reducer,
      ActionConst,
      Overlay,
      Tabs,
      Modal,
      Stack,
      Lightbox,
    } from 'react-native-router-flux';
    
    export default class App extends Component {
      constructor(props) {
        super(props);
        this.state = { isOpen: false };
      }
    
      toggleSidebar = () => {
        console.debug(this.state.isOpen);
        if (this.state.isOpen) {
          this._drawer.close();
        } else {
          this._drawer.open();
        }
      }
    
      onOpen = () => {
        console.debug('onOpen');
        this.setState({ isOpen: true });
      }
    
      onClose = () => {
        console.debug('onClose');
        this.setState({ isOpen: false });
      }
    
      render() {
        // <View>
    //   <Header toggleSidebar={this.toggleSidebar} />
    //   <CryptoContainer />
    // </View>
    
        return (
          <Provider store={Store}>
            <Drawer
              content={<ControlPanel />}
              ref={(ref) => this._drawer = ref}
              openDrawerOffset={100}
              onOpen={this.onOpen}
              onClose={this.onClose}
              openDrawerOffset={0.5}
              tapToClose={true}
              // open={true}
            >
              <View>
              <Router>            
                  <Stack key="root">
                    <Scene key="homepage" component={Homepage} title="Homepage" />
                  </Stack>
              </Router>
              </View>
            </Drawer>
          </Provider>
        );
      }
    }

    wikus, 26 Марта 2018

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

    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
    public function isSpecial()
        {
    		$special_ids = array(
    			2222,
    			3028,
    			3333,
    			5555,
    			5702,
    			6666,
    			6700,
    			7654,
    			7777,
                8451,
    			11225
    		);
    		return in_array((int)$this->getId(), $special_ids);
            //return $this->getId() == 2222 || $this->getId() == 3028 || $this->getId() == 3333 || $this->getId() == 5555 || $this->getId() == 5702;
        }

    Нашел поняшек
    https://github.com/wiistriker/govnokod_legacy/blob/9f1b89379a64f87a275f9d932128870a8292fb1e/modules/quoter/models/quote.php

    inho, 26 Марта 2018

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

    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
    <?
    if(get($_REQUEST, 'class') && $class = "{$conf['db']['prefix']}{$arg['modpath']}_". ($t = first(explode(" ", $_REQUEST['class'])))){
    	if($arg['admin_access'] > 1){
    		mpevent("ajax://{$arg['modpath']}:ajax/class:{$t}", $conf['user']['uid'], $_REQUEST);
    		$where = array_diff_key($_REQUEST, array_flip(array("class", "m", "null")));
    		$w = array("time"=>time()) + array_diff_key($_REQUEST, array("id"=>false));
    		if($arg['admin_access'] >= 2){
    			if(get($_POST, 'id') < 0){
    				qw("DELETE FROM {$class} WHERE ". implode(" AND ", array_map(function($k, $v){
    					return "`$k`=". (is_numeric($v) ? (int)$v : "\"". mpquot($v). "\"");
    				}, array_keys($where), array_values($where))));
    				exit("{}");
    			}elseif(!$fdk = fdk($class, $where, $w = ($where + ($_POST ? $w : [])), $w)){ exit(mpre("Ошибка запроса к БД", $class, $where, $w));
    			}else{
    				if(array_key_exists("sort", $fdk) && ($fdk['sort'] == 0)){
    					$fdk = fdk($class, array("id"=>$fdk['id']), null, array("sort"=>$fdk['id']));
    				} if($_FILES) foreach($_FILES as $f=>$v){
    					$file_id = mpfid($class, $f, $fdk['id']);
    				}elseif($img = get($_POST, $f = 'img')){
    					$file_id = mphid($class, $f, $fdk['id'], $img);
    				} exit(json_encode($fdk));
    			}
    		}else{
    			$error = "Прав доступа {$arg['admin_access']} недостаточно для изменения данных";
    			mpevent("Аякс запрос /{$arg['modpath']}:{$class[0]}", $conf['user']['uid'], $error, $_REQUEST);
    			exit($error);
    		}
    	}else{
    		$error = "Недостаточно прав доступа";
    		mpevent("Аякс запрос /{$arg['modpath']}:{$class[0]}", $conf['user']['uid'], $error, $_REQUEST);
    		exit($error);
    	}
    }else{
    	$error = "Не указана таблица";
    	mpevent("Аякс запрос /{$arg['modpath']}:{$class[0]}", $conf['user']['uid'], $error, $_REQUEST);
    	exit($error);
    }

    https://github.com/mpak2/mpak.su/blob/master/modules/seo/ajax.php

    inho, 26 Марта 2018

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    class UserFixture extends ActiveFixture
    {
        public function getDataMorozov() {
            return $this->getData();
        }
    
        protected function getData() {
    ...

    Yii 2 fixtures. Называем костыли правильно

    kissarat, 25 Марта 2018

    Комментарии (11)
  5. Objective C / Говнокод #23987

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    NSString* bodyParams = [NSString stringWithFormat:@"username=%@&password=%@&client_secret=very_secret", username, password];
    
    // Ниже по коду
    
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[bodyParams dataUsingEncoding:NSUTF8StringEncoding]];

    И ведь имя переменной не врёт

    Desktop, 23 Марта 2018

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

    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
    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
    89. 89
    class NTPTime {
    public:
    	static NTPTime getInvalidTime() { NTPTime t; t.setInvalid(); return t; }
    
    public:
    	NTPTime() : m_Time(0) {}
    	NTPTime(const uint64_t time) : m_Time(time) {}
    	NTPTime(const uint32_t sec, const uint32_t frac)
    	  : m_Time(0)
    	{
    		this->set(sec, frac);
    	}
    
    	NTPTime(const boost::posix_time::ptime& timestamp);
    
    public: // Assignment operators
    	NTPTime& operator=(const uint64_t u) { m_Time = u; return *this; }
    	NTPTime& operator+= (const NTPTime& Q) { m_Time += Q.m_Time; return *this; }
    	NTPTime& operator-= (const NTPTime& Q) { m_Time -= Q.m_Time; return *this; }
    
    public: // Cast operators
    	operator uint64_t() { return this->m_Time; }
    
    public: // comparison operators
    	bool operator==(const NTPTime& other) const { return (m_Time == other.m_Time); }
    	bool operator!=(const NTPTime& other) const { return (m_Time != other.m_Time); }
    	bool operator>=(const NTPTime& other) const { return (m_Time >= other.m_Time); }
    	bool operator>(const NTPTime& other) const { return (m_Time > other.m_Time); }
    	bool operator<=(const NTPTime& other) const { return (m_Time <= other.m_Time); }
    	bool operator<(const NTPTime& other) const { return (m_Time < other.m_Time); }
    
    public: // arithmetic operators
    	NTPTime operator+(const NTPTime& other) const
    	{
    		NTPTime result = *this;
    		result += other;
    		return result;
    	}
    
    	NTPTime operator-(const NTPTime& other) const
    	{
    		NTPTime result = *this;
    		result -= other;
    		return result;
    	}
    
    public:
    	uint32_t getSeconds() const { return ((uint32_t)(m_Time >> 32));}
    	uint32_t getFracSeconds() const { return ((uint32_t)(m_Time & 0xFFFFFFFF));}
    	uint32_t getMilliseconds() const { const uint64_t t = 1000*m_Time ; return (uint32_t)((t>>32)&0xFFFFFFFF);}
    	uint32_t getMicroseconds() const { const uint64_t t = 125*m_Time/536871; return (uint32_t)(t&0xFFFFFFFF);}
    	void getTime_s_us(uint32_t& sec, uint32_t& us) const { sec = getSeconds(); us = getFracSeconds()/4295;}
    	uint64_t getTime(void) const {return m_Time;}
    
    public:
    	/// set the time in seconds and microseconds (micros: 0..1000 0000)
    	///This routine uses the factorization: 2^32/10^6 = 4096 + 256 - 1825/32
    	void setTime_s_us(const uint32_t sec, const uint32_t us) { m_Time = ((uint64_t)sec<<32) | ((us<<12)-((us*1852)>>5)+(us<<8));}
    
    	void set(const uint64_t& u) {m_Time = u;}
    	void set(const uint32_t sec, const uint32_t frac)
    	{
    		m_Time = sec;
    		m_Time = m_Time<<32;
    		m_Time |= frac;
    	}
    
    	void setInvalid() { m_Time = uint64_t(NOT_A_DATE_TIME) << 32; }
    
    	/// 2^32/10^6 = 4096 + 256 - 1825/32
    	void setMicroseconds(const uint32_t u) { const uint64_t t = ((uint64_t)u * 1825) >> 5; m_Time = ((uint64_t)u << 12) + ((uint64_t)u << 8) - t;}
    	void setMicroseconds(const uint64_t u) { const uint64_t t = (u * 1825) >> 5; m_Time = (u << 12) + (u << 8) - t;}
    	void setMilliseconds(const uint32_t u) { m_Time = (uint64_t)u * 536870912 / 125;}
    	void addMilliseconds(const uint32_t u) { NTPTime t; t.setMilliseconds(u); *this += t;}
    	void addMicroseconds(const uint32_t u) { NTPTime t; t.setMicroseconds(u); *this += t;}
    
    protected:
    	static double round(const double v);
    
    private:
    	static const double secondFractionNTPtoNanoseconds;
    	static const double nanosecondsToSecondFractionNTP;
    	static const uint32_t NOT_A_DATE_TIME;
    	static const uint64_t NOT_A_DATE_TIME64;
    	static const boost::posix_time::ptime m_epoch;
    
    protected:
    	uint64_t m_Time; ///< NTP time in 1/2^32 seconds (~233 ps)
    }; // NTPTime

    Чуть г-на и несколько комментов удалил, чтоб влезло. Чтоб понятно было, m_Time хранит время в единицах 1/2^32 сек.

    elapidae, 22 Марта 2018

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // OK
    class foo {};
    void foo();
    
    // не ОК: error: 'void bar()' redeclared as different kind of symbol
    namespace bar {}
    void bar();

    "Двойные стандарты"

    Elvenfighter, 22 Марта 2018

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    
    switch ($type) {
        case 'text';
            echo 'А вы знали';
            break;
        case 'number';
            echo 'что так можно?';
            break;
    }

    inho, 22 Марта 2018

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    template<class T, T = 1>
        constexpr bool __can_one(int) { return true; };
        template<class T>
        constexpr bool __can_one(long) { return false; };
    
        template <class T>
        constexpr bool is_integral_v = __can_one<T>(0);

    https://twitter.com/ericniebler/status/976524085927731200
    Не кто попало, а автор Ranges TS (без пяти минут кусок стандарта) сомневается, валидную метушню он написал или нет. Пора уже создавать крестоблядский суд, который будет трактовать букву стандарта и решать, где с++ а где нет. И разрабы гцц будут нанимать за бешеное бабло крестоблядских юристов и судиться в крестоблядском суде с авторами багрепортов.

    subaru, 21 Марта 2018

    Комментарии (3)
  10. 1C / Говнокод #23976

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    Если Не ЗначениеЗаполнено(ДатаПриемаСотрудника) Тогда
    		Возврат 0;
    		Предупреждение("У сотрудника "+Сотрудник+" нет даты приема проведите прием на работу");
    	КонецЕсли;

    еее анричабол стейтментс

    sgo, 21 Марта 2018

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