- 1
https://software.intel.com/sites/billboard/article/simd-javascript-faster-html5-apps
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+159
https://software.intel.com/sites/billboard/article/simd-javascript-faster-html5-apps
Почему нужно выбрать самый говенный язык, и усиленно добавлять в него фичи, с которыми он все равно не может нормально работать? :( Просто пиздец какой-то.
+156
function EngineListCtrl($scope, $timeout, $http)
{
$scope.engines = {};
$scope.workers = [];
$scope.checkEngines = function(){
$http.get(engineUrl + '&type=json&jcmd=getClients').success(function(req){
var engines = {};
var workers = {};
$scope.workers = []; // Это в отрисовке не используется.
// Сначала распихиваю всех по местам
angular.forEach(req, function(ob, i){
if( ob.info.type == 'engine' )
engines[ob.info.engine] = ob;
if( ob.info.type == 'worker' ){
if( workers[ob.info.engine] == undefined )
workers[ob.info.engine] = {};
workers[ob.info.engine][ob.info.worker] = ob;
if( ob.task && ob.task.state )
ob.info.state = ob.task.state;
$scope.workers.push(ob);
}
});
// Перебераю уже имеющиеся объекты
angular.forEach($scope.engines, function(engineOb, engineName){
var needRemove = true;
angular.forEach(engines, function(val, key){
if( engineName == key ){
angular.extend($scope.engines[engineName], val);
needRemove = false;
}
});
if( needRemove == false && $scope.engines[engineName] ){
$scope.checkEngineEvents($scope.engines[engineName]);
if( workers[engineName] != undefined ){
if( $scope.engines[engineName].workers == undefined )
$scope.engines[engineName].workers = {};
angular.extend($scope.engines[engineName].workers, workers[engineName]);
}else
$scope.engines[engineName].workers = {};
}
if( needRemove == true ){
delete $scope.engines[engineName];
}
});
// А теперь новые добавляю
angular.forEach(engines, function(engineOb, engineName){
if( $scope.engines[engineName] == undefined ){
$scope.engines[engineName] = engineOb;
if( workers[engineName] != undefined ){
if( $scope.engines[engineName].workers == undefined )
$scope.engines[engineName].workers = {};
angular.extend($scope.engines[engineName].workers, workers[engineName]);
}
$scope.checkEngineEvents($scope.engines[engineName]);
}
});
$timeout($scope.checkEngines, 2000);
});
}
$timeout($scope.checkEngines, 1000);
+155
function deposit(){
if(document.getElementById("no_of_year").value=="1") {
document.getElementById("interest_rate").value="9.5"
}
if(document.getElementById("no_of_year").value=="2") {
document.getElementById("interest_rate").value="10"
}
if(document.getElementById("no_of_year").value=="3") {
document.getElementById("interest_rate").value="10.5"
}
if(document.getElementById("no_of_year").value=="4") {
document.getElementById("interest_rate").value="11"
}
if(document.getElementById("no_of_year").value=="5") {
document.getElementById("interest_rate").value="11.5"
}
}
отсюда - http://stackoverflow.com/questions/24236980/values-not-passing-in-to-database
+159
var pz = 1/Infinity;
var mz = -1/Infinity;
// неотличимы
pz == mz; // true
pz === mz; // true
mz < pz; // false
pz < mz; // false
// но
Math.min(pz, mz); // -0
Math.max(pz, mz); // 0
Так как же отличить -0 от +0?
(-1.0 / mz) == Infinity?
+156
(function(G, D) {
"use strict";
var $ = G.jQuery,
listener;
function addListener(elem, fn) {
function handler(event) {
event = event || G.event;
var dx = event.DeltaX || event.wheelDeltaX || event.detail || 0,
dy = event.DeltaY || event.wheelDeltaY || event.detail || 0;
event.dx = dx === 0 ? 0 : dx / Math.abs(dx);
event.dy = dy === 0 ? 0 : dy / Math.abs(dy);
fn(event);
}
if (elem.addEventListener) {
if (D.hasOwnProperty('onwheel')) { //Modern browsers
listener = "wheel";
} else if (D.hasOwnProperty('onmousewheel')) { //Old browsers
listener = "mousewheel";
} else { //FF<17
listener = "MozMousePixelScroll";
}
elem.addEventListener(listener, handler, false);
} else { //IE<9
elem.attachEvent("onmousewheel", handler);
listener = "onmousewheel";
}
}
function removeListener(elem) {
if (elem.removeEventListener) {
elem.removeEventListener(listener);
} else {
elem.detachEvent(listener);
}
}
$.fn.mousewheel = function(fn) {
return this.each(function() {
addListener(this, fn);
});
};
$.fn.unmousewheel = function(fn) {
return this.each(function() {
removeListener(this, fn, false);
});
};
}(this, document));
Написал плагин для jQuery, который цепляет на элементы обработчик события вращения колесика мыши. Что скажете? Как бы вы написали функцию unmousewheel()?
+149
(function (G) {
"use strict";
var $ = G.jQuery;
if ($ === undefined) {
G.console.log("jQuery not found.");
return;
}
function resizeContainer() {
$("div.container").outerHeight($(G).innerHeight());
}
$(G).resize(resizeContainer);
resizeContainer();
}(this));
Вот тут: http://jsfiddle.net/dunmaksim/NWN5f/3/ написал небольшой код, который позволяет сделать разметку на странице в стиле ModernUI. Высота контейнера автоматом подгоняется под высоту окна. Код прогнал через JSLint. Решение ориентировано на новые браузеры. Какие будут замечания? Замыкание использую для ограничения пространства имён.
+162
var interval = setInterval(function() {}, 10000);
// get rid of the newline-removing interval
for (var j = interval - 10000; j < interval + 10000; j++) { clearInterval(j); }
Кусок юзерскрипта, позволяющего вставлять переносы строки в заданных вопросах на Tumblr.
Это просто волшебно...
+158
// weclome to main-menu-hover.js
function load(){
var url = window.location;
var m1 = document.getElementById("m1");
var m2 = document.getElementById("m2");
var m3 = document.getElementById("m3");
var m4 = document.getElementById("m4");
//var m5 = document.getElementById("m5");
var mm1 = document.getElementById("mm1");
var mm2 = document.getElementById("mm2");
var mm3 = document.getElementById("mm3");
var mm4 = document.getElementById("mm4");
var mm5 = document.getElementById("mm5");
var mm6 = document.getElementById("mm6");
var mm7 = document.getElementById("mm7");
var mm8 = document.getElementById("mm8");
if (m1.href == url){
m1.style.color = "#ffc12b";
//m1.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat top center";
m1.style.textDecoration = "none";
}
if (m2.href == url){
m2.style.color = "#ffc12b";
m2.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m2.style.textDecoration = "none";
}
if (m3.href == url){
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (m4.href == url){
m4.style.color = "#ffc12b";
m4.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m4.style.textDecoration = "none";
}
if (m5.href == url || url.href.indexOf(m5.href)!=-1){
m5.style.color = "#ffc12b";
m5.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg2.png)no-repeat center center";
m5.style.textDecoration = "none";
}
if (url.href.indexOf(mm1.href)!=-1){
mm1.style.color = "#741f0c";
mm1.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm2.href)!=-1){
mm2.style.color = "#741f0c";
mm2.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm3.href)!=-1){
mm3.style.color = "#741f0c";
mm3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm4.href)!=-1){
mm4.style.color = "#741f0c";
mm4.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm5.href)!=-1){
mm5.style.color = "#741f0c";
mm5.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm6.href)!=-1){
mm6.style.color = "#741f0c";
mm6.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm7.href)!=-1){
mm7.style.color = "#741f0c";
mm7.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
if (url.href.indexOf(mm8.href)!=-1){
mm8.style.color = "#741f0c";
mm8.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
m3.style.color = "#ffc12b";
m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
m3.style.textDecoration = "none";
}
}
Пришел проект на поддержку... Сразу отказался=)
Естественно вкрапления %_some_text_% от меня.
Файл назывался main-menu-hover.js
+161
var percent = 0;
setInterval(function() {
if(percent < 100) {
percent += 10;
showprogress(percent);
}
}, 50);
Прогресс-бар асинхронной загрузки картинки
+161
function FindPosOfStr(str1, str2) {
for (i = 0; i <= str1.length; i++) {
comp = str1.substring(i, str1.length);
comp = comp.substring(0, str2.length);
if (comp == str2) {
return i;
break;
}
}
return -1;
}
Вот такое вот веселье встретилось в одном проекте. Кто-то был сильно пьян и забыл про indexOf