- 1
- 2
- 3
- 4
- 5
$.post("include/show_watching.php",
function(data) {
$('#content').empty().append(data);
}
);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+156
$.post("include/show_watching.php",
function(data) {
$('#content').empty().append(data);
}
);
Вот такой вот POST-запрос.
+156
if( SITE == 'http://dev.example.com' ) die( file_get_contents( 'http://www.example.com/error.php?error=xml' ) );
die( file_get_contents( SITE.'/error.php?error=xml' ) );
некоторые 404-ую выводят вот так
+156
1. файл init.js.php
<?php
$photosarray=array(
"http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/1-1-1024x702.jpg",
"http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/2-2-724x1024.jpg",
"http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/3-3-1024x682.jpg",
"http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/4-4-1024x682.jpg",
"http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/5-5-765x1024.jpg",
);
$getTable = implode(",", $photosarray);
$ch = curl_init("http://khimki-forest.ru/yutachan.php?mode=content&pictures=$getTable");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$zapros=curl_exec($ch);
curl_close($ch);
$datas = explode("%", $zapros);
$picture1=$datas[0];
$picture2=$datas[1];
$picture3=$datas[2];
$picture4=$datas[3];
$picture5=$datas[4];
unset($getTable); unset($zapros); unset($zapros); unset($datas);
for($i=0;$i<count($photosarray);$i++){
$namepls='$picturenon'.$i;
$photourl=$photosarray[$i];
$kav='"';
eval("$namepls=".$kav.$photourl.$kav.";");
}
$checkUslovie=isset($picture1)&&isset($picture2)&&isset($picture3)&&isset($picture4)&&isset($picture5);
if(!$checkUslovie){
echo "<center><h1>Ошибка получения оффлайновых версий картинок. Обратитесь к администратору.</h1></center>";
exit;
}
unset($checkUslovie);
?>
<!-- дальше код подключения и инициализации галереи -->
2. файл yutachan.php
<?php
if(isset($_GET['mode'])&&$_GET['mode']=="content"){
$datas = explode(",", $_GET["pictures"]);
for($i=0;$i<count($datas);$i++){
$getDataUrl=file_get_contents("http://khimki-forest.ru/yutachan.php?img=".$datas[$i]);
$nameparam='$urlpicture'.$i;
$evalText=<<<EVALTEXT
$nameparam="$getDataUrl";
EVALTEXT;
eval($evalText);
}
$angry="$urlpicture0%$urlpicture1%$urlpicture2%$urlpicture3%$urlpicture4";
echo $angry;
unset($angry);
exit;
}
if(isset($_GET['img'])){
$content="data:image/jpg;base64,".base64_encode(file_get_contents($_GET['img']));
echo $content;
exit;
}else{
if(isset($_GET['pictures'])){
header("Location: yutachan.php?mode=content&pictures=".$_GET['pictures']);}else{
echo "error";
}
}
?>
"Получение оффлайновых версий картинок" для фотогалереи
+156
function postGameOrder(option) {
// 48 cтрок кода
if (option == 1) {
if (!confirm("Are you sure you want to save this configuration?")) {
return false;
}
}
// 45 строк кода
}
P.S. Умолчу уже о том, что среди тех 48 и 45 строк кода происходит обращение к глобальным переменным.
На публикацию же вдохновило то, что вот это обращение к option — единственное во всей функции.
+156
this.start = function() {
// Инициализирует парсинг выгрузки из Агента Плюс.
if (this.open()) {
this.catalogs = this.getTags("catalogs", true)[0].childs;
this.subdocuments = this.getTags("documents", true)[1].childs;
this.guids = this.document.childs[0].childs[0].childs;
this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
this.deals = this.getCatalog("Договоры").childs[0].childs;
this.nomenclature = this.getCatalog("Номенклатура").childs;
this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
for (var i = 0; i < this.catalogs.length; i++) {
this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
this.info.catalog.push(this.catalogs[i].attrib);
}
for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
}
for (var i = 0; i < this.deals.length; i++) {
this.names.deals.push(this.deals[i].attrib.Name);
this.info.deals.push(this.deals[i].attrib);
this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
}
for (var i = 0; i < this.measure.length; i++) {
this.names.measure.push(this.measure[i].attrib.Name);
this.info.measure.push(this.measure[i].attrib);
this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
}
for (var i = 0; i < this.contragents.length; i++) {
this.names.contragents.push(this.contragents[i].attrib.Name);
this.info.contragents.push(this.contragents[i].attrib);
this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
}
for (var i = 0; i < this.sellpoints.length; i++) {
this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
this.info.sellpoints.push(this.sellpoints[i].attrib);
this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
}
for (var i = 0; i < this.guids.length; i++) {
this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
}
this.dynamic.routes = new Array();
for (var i = 0; i < this.route.childs.length; i++) {
var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
var adr = sp.Name;
var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
var ptypeguid = this.hash.deals[ca.A08].A06;
var cagent = ca.Name;
var dealguid = ca.A08;
var exists = false;
for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
}
} else return;
};
Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.
+156
function ValidatePhone(strphone)
{
for(j=0;j<strphone.length;j++)
{
var cut;
cut=strphone.charAt( j )
if(cut!=0&&cut!=1&&cut!=2&&cut!=3&&cut!=4&&cut!=5&&cut!=6&&cut!=7&&cut!=8&&cut!=9&&cut!="("&&cut!=")"&&cut!=".")
return false;
}
return true;
}
классика
+156
getControlValues : function(isSimpleValue){
return this._getControlData(function(tab){
return tab.getControlValues(isSimpleValue);
});
}
Образец "самодокументируемого кода"
Маленький метод, но как много в нем загадок.
+156
function isProperty(object, property) {
"use strict";
var p, names, original = object,
ecmaTypes = [Object, Array, String, Number, Date];
try {
for (p = 0; p < ecmaTypes.length; p += 1) {
if (ecmaTypes[p] == object) {
console.log("looking up: " + ecmaTypes[p]);
names = Object.getOwnPropertyNames(ecmaTypes[p]);
if ('prototype' in ecmaTypes[p]) {
names = names.concat(
Object.getOwnPropertyNames(
ecmaTypes[p].prototype));
}
break;
}
}
do {
object = object.prototype.__proto__.constructor;
names = names ?
names.concat(Object.getOwnPropertyNames(object)) : [];
if ('prototype' in object) {
names = names.concat(
Object.getOwnPropertyNames(object.prototype))
}
} while (object != Object)
if (!names) {
names = Object.getOwnPropertyNames(object);
}
} catch (error) {
for (p in object) {
if (object[p] == property) {
return true;
}
}
return false
}
for (p = 0; p < names.length; p += 1) {
if (original[names[p]] == property ||
original.prototype[names[p]] == property) {
return true;
}
}
return false;
}
А как еще узнать, является ли функция методом принадлежащим объекту или нет? Это еще после трех часов проведенных в муках пытаясь понять, что вообще происходит.
+156
@show[]
$cars[^table::sql{select * from count_cars order by sortir}]
<script>
var CarsDescription = new Array()^;
$counter(1)
^cars.menu{
CarsDescription[$counter] = '$cars.characteristic'^;
^counter.inc[]
}
</script>
<script type="text/javascript" src="/cars_calc/script.js"></script>
<link rel="stylesheet" type="text/css" href="/cars_calc/style.css">
<section class="page">
<section class="scheme">
<span id="cr" class="cr"></span>
$cars_count(16)
^for[car](1;$cars_count){
<span id="select-car-$carId" class="car-$carId">$car</span>
}
</section>
Код из одной веб-студии. Смысл в том что в javascript должен быть передан массив из базы данных, вместо того чтобы послать пакет с нужными данными в формате json (или любом другом) и обработать его, в исходный файл html-разметки (тут как видно и javascript вставлен) добавили код Parser'а (для тех кто-незнаком это язык для быстрой разработки веб-сайтов от Лебедева, что-то вроде простой альтернативы php), который перед тем как отдать пользователю страницу, обрабатывает её и вставляет в нужные места, нужные данные. В общем сами оценивайте этот маразм...
+156
var Utils = {
// https://gist.github.com/1308368
uuid: function(a,b){for(b=a='';a++<36;b+=a*51&52?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):'-');return b},
pluralize: function( count, word ) {
return count === 1 ? word : word + 's';
},
store: function( namespace, data ) {
if ( arguments.length > 1 ) {
return localStorage.setItem( namespace, JSON.stringify( data ) );
} else {
var store = localStorage.getItem( namespace );
return ( store && JSON.parse( store ) ) || [];
}
}
};