- 1
- 2
- 3
- 4
- 5
- 6
- 7
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*.govnokod.ru")) {
return "PROXY 178.63.104.146:80";
}
return "DIRECT";
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+154
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*.govnokod.ru")) {
return "PROXY 178.63.104.146:80";
}
return "DIRECT";
}
Навеяно прочтением статьи http://en.wikipedia.org/wiki/Proxy_auto-config
+10
int ScriptArrow;
...
// проверим а есть ли в натуре скрипт по этому указателю
try
{
RunScript = (Script*)ScriptArrow;
RunScript->Script.ArrVar.count();
}
catch (...)
{
RunScript = NULL;
}
Проверка, в натуре. Авторский комментарий сохранен :)
−98
rows = db.query_all("select id, command from всякие-заджойненные-таблички")
foreach row in rows:
if row[1] == command:
return row[0]
return None
Высрал сегодня на работе. Пока пых не трогал - такого говна не писал ;)
+22
printf("Куда все подевались? Ни одного коммента за два дня...\n");
+161
/*
* Calculates date for $count_days before today
*
* @param int $count_days - how much days before today
* @return date - date for $count_days before today
*/
function DaysBeforeToday($count_days) {
$date = date('Y-m-d');
$pos = strrpos($date, '-');
$date = substr($date, 0, $pos + 1) . (substr($date, $pos + 1, 2) - $count_days);
return $date;
}
ня! ^^
+72
String isFeatureEnabled = object.get("featureEnabledParam");
boolean featureEnabled = app.isFeatureEnabled();
if (Boolean.parseBoolean(isFeatureEnabled) && !featureEnabled) {
return false;
}
if (!Boolean.parseBoolean(isFeatureEnabled) && featureEnabled)
{
return false;
}
+168
// ==UserScript==
// @name no horses
// @match *://govnokod.ru/*
// @grant none
// @run-at document-start
// ==/UserScript==
var CONFIG = {
horses: [
"Horse2",
"PragramistOtBoga",
"anonimb84a2f6fd141",
],
autoDownVote: true,
};
var observer = new MutationObserver(observeCallback);
var config = {
childList: true,
subtree: true,
};
observer.observe(document, config);
function observeCallback(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
Array.prototype.forEach.call(mutation.addedNodes, function(node) {
try {
if (node.nodeType === 1 && /^comments_\d+$/.test(node.id)) {
handleComments(node);
}
} catch (e) {
console && console.warn && console.warn(e);
}
});
}
});
}
function downVote(node, type) {
var sel;
switch (type) {
case "post": sel = ".vote-against"; break;
case "comment": sel = ".comment-vote-against"; break;
default: throw 42; break;
}
var el = node.querySelector(sel);
if (el) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, unsafeWindow,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
}
function handleComments(node) {
var comments = node.querySelectorAll(".entry-comment-wrapper");
Array.prototype.forEach.call(comments, function(comment) {
try {
handleComment(comment);
} catch (e) {
console && console.warn && console.warn(e);
}
});
}
function handleComment(node) {
var author = node.querySelector(".entry-author").textContent.trim();
if (CONFIG.horses.indexOf(author) != -1) {
node.style.opacity = 0.3;
node.style.maxHeight = "4em";
node.style.overflow = "scroll";
if (CONFIG.autoDownVote) {
downVote(node, "comment");
}
}
}
function handlePosts(node) {
var posts = node.querySelectorAll(".hentry");
var i;
for (i = 0; i < posts.length; i++) {
try {
handlePost(posts[i]);
} catch (e) {
console && console.warn && console.warn(e);
}
}
}
function handlePost(node) {
var author = node.querySelector(".author a:nth-child(2)").textContent.trim();
if (CONFIG.horses.indexOf(author) != -1) {
if (!/^\/\d+$/.test(document.location.pathname)) {
node.style.opacity = 0.3;
node.style.maxHeight = "4em";
node.style.overflow = "scroll";
}
if (CONFIG.autoDownVote) {
downVote(node, "post");
}
}
}
document.addEventListener("DOMContentLoaded", function() {
handleComments(document.body);
handlePosts(document.body);
});
Я так и не смог заставить MutationObserver срабатывать на новые элементы, появляющиеся во время загрузки страницы. Отсюда и костыль в последних строчках.
+155
function printNumbersTimeout20_100() {
var i = 1;
var timerId = setTimeout(function go() {
console.log(i);
if (i < 20) setTimeout(go, 100);
i++;
}, 100);
}
// вызов
printNumbersTimeout20_100();
Вывод чисел каждые 100мс, через setTimeout
Сделайте то же самое, что в задаче "Вывод чисел каждые 100мс", но с использованием setTimeout вместо setInterval.
http://learn.javascript.ru/task/vyvod-chisel-kazhdye-100ms-cherez-settimeout
+156
function date_to_text($date){
$now=time();
if ($s=strtotime($date)) //the function returns false is $date is not a string (as already in numeric unix date format)
$date = $s;
$d=round(($now-$date)); //s
//echo $d;
if($d>60){
$d=$d/60;//m
if($d>60){
$d=$d/60;//h
if($d>24){
$d=$d/24;//d
if($d>7){
$d=$d/7;//w
if($d>(52/12)){
$d=$d/52*12;//m
if($d>12){
$d=$d/12;//y
$d=floor($d);
$str=$d.' year'.(($d>1)?'s':'');
}else{
$d=floor($d);
$str=$d.' month'.(($d>1)?'s':'');
}
}else{
$d=floor($d);
$str=$d.' wk'.($d>1?'s':'');
}
}else{
$d=floor($d);
$str=$d.' day'.($d>1?'s':'');
}
}else{
$d=floor($d);
$str=$d.' hr'.(($d>1)?'s':'');
}
}else{
$d=floor($d);
$str=$d.' min'.(($d>1)?'s':'');
}
}elseif ($d>0) {
$d=floor($d);
$str=$d.' sec'.(($d>1)?'s':'');
}
if ($d>0){
$str.=' ago';
} else {
$str = '';
}
return $str;
}
неопiсуемо
+100
ТРАЛИ ПАБЕДЕЛИ ВАМ НЕАТКУДАВА ЖДАТЬ ПОМАЩИ ЛАЛКИ ИБАНЫЕЙЕ АЗАЗААЗХАЗХЗАХВАХВЩАХВЩАВА