- 1
Я заебался жать на рефреш весь долбанный день со всех устройств, чтобы запостить гет
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+146
Я заебался жать на рефреш весь долбанный день со всех устройств, чтобы запостить гет
−113
public override function match(xdoc:XML):Boolean {
var newsearch:String = search;
var xpathnodes:Array = new Array();
while(true) {
var xpathnode:String = splitnodes.exec(newsearch);
if(xpathnode) {
xpathnodes.push(xpathnode);
} else {
break;
}
newsearch = newsearch.substring(newsearch.search(xpathnode) + xpathnode.length);
}
return matchXPath(xpathnodes, xdoc);
}
Фантастическая реализация String.split() за тем же авторством. :)
+156
$varians_ids = array();
$getvaluesvariants=mysql_query("SELECT `id` FROM `values` group by `id`") or die(mysql_error());;
while($valuesvariants = mysql_fetch_array($getvaluesvariants, MYSQL_ASSOC))
{
$varians_ids[]= $valuesvariants['id'];
}
mysql_free_result($getvaluesvariants)or die("Query failed: " . mysql_error());
for ($i = 0; $i < count($varians_ids); $i++)
{
$setvaluesnames = mysql_query("UPDATE `option_values` SET `option_value_ru` = (SELECT `option_value_ru` FROM `values` WHERE `id` = '$varians_ids[$i]') WHERE `id` = '$varians_ids[$i]'") or die(mysql_error());;
}
Наткнулся на этот шедевр. Отсутствие использования foreach кажется мелочью по сравнению с тем, как производится операция, которую можно сделать одним запросом:
$setvaluesnames = mysql_query("UPDATE `option_values`, `values`
SET
`option_values`.`option_value_ru` = `values`.`option_value_ru`
WHERE `option_values`.`id` = `values`.`id`") or die(mysql_error());
P. S.: там еще в БД пишется пробел вместо пустой строки или NULL...
+163
<?
if (!(empty($_GET['set_cpulinks'])))
{
echo set_cpulinks();
unset($_GET);
}
if (!(empty($_GET['change_page'])))
{
if (file_exists('inc/templates/change_page.inc'))
{
include ('inc/templates/change_page.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['search_str'])))
{
if (file_exists('inc/templates/search_'.$lang_prefix.'.inc'))
{
include ('inc/templates/search_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['adv_search_str'])))
{
if (file_exists('inc/templates/adv_search_'.$lang_prefix.'.inc'))
{
include ('inc/templates/adv_search_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['rss'])))
{
if (file_exists('inc/templates/rss_'.$lang_prefix.'.inc'))
{
include ('inc/templates/rss_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if ($_GET['business'] == 1)
{
if (file_exists('inc/templates/main_business_'.$lang_prefix.'.inc'))
{
include ('inc/templates/main_business_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if ($_GET['business'] == 2)
{
if (file_exists('inc/templates/current_business_'.$lang_prefix.'.inc'))
{
include ('inc/templates/current_business_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['business_full'])))
{
if (file_exists('inc/business/business_'.$_GET['business_full'].'.inc'))
{
include ('inc/business/business_'.$_GET['business_full'].'.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['new_add'])))
{
if (file_exists('inc/templates/new_add_'.$lang_prefix.'.inc'))
{
include ('inc/templates/new_add_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
if (!(empty($_GET['section_id'])))
{
if (file_exists('inc/templates/main_section_'.$lang_prefix.'.inc'))
{
include ('inc/templates/main_section_'.$lang_prefix.'.inc');
}
else
header ("Location: /index.php");
}
else
{
if (file_exists('inc/templates/main_'.$lang_prefix.'.inc'))
Продолжаю выкладывать интересные перлы. Тут была попытка сделать ЧПУ и шаблонную структуру
Зы ЧПУ не работает)))
+147
#include <iostream>
#include <cmath>
using namespace std;
#define EXIT 10
#define CMATRIX_ROW_SIZE 2
#define CMATRIX_COL_SIZE 2
class Matrix
{
float M[CMATRIX_ROW_SIZE][CMATRIX_COL_SIZE];
public:
Matrix(){
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
M[i][j]=0;
}
}
}
Matrix(const Matrix &m){
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
this->M[i][j]=m.M[i][j];
}
}
}
Matrix(float a_11,float a_12,float a_21,float a_22){
this->M[0][0]=a_11;
this->M[0][1]=a_12;
this->M[1][0]=a_21;
this->M[1][1]=a_22;
}
void print()const{cout<<" ("<<M[0][0]<<" "<<M[0][1]<<")\n"<<" ("<<M[1][0]<<" "<<M[1][1]<<")"<<endl;}
float determinant()const{return (M[0][0]*M[1][1] - M[0][1]*M[1][0]);}
bool compare(Matrix &m1,Matrix &m2)const{return (m1==m2) ? true : false;}
template <class Matrix> float get_ij (Matrix &m,int i,int j){
if( (i>=0 && i<CMATRIX_ROW_SIZE) && (j>=0 && j<CMATRIX_COL_SIZE ) ) return m.M[i][j];
else return 0;
}
template <class Matrix> void set_ij (Matrix &m,int i,int j,float setter){
if( (i>=0 && i<CMATRIX_ROW_SIZE) && (j>=0 && j<CMATRIX_COL_SIZE ) ) this->M[i][j]=setter;
}
friend istream &operator >>(istream &in,Matrix &m){
cout<<" Input [i][j]"<<endl;
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
in>>m.M[i][j];
}
}
return in;
}
friend Matrix operator * (const Matrix &m,int degree){
if(degree>0){
Matrix temp;
for(int k=0;k<degree-1;k++){
temp.M[0][0] = temp.M[0][0] + m.M[0][0]*m.M[0][0] + m.M[0][1]*m.M[1][0];
temp.M[0][1] = temp.M[0][1] + m.M[0][0]*m.M[0][1] + m.M[0][1]*m.M[1][1];
temp.M[1][0] = temp.M[1][0] + m.M[1][0]*m.M[0][0] + m.M[1][1]*m.M[1][0];
temp.M[1][1] = temp.M[1][1] + m.M[1][0]*m.M[0][1] + m.M[1][1]*m.M[1][1];
}
return temp;}
else if(degree==0){
Matrix temp(1,0,0,1);
return temp;}
else {
Matrix temp;
return temp;
}
}
friend Matrix operator * (float lambda,const Matrix &m){
Matrix temp;
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
temp.M[i][j] = lambda*m.M[i][j];
}
}
return temp;}
Matrix operator * (const Matrix &m){
Matrix temp;
temp.M[0][0] = temp.M[0][0] + M[0][0]*m.M[0][0] + M[0][1]*m.M[1][0];
temp.M[0][1] = temp.M[0][1] + M[0][0]*m.M[0][1] + M[0][1]*m.M[1][1];
temp.M[1][0] = temp.M[1][0] + M[1][0]*m.M[0][0] + M[1][1]*m.M[1][0];
temp.M[1][1] = temp.M[1][1] + M[1][0]*m.M[0][1] + M[1][1]*m.M[1][1];
return temp;}
Matrix operator + (const Matrix &m){
Matrix temp;
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
temp.M[i][j] = M[i][j] + m.M[i][j];
}
}
return temp;}
bool operator == (const Matrix &m){
bool flag;
for(int i=0;i<CMATRIX_ROW_SIZE;i++){
for(int j=0;j<CMATRIX_COL_SIZE;j++){
flag = (M[i][j]==m.M[i][j]) ? true : false;
}
}
return temp;
}
};
Простите ради Бога за лабу. Просто очень хочется узнать мнение общественности. Заранее спасибо, за любую оценку!
+166
//Анти - XSS
function antixss() {
//Запрещенные элементы
$array = array('./' , '../' , '\'' , '<script>' , 'document.cookie' , '</script>' );
//GET
$query = $_GET;
if( sizeof($query) ) {
foreach($query AS $arr => $value) {
$clear_xss = str_replace($array , '[xss]' , $value);
$_GET[$arr] = $clear_xss;
}
}
//GET
$query = $_POST;
if( sizeof($query) ) {
foreach($query AS $arr => $value) {
$clear_xss = str_replace($array , '[xss]' , $value);
$_POST[$arr] = $clear_xss;
}
}
return true;
}
Наконец-то школьники придумали средство от XSS.
* BY LiteTracker Source
−92
-- async IO operations
-- op1.asyncRun(cb) - execute op1, and call cb(op1_result) after op1 completion
-- op1 * g - new async operation which will execute op1.asyncRun(), then execute g(op1_result).asyncRun() and return op2_result
-- op1 .. op2 - the same, but ignore result of op1. Will execute op1.asyncRun(), then op2.asyncRun() and return op2_result
private.binder = {
__mul =
function(op1, g)
local op = {
asyncRun =
function(cb)
op1.asyncRun(
function(op1_result)
g(op1_result).asyncRun(cb)
end
)
end
}
setmetatable(op, private.binder)
return op
end,
__concat =
function(op1, op2)
return op1 * function(op1_result) return op2 end
end,
__metatable = 1
}
-- примеры использования:
-- (Chatter.IO.Log("tic") .. Chatter.IO.Sleep(1000) .. Chatter.IO.Log("tac") .. Chatter.IO.Sleep(1000) .. Chatter.IO.Log("toe")).asyncRun(function() end)
-- (Chatter.IO.GetTime * Chatter.IO.Log .. Chatter.IO.Sleep(1000) .. Chatter.IO.GetTime * Chatter.IO.Log).asyncRun(function() end)
Lua.
+154
function AdminMain()
{
global $config, $user, $site, $db; // $user, $site и $db используются в подпрограммах.
if(isset($_GET['exe']) && $_GET['exe'] == 'exit'){
$user->UnsetCookie('admin');
GO(Ufu('index.php'));
}elseif(!isset($_GET['exe'])){
$exe = 'adminpanel';
}else{
...
}
из LinkorCMS...
+158
$y=date("Y"); $m=date("n"); $d=date("d");
if($d>1) {$d1=$d-1; $m1=$m; $y1=$y;}
if($d==1 && $m>1) {$d1=date('t',mktime(0, 0, 0, $m-1, 1, $y)); $m1=$m-1; $y1=$y;}
if($d==1 && $m==1) {$d1=date('t',mktime(0, 0, 0, 12, 1, $y)); $m1=12; $y1=$y-1;}
echo "Вчера - $d1.$m1.$y1";
if($d>2) {$d2=$d-2; $m2=$m; $y2=$y;}
if($d==2 && $m>1) {$d2=date('t',mktime(0, 0, 0, $m-1, 1, $y)); $m2=$m-1; $y2=$y;}
if($d==2 && $m==1) {$d2=31; $m2=12; $y2=$y-1;}
if($d==1 && $m>1) {$d2=date('t',mktime(0, 0, 0, $m-1, 1, $y))-1; $m2=$m-1; $y2=$y;}
if($d==1 && $m==1) {$d2=30; $m2=12; $y2=$y-1;}
echo "Позавчера - $d2.$m2.$y2";
Решение в лоб - зато полностью рабочее. Обнаружил в собственном проекте (вполне действующем).
+160
/*
* Быстрая навигация
*/
if(isset($url[1]))
{
if(isset($component_array[$url[1]]))
{
if(isset($component_array[$url[1]]['subAct']))
{
foreach($component_array[$url[1]]['subAct'] as $comAct => $comActLink)
{
$subNav .= '<span' . ((isset($url[2]) && $url[2] == $comActLink OR !isset($url[2]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/' . $url[1] . '/' . $comActLink . '">' . $comAct . '</a></span>';
}
}
$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/' . $url[1] . '">' . $component_array[$url[1]]['name'] . '</a></span>';
}
elseif(isset($url[2]) && isset($module_array[$url[2]]))
{
if(isset($module_array[$url[2]]['subAct']))
{
foreach($module_array[$url[2]]['subAct'] as $comAct => $comActLink)
{
$subNav .= '<span' . ((isset($url[3]) && $url[3] == $comActLink OR !isset($url[3]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/module/' . $url[2] . '/' . $comActLink . '">' . $comAct . '</a></span>';
}
}
$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/module/' . $url[2] . '">' . $module_array[$url[2]]['name'] . '</a></span>';
}
elseif(isset($services_array[$url[1]]))
{
if(isset($services_array[$url[1]]['subAct']))
{
foreach($services_array[$url[1]]['subAct'] as $comAct => $comActLink)
{
$subNav .= '<span' . ((isset($url[2]) && $url[2] == $comActLink OR !isset($url[2]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/' . $url[1] . '/' . $comActLink . '">' . $comAct . '</a></span>';
}
}
$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/' . $url[1] . '">' . $services_array[$url[1]]['name'] . '</a></span>';
}
}
Кусок из Toogle CMS.
facepalm.