- 1
- 2
if(~window.location.href.indexOf('#')){
var el = window.location.href.slice(window.location.href.indexOf('#')+1,~window.location.href.indexOf('?')?window.location.href.indexOf('?'):window.location.href.length);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+6
if(~window.location.href.indexOf('#')){
var el = window.location.href.slice(window.location.href.indexOf('#')+1,~window.location.href.indexOf('?')?window.location.href.indexOf('?'):window.location.href.length);
location.hash? не, не слышал
+3
function getBounds(curve) {
var px;
var py;
var qx;
var qy;
var rx;
var ry;
var sx;
var sy;
var tx;
var ty;
var tobx;
var toby;
var tocx;
var tocy;
var todx;
var tody;
var toqx;
var toqy;
var torx;
var tory;
var totx;
var toty;
var step;
var x;
var y;
var minX;
var minY;
var maxX;
var maxY;
var ax = curve[0].x;
var ay = curve[0].y;
var bx = curve[1].x;
var by = curve[1].y;
var cx = curve[2].x;
var cy = curve[2].y;
var dx = curve[3].x;
var dy = curve[3].y;
var ITERATIONS_COUNT = 250;
minX = minY = Number.POSITIVE_INFINITY;
maxX = maxY = Number.NEGATIVE_INFINITY;
tobx = bx - ax;
toby = by - ay;
tocx = cx - bx;
tocy = cy - by;
todx = dx - cx;
tody = dy - cy;
step = 1 / ITERATIONS_COUNT;
for (var i = 0; i < ITERATIONS_COUNT; i++) {
var d = i * step;
px = ax + d * tobx;
py = ay + d * toby;
qx = bx + d * tocx;
qy = by + d * tocy;
rx = cx + d * todx;
ry = cy + d * tody;
toqx = qx - px;
toqy = qy - py;
torx = rx - qx;
tory = ry - qy;
sx = px + d * toqx;
sy = py + d * toqy;
tx = qx + d * torx;
ty = qy + d * tory;
totx = tx - sx;
toty = ty - sy;
x = sx + d * totx;
y = sy + d * toty;
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
return {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
}
Хорошей функции должно быть много
+1
while ((math == (math = Math)).toString() == "true") {
...
}
программист-дотер
+2
str.indexOf('#') === 0
Проверка что строка начинается с '#'
+1
componentDidMount() {
this.clickListener = (e) => {
var input = document.getElementById('searchInput');
var filtersBar = document.getElementById('filters');
var searchBar = document.getElementById('search');
var clearButton = document.getElementById('suggestInputClearBtn');
var isNav = e.target.className.indexOf('suggestNavBtn') >= 0;
if(input == e.target || searchBar == e.target || filtersBar == e.target || clearButton == e.target || isNav || e.target.className.indexOf('tags-controller-wrapper') !== -1)
return;
var classes = e.target.c†.split(' ');
for(var cls of classes){
if(cls == 'autocompleteItem')
{
return;
}
}
if(this.props.isSuggestInputVisible)
this.props.onCloseAutosuggestion();
};
this.attachClickListener();
}
Я бы только за if без скобок прибил) Обратите внимание на 4 выборки по id которые можно было не делать каждый раз при клике, а если приглядеться то можно понять, что можно было совсем не выбирать ни разу, а если бы пионер знал что всплытие событие можно остановить то этот метод занял бы три строчки и на десерт обратите внимание как он перебирает значение className циклом - это при том что в этом проекте можно писать на es6 Это самый дебильный код который я видел в этом году
−3
class Point {
x: number;
y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
getDist() {
return Math.sqrt(this.x * this.x +
this.y * this.y);
}
}
var p = new Point(3,4);
var dist = p.getDst(); // <- пропущена буква i в названии метода getDist()
alert("Hypotenuse is: " + dist);
Неработающий пример кода на TypeScript прямо на главной странице официального сайта этого языка ( http://www.typescriptlang.org ). TypeScript, если что, разработка Microsoft. Надеюсь, винду они не пишут с такими же позорными ошибками
+1
// Qt QML >:D
UI_Button
{
id: bt_connect
height: 40
width: 150
radiusBorder: 20
anchors.right: led_connection.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
textOn: qsTr("Отключиться")
textOff: qsTr("Подключиться")
state: putState(QVipGUI.btConnection)
onClicked:{
if(QVipGUI.btConnection !== GuiDefines.DEF_STATE_DIMMED) {
if(QVipGUI.btConnection === GuiDefines.DEF_STATE_OFF) {
QVipGUI.setLedConnection(GuiDefines.DEF_STATE_OFF)
QVipGUI.method_ActionGui(GuiDefines.ID_ACTION_CONNECT)
QVipGUI.method_ActionGui(GuiDefines.ID_ACTION_GETPORT) // <!>
var i = 0;
while(++i < 1000000){};
QVipGUI.method_ActionGui(GuiDefines.ID_ACTION_GETCONF);
}
else {
QVipGUI.method_ActionGui(GuiDefines.ID_ACTION_DISCONNECT)
}
}
}
}
Qt-среда, язык описания интерфейса - QML >:D
+1
function intersectRange (r1, r2) {
return !(Math.max(r1['min'], r2['min']) > Math.min(r1['max'], r2['max']));
}
Пересечения диапазонов.
Это то самое, которое: (r1[min] <= r2[max]) and (r1[max] >= r2[min])
Я ж джва года над этим думал, прежде чем накласть.
0
} else if(location.href.split('#')[1] == 'optimal') {
var str = $($('.dropdown-section-title')[1]).text().trim();
$('#package_select').removeClass('services-package-start').addClass('services-package-optimal');
$('#package_select').text(str+' ('+$($($('.form_select_body')[1]).find('.dropdown').find('.services-package-optimal')[1]).text().trim()+')');
$('.package-overview-price p').text(pricesCost[getCookie('language')] + prices[parseInt($($($('.form_select_body')[1]).find('.dropdown').find('.services-package-optimal')[1]).text().trim())]);//+ pricesMonth[getCookie('language')]
$('.registration-section-right').find('.packages-overview-section').find('.package-overview-price').addClass('services-package-optimal');
$('.registration-section-left').find('.service-packages-select').find('span.value').removeClass('services-package-start').addClass('services-package-optimal').text(str+' ('+$($($('.form_select_body')[1]).find('.dropdown').find('.services-package-optimal')[1]).text().trim()+')');
0
if (document.querySelector('.instruction-wrapper')) {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function() {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame
})();
}
var animator = {
stageArray: [
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
[14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
],
// min:16,max:25,
element: document.querySelector('.instruction-wrapper'),
originalClassName: 'instruction-wrapper',
currentStage: 1,
currentStep: 0,
oldTime: new Date().getTime(),
timeStep: 1200,
addStateClass: 'state-', //+stateRange.currentStep
chaning: true,
repeat: true,
debug: true,
autoplay: true,
animate: function() {
requestAnimationFrame(animator.animate);
if (animator.autoplay) {
animator.draw();
}
},
classCheckUpdate: function(arg1) {
this.element.className = this.originalClassName;
for (var i = 0; i <= arg1; i++) {
this.element.classList.add(this.addStateClass + '' + i);
}
},
draw: function(arg) {
var time = new Date().getTime();
// console.log(time - oldTime);
if (time > this.oldTime + this.timeStep) {
if (this.debug) {
console.log(this.currentStep)
};
this.oldTime = time;
if (!arg && !!this.stageArray[this.currentStage][this.currentStep + 1]) {
console.log('instr-' + 1 + '_' + this.stageArray[this.currentStage][this.currentStep + 1]);
this.currentStep += 1;
this.classCheckUpdate(this.stageArray[this.currentStage][this.currentStep])
// this.element.classList.add(this.addStateClass + '' + this.stageArray[this.currentStage][this.currentStep]);
} else if (!arg && !this.stageArray[this.currentStage][this.currentStep + 1] && !!this.repeat) {
this.currentStep = 0;
console.log('instr-' + 2);
this.classCheckUpdate(this.stageArray[this.currentStage][this.currentStep])
// this.element.className = this.originalClassName;
// this.element.classList.add(this.addStateClass + '' + this.stageArray[this.currentStage][this.currentStep]);
} else if (!this.stageArray[this.currentStage][this.currentStep + 1] &&
!this.repeat &&
this.stageArray[this.currentStage + 1]) {
this.currentStage += 1;
console.log('instr-' + 3);
this.currentStep = this.stageArray[this.currentStage + 1][0];
} else if (arg > 1) {
console.log('instr-' + 4);
this.element.className = this.originalClassName;
for (var i = 0; i <= arg; i++) {
this.element.classList.add(this.addStateClass + '' + i);
this.element.classList.add(this.addStateClass + '' + this.stageArray[this.currentStage][this.currentStep]);
}
}
}
}
}
animator.animate();
}
Перекулючение классов для анимационного сценария