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

    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
    const uuid = require('uuid');
    const param = process.argv[2];
    const count = Number(param);
    if(typeof count !== 'number' || isNaN(count) || count < 0) {
        console.error(`bad number parameter ${param}`);
        return;
    }
    console.log('namespace LotsofClass {');
    for(let i = 0; i <= count; i++) {
        console.log(`class Class${uuid.v4().replace(/-/g, '')}{}`);
    }
    console.log('}');

    mazhuravlev, 05 Апреля 2018

    Комментарии (1)
  2. JavaScript / Говнокод #24072

    +3

    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
    return query instanceof RegExp ?
        (function () {
    	fn.each(function (id) {
    	    if (id.match(query)) {
    		seatSet.push(id, this);
    	    }
    	});
    	return seatSet;
        })() :
        (query.length == 1 ?
    	(function (character) {
    	    //user searches just for a particual character
    	    fn.each(function () {
    		if (this.char() == character) {
    		      seatSet.push(this.settings.id, this);
    		}
    	    });
                return seatSet;
    	})(query) :
                (function () {
                    //user runs a more sophisticated query, so let's see if there's a dot
    		    return query.indexOf('.') > -1 ?
    		        (function () {
    		             //there's a dot which separates character and the status
    		                 var parts = query.split('.');
    		
    		                 fn.each(function (seatId) {
    		                     if (this.char() == parts[0] && this.status() == parts[1]) {
    		                         seatSet.push(this.settings.id, this);
    		                     }
    		                 });
    		
    		                 return seatSet;
    		         })() :
    		             (function () {
    		                 fn.each(function () {
    		                     if (this.status() == query) {
    		                         seatSet.push(this.settings.id, this);
    		                     }
    		                 });
    		                return seatSet;
    		         })();
    		     })()
    		 );

    https://github.com/mateuszmarkowski/jQuery-Seat-Charts -- отсюда, заставила нелегкая использовать на одном мелком проекте. в пост запилил самый блистательный и ароматный кусок

    bakahakka, 04 Апреля 2018

    Комментарии (0)
  3. JavaScript / Говнокод #24056

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (typeof _dragon_pic_shift[el]['did'] === typeof undefined || typeof _dragon_pic_shift[el]['pic_id'] === typeof undefined ) {
        continue;
    }
                
    if (_dragon_pic_shift[el]['did'].indexOf(active_dragon_id) >= 0 
        && _dragon_pic_shift[el]['pic_id'].indexOf(active_dragon_lvl) >= 0
        && _dragon_pic_shift[el]['place'] == this_place) {
        css_shift_class = _dragon_pic_shift[el]['css_shift'];
        break;
    }

    это какой то новый уровень построения условий в js

    Snickers, 02 Апреля 2018

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

    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
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    'use strict';
    
    function map(fn, array) {
    	let arr = [];
    	for(let i of array)
    		arr.push(fn(i));
    	return arr;
    }
    
    function take(fn, count) {
    	var arr = [];
    	for(let i = 0; i < count; i++)
    		arr.push(fn());
    	return arr;
    }
    
    function sequence(start, step)
    {
    	step = step || 1;
    	start = start || 0;
    	start-=step;
    	return function() {
    		return start+=step;
    	}
    }
    
    function fmap(a, gen) {
    	return (...args) => {
    		if(args.length > 0)
    			return a(gen(...args));
    		else
    			return a(gen());
    	};
    }
    
    function partial(fn, ...args) {
    	return (...twoArgs) => {
    		let newM = args.slice();
    		for(let k of twoArgs)
    			newM.push(k);
    		return fn(...newM);
    	};
    }
    
    function partialAny(fn, ...args) {
    	return (...twoArgs) => {
    		let newM = args.slice();
    		let k = 0;
    		for(let i = 0; i < newM.length; i++)
    			if(newM[i] === undefined)
    				newM[i] = twoArgs[k++];
    		while(twoArgs[k] !== undefined) {
    			newM.push(twoArgs[k]);
    			k++;
    		}
    		return fn(...newM);
    	};
    }
    
    function bind(fn, context) {
    	return (...args) => {
    		return fn.apply(context, args);
    	};
    }
    
    function pluck(objects, fieldName) {
    	let a = [];
    	for(let i = 0; i < objects.length; i++)
    		if(objects[i][fieldName] !== undefined)
    			a.push(objects[i][fieldName]);
    	return a;
    }
    
    function filter(arr, fn) {
    	let a = [];
    	arr.forEach((item, i, arr) => {
    		if(fn(item))
    			a.push(item);
    	});
    	return a;
    }
    
    function count(arr) {
    	return Object.keys(arr).length;
    }
    
    var a = { a: 1, b: 2 };
    console.log(count(a)); // 2
    var b = function () {};
    console.log(count(b)); // 0
    var c = [1, 2, 3];
    console.log(count(c)); // 3
    var d = [];
    d[100] = 1;
    console.log(count(d)); // 1

    Ня (^_^)
    Суперкодики!

    fuckercoder, 27 Марта 2018

    Комментарии (3)
  5. JavaScript / Говнокод #24003

    −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
    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
    90. 90
    91. 91
    92. 92
    buildChartStaffNeed: function() {
    		Stat.staffNeedWithTopIs = [];
    		var levelEducation = $('#level_education_filter').selectpicker('val');
    		var specId = $('#spec_filter').selectpicker('val');
    		var specTitle = $('#spec_filter option:selected').text();
    
    		var filter = JSON.parse(getKeyByUrl('filter'));
    		filter.specialty_id = specId;
    		filter.level_education = levelEducation;
    		$('#stat_detalise').show();
    
    		if (specId) {
    			$.ajax({
    				url: "/index.php/ajax/staff/get_need_by_spec_id/",
    				type: "POST",
    				dataType:'json',
    				data: {filter: JSON.stringify(filter)},
    				success: function(r) {
    
    					var regions = [];
    					var regionPrognosis = [];
    					var staffNeed = r.data.need.staff_need;
    
    					for (var i in staffNeed) {
    						var exist = inArray(staffNeed[i].region_title, regions);
    						if (typeof exist == 'boolean' && exist == false) {
    							regions.push(staffNeed[i].region_title);
    							regionPrognosis.push([0,0,0,0,0,0,0,0,0,0]);
    						}
    					}
    
    					for (var i in staffNeed) {
    						if (typeof inArray(staffNeed[i].region_title, regions) != 'boolean') {
    							var index = inArray(staffNeed[i].region_title, regions);
    							var currPrognoise = staffNeed[i].years_prognoses.split('|');
    							for (var p in currPrognoise) {
    								var cp = currPrognoise[p].split('-');
    								regionPrognosis[index][p] += cp[1] * 1;
    							}
    						}
    					}
    
    					var regionsHtmlBody = '';
    					for (var i in regions) {
    						regionsHtmlBody += "<tr>";
    						regionsHtmlBody += "<td>"+ incrementNum(i) +"</td>";
    						var regionTitle = regions[i] == null ? 'Не определено' : regions[i];
    						regionsHtmlBody += "<td>"+ regionTitle +"</td>";
    						for (var p in regionPrognosis[i]) {
    							regionsHtmlBody += "<td>"+  regionPrognosis[i][p] +"</td>";
    						}
    						regionsHtmlBody += "</tr>";
    					}
    
    					$('#spec_subjects').find('tbody').html(regionsHtmlBody);
    
    					var allCount = [0,0,0,0,0,0,0,0,0,0];
    
    					for (var i in regionPrognosis) {
    						for (var j in regionPrognosis[i]) {
    							allCount[j] += regionPrognosis[i][j];
    						}
    					}
    
    					var allHtml = '<tr><td></td><td><b>Всего:</b></td>';
    					for (var i in allCount) {
    						allHtml += '<td><b>' + allCount[i] + '</b></td>';
    					}
    					allHtml += '</tr>';
    
    					$('#spec_subjects').find('tbody').append(allHtml);
    
    					var industrys = [];
    					var industryPrognosis = [];
    					for (var i in staffNeed) {
    						var exist = inArray(staffNeed[i].industry_title, industrys);
    						if (typeof exist == 'boolean' && exist == false) {
    							industrys.push(staffNeed[i].industry_title);
    							industryPrognosis.push([0,0,0,0,0,0,0,0,0,0]);
    						}
    					}
    
    					for (var i in staffNeed) {
    						if (typeof inArray(staffNeed[i].industry_title, industrys) != 'boolean') {
    							var index = inArray(staffNeed[i].industry_title, industrys);
    							var currPrognoise = staffNeed[i].years_prognoses.split('|');
    							for (var p in currPrognoise) {
    								var cp = currPrognoise[p].split('-');
    								industryPrognosis[index][p] += cp[1] * 1;
    							}
    						}
    					}

    nir007, 26 Марта 2018

    Комментарии (4)
  6. JavaScript / Говнокод #24000

    +7

    1. 1
    console.log(24000);

    1024--, 26 Марта 2018

    Комментарии (77)
  7. JavaScript / Говнокод #23999

    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
    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}>
              <View>
              <Drawer
                content={<ControlPanel />}
                ref={(ref) => this._drawer = ref}
                openDrawerOffset={100}
                onOpen={this.onOpen}
                onClose={this.onClose}
                openDrawerOffset={0.5}
                tapToClose={true}
                // open={true}
              >
              </Drawer>
                <View>
                <Header toggleSidebar={this.toggleSidebar} />
                {/* <CryptoContainer /> */}
                </View>
              <Router>            
                  <Stack key="root">
                    <Scene key="homepage" component={Homepage} title="Homepage" />
                  </Stack>
              </Router>
              </View>
           </Provider>
        );
      }
    }

    wikus, 26 Марта 2018

    Комментарии (0)
  8. 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)
  9. JavaScript / Говнокод #23975

    −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
    export const getBasketProductsWithCount = state => {
      const productCount = id => R.compose(
        R.length,
        R.filter(basketId => R.equals(id, basketId.id))
      )(state.basket);
      const productWithCount = product => R.assoc('count', productCount(product.id), product);
    
      const uniqueIds = R.uniq(state.basket);
      const products = R.compose(
        R.map(productWithCount),
        R.map(id => id)
      )(uniqueIds);
    
      return products;
    };

    greshnik, 21 Марта 2018

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

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for condition in price_to_deposit_config
      condition_is_true = false
      if condition.range.length is 2
        if market_data[item.id].volume >= condition.range[0] and market_data[item.id].volume <= condition.range[1]
          condition_is_true = true
      if condition.range.length is 1
        if market_data[item.id].volume >= condition.range[0]
          condition_is_true = true
      if condition_is_true is true
        #mk deposit price by this condition

    CoffeeScript. Мозг плавится 2е сутки.
    Читабельность кода уровень Высоцкого, а то и выше.

    win32, 07 Марта 2018

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