- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
if(true)
{
//Код
}
else
{
//Закомментированно, но компилируется. ^_^
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+138.2
if(true)
{
//Код
}
else
{
//Закомментированно, но компилируется. ^_^
};
Способ комментирования... O_o
+84
char* c=a;
char* d=b;
while(*(c++)=*(d++));
Кажется страус труп предложил. Копирование из буфера PChar b в буфер PChar a.
+153
<?
ob_start();
session_start();
include("includes/applicationTop.php");
?>
<?
if($_SESSION["CONTACT_ID"]=="" || $_SESSION["CONTACT_ID"]==0)
{
$contact_id=$_GET['contact_id'];
}
else
{
$contact_id = $_SESSION["CONTACT_ID"];
}
if($_SESSION["ORDER_ID"]=="" || $_SESSION["ORDER_ID"]==0)
{
$order_id=$_GET['order_id'];
}
else
{
$order_id = $_SESSION["ORDER_ID"];
}
$selBillingInfo = "SELECT * FROM `contact` WHERE `contact_id`='".$contact_id."'";
$resBillingInfo = $db->select_data($selBillingInfo);
$selOrderInfo = "SELECT * FROM `order` WHERE `order_id`='".$order_id."'";
$resOrderInfo = $db->select_data($selOrderInfo);
?>
<? $exesql=mysql_query("select * from admin_updation where id = 1");
$rs=mysql_fetch_object($exesql); $to_mail=$rs->paypal_id;?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30"><img src="images/spacer.gif" width="30" height="1" /></td>
<td><form class="formclass" method="post" action="https://www.paypal.com/cgi-bin/webscr" id="myform" name="theForm" ><!--<form class="formclass" method="post" action="https://www.paypal.com/cgi-bin/webscr" id="myform" name="theForm" >-->
<input name="validate" value="1" type="hidden">
<input type="hidden" name="order_id" value="<?=$order_id?>" />
<?
$paypal[site_url]="http://говносайт";
$paypal[success_url]="/paymentReceipt.php?success=paypal&pt=paypal&contact_id=$contact_id&order_id=$order_id";
$paypal[cancel_url]="/paymentReceipt.php?success=failed&pt=paypal&contact_id=$contact_id&order_id=$order_id";
$paypal[notify_url]="/ipn/ipn.php";
$paypal[return_method]="2"; //1=GET 2=POST
$paypal[currency_code]="USD"; //[USD,GBP,JPY,CAD,EUR]
$paypal[lc]="US";
$paypal[url]="https://www.sandbox.paypal.com/cgi-bin/webscr"; // For Test
$paypal[post_method]="fso"; //fso=fsockopen(); curl=curl command line libCurl=php compiled with libCurl support
$paypal[curl_location]="/usr/local/bin/curl";
$paypal[bn]="toolkit-php";
$paypal[cmd]="_xclick";
$paypal[display_comment]="0"; //0=yes 1=no
$paypal[comment_header]="Comments";
$paypal[continue_button_text]="Continue >>";
$paypal[background_color]="1"; //""=white 1=black
$paypal[display_shipping_address]="1"; //""=yes 1=no
$paypal[display_comment]="1"; //""=yes 1=no
?>
<!--<input type="hidden" name="business" value="[email protected]">--><? // For Live ?>
<input type="hidden" name="business" value="<?=$to_mail?>"><? // For Test ?>
<!--<input type="hidden" name="business" value="[email protected]">--><? // For Test ?>
<input type="hidden" name="item_name" value="Говнобрэнд">
<input type="hidden" name="cmd" value="<?=$paypal[cmd]?>">
<input type="hidden" name="redirect_cmd" value="<?=$paypal[cmd]?>">
<input type="hidden" name="image_url" value="">
<input type="hidden" name="return" value="<? echo "$paypal[site_url]$paypal[success_url]"; ?>">
<input type="hidden" name="cancel_return" value="<? echo "$paypal[site_url]$paypal[cancel_url]"; ?>">
<input type="hidden" name="notify_url" value="<? echo "$paypal[site_url]$paypal[notify_url]"; ?>">
<input type="hidden" name="rm" value="<?=$paypal[return_method]?>">
<input type="hidden" name="currency_code" value="<?=$paypal[currency_code]?>">
<input type="hidden" name="lc" value="<?=$paypal[lc]?>"><input type="hidden" name="bn" value="<?=$paypal[bn]?>">
<input type="hidden" name="cbt" value="<?=$paypal[continue_button_text]?>"><input type="hidden" name="no_shipping" value="<?=$paypal[display_shipping_address]?>">
<input type="hidden" name="no_note" value="<?=$paypal[display_comment]?>">
<input type="hidden" name="order_id" value="<?=$order_id?>"><input type="hidden" name="amount" value="<?=$resOrderInfo[0]['amount']?>">
<input type="hidden" name="first_name" value="<?=$resBillingInfo[0]['first_name']?>"> <input type="hidden" name="last_name" value="<?=$resBillingInfo[0]['last_name']?>">
<input type="hidden" name="company" value="<?=$resBillingInfo[0]['company']?>"><input type="hidden" name="address" value="<?=$resBillingInfo[0]['address']?>">
<input type="hidden" name="city" value="<?=$resBillingInfo[0]['city']?>"><input type="hidden" name="state" value="<?=$resBillingInfo[0]['state']?>">
<input type="hidden" name="zip" value="<?=$resBillingInfo[0]['zip']?>">
<input type="hidden" name="country" value="<?=$resBillingInfo[0]['country']?>">
<input type="hidden" name="phone" value="<?=$resBillingInfo[0]['phone']?>"> <input type="hidden" name="email " value="<?=$resBillingInfo[0]['email']?>"> <input type="hidden" name="a3" value="<?=$resOrderInfo[0]['amount']?>">
<input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="no_note" value="1">
<input type="hidden" name="src" value="1"><input type="hidden" name="sra" value="1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="text_body"> </td>
</tr>
<tr>
<td align="left"></td>
</tr>
</table>
</form></td>
<td width="15"><img src="images/spacer.gif" width="15" height="1" /></td>
</tr>
</table>
<script language="JavaScript">
objfrm = document.getElementById("myform");
objfrm.submit();
</script>
А вот занятный способ переброса посетителя на paypal.
С помощью невидимой формы, который сама засабмитится (может быть).
Источник тот же, что у #1244-#1245, #1248-#1250
+46.7
$t = new Table('foo');
$t->th('Header 1');
$t->th('Header 2');
$t->th('Header 3');
$t->endRow();
for($i = 0; $i<10; $i++) {
$t->td('Cell 1');
$t->td('Cell <2>', '', true);
$t->td('Cell 3');
$t->endRow();
}
$t->end();
На выходе получаем html таблицы...
Вот так крутые пацаны понимают термин OOP,
http://habrahabr.ru/sandbox/3112/ человек хочет за изобретение инвайт, ссылка по видимому умрет, так что инвайт дарите быстрее, если шедевр вас тронул :)
+60.3
function fromunicode($string,$lang){
if ($lang=="fr"):
return utf8_decode($string);
elseif($lang=="rus"):
$tempchar1=chr(208);
$string=ereg_replace( "Рђ" , "А" , $string);
$tempchar2=chr(145);
$tempchar=$tempchar1.$tempchar2;
$string=ereg_replace( $tempchar , "Б" , $string);
$tempchar2=chr( 146);
$tempchar=$tempchar1.$tempchar2;
$string=ereg_replace( $tempchar, "В" , $string);
$tempchar2=chr( 147);
$tempchar=$tempchar1.$tempchar2;
$string=ereg_replace( $tempchar ,"Г" , $string);
$tempchar2=chr( 148);
$tempchar=$tempchar1.$tempchar2;
$string=ereg_replace( $tempchar, "Д" , $string);
$string=ereg_replace( "Р•" , "Е" , $string);
$string=ereg_replace( "РЃ" ,"Ё" , $string);
$string=ereg_replace( "Р–" , "Ж" , $string);
$string=ereg_replace( "Р—" , "З" , $string);
$string=ereg_replace( "Р?" , "И" , $string);
$string=ereg_replace( "Р™" , "Й" , $string);
$string=ereg_replace( "Рљ" , "К" , $string);
$string=ereg_replace( "Р›" , "Л" , $string);
$string=ereg_replace( "Рњ" , "М" , $string);
$string=ereg_replace( "Рќ" , "Н" , $string);
$string=ereg_replace( "Рћ" , "О" , $string);
$string=ereg_replace( "Рџ" , "П" , $string);
//$string=ereg_replace( "Р" , "Р " , $string);
//$string=ereg_replace( "С" , "РЎ" , $string);
$string=ereg_replace( "Рў" , "Т" , $string);
$string=ereg_replace( "РЈ" , "У" , $string);
$string=ereg_replace( "Р¤" , "Ф" , $string);
$string=ereg_replace("РҐ" , "Х" , $string);
$string=ereg_replace( "Р¦" , "Ц" , $string);
$string=ereg_replace( "Р§" , "Ч" , $string);
$string=ereg_replace( "РЁ" , "Ш" , $string);
$string=ereg_replace( "Р©" , "Щ" , $string);
$string=ereg_replace( "Р¬" , "Ь" , $string);
$tempchar2=chr( 170);
$tempchar=$tempchar1.$tempchar2;
$string=ereg_replace( $tempchar,"Ъ" , $string);
//echo "tempmygk=$tempchar";
$tempchar2=chr( 171);
$tempchar=$tempchar1.$tempchar2;
// $string=ereg_replace( $tempchar3,$tempchar, $string);
$string=ereg_replace( $tempchar,"Ы" , $string);
//echo "tempy=$tempchar";
$string=ereg_replace("Р" , "Э" , $string);
$string=ereg_replace( "Р®" , "Ю" , $string);
$string=ereg_replace( "РЇ" , "Я" , $string);
// small
$string=ereg_replace( "Р°" ,"а" , $string);
$string=ereg_replace( "Р±" ,"б" , $string);
$string=ereg_replace( "РІ" ,"в" , $string);
$string=ereg_replace( "Рі" ,"г" , $string);
$string=ereg_replace( "Рґ" , "д" , $string);
$string=ereg_replace( "Рµ" ,"е" , $string);
$string=ereg_replace( "Рµ" ,"ё" , $string);
// $string=ereg_replace( "С'" , "ё" , $string);
$string=ereg_replace( "Р¶" , "ж" , $string);
$string=ereg_replace( "Р·" , "з" , $string);
$string=ereg_replace( "Рё" ,"и" , $string);
$string=ereg_replace( "Р№" ,"й" , $string);
$string=ereg_replace("Рє" , "к" , $string);
$string=ereg_replace( "Р»" , "л" , $string);
$string=ereg_replace( "Рј" , "м" , $string);
$string=ereg_replace( "РЅ" , "н" , $string);
$string=ereg_replace( "Рѕ" , "о" , $string);
$string=ereg_replace("Рї" , "п" , $string);
$string=ereg_replace("СЂ" , "р" , $string);
$string=ereg_replace("СЃ" , "с" , $string);
$string=ereg_replace( "С‚" , "т" , $string);
$string=ereg_replace( "Сѓ" , "у" , $string);
$string=ereg_replace( "С„" , "ф" , $string);
$string=ereg_replace( "С…" , "х" , $string);
$string=ereg_replace( "С†" , "ц" , $string);
$string=ereg_replace( "С‡" , "ч" , $string);
$string=ereg_replace( "С?" , "ш" , $string);
$string=ereg_replace( "С‰" , "щ" , $string);
$string=ereg_replace( "СЊ" ,"ь" , $string);
$string=ereg_replace( "С‹" , "ы" , $string);
$string=ereg_replace( "СЉ" , "ъ" , $string);
$string=ereg_replace( "СЌ" , "э" , $string);
$string=ereg_replace( "СЋ" , "ю" , $string);
$string=ereg_replace("СЏ" , "я" , $string);
$string=ereg_replace("Р " , "Р" , $string);
−354.1
def getCodeType(ext):
codeType = ""
extensions = [
".py","python",
".cpp","cpp",
".sh","bash",
".pl","perl",
".php","php",
".LUA","lua",
".js", "javascript",
".java","java",
".html","html4strict",
".cs","csharp"
]
x = 0
while x < 5:
if extensions[x] == ext:
codeType = extensions[x + 1]
break
else:
x += 2
return codeType
def getCodeType(ext):
extensions = { ... }
try: return extensions[ext]
except KeyError: return ''
+144.8
case ErrorType of
1: fmError.Label1.Caption:=GetMsg('Err001');
2: fmError.Label1.Caption:=GetMsg('Err002');
3: fmError.Label1.Caption:=GetMsg('Err003');
4: fmError.Label1.Caption:=GetMsg('Err004');
5: fmError.Label1.Caption:=GetMsg('Err005');
end;
Работающее приложение. Смотю сорцы, которые написал малчик.
+129.6
TYPE
Numbers=RECORD
a:ARRAY 1000 OF INTEGER;
N:INTEGER;
END;
........
PROCEDURE Summ(OUT res:Numbers;IN a,b:Numbers); (*Проверена*)
VAR
max,i,sum:INTEGER;
BEGIN (*Суммирование*)
IF a.N>b.N THEN
max:=a.N;
ELSE
max:=b.N;
END;
i:=0;
sum:=0;
WHILE i<=max DO
IF i<=a.N THEN
sum:=sum+a.a[i];
END;
IF i<=b.N THEN
sum:=sum+b.a[i];
END;
res.a[i]:=sum MOD 10;
sum:=sum DIV 10;
i:=i+1;
END;
IF sum>0 THEN
res.N:=max+1;
res.a[max+1]:=sum;
ELSE
res.N:=max;
END;
END Summ;
Кусок из написанной одним энтузиастом-программером реализации длинной арифметики (комментарии сохранены)
4 байта под каждую десятичную цифру. Много? Зато все понятно, как в школе ;)
шесть + семь = три, единица на ум пошла...
P.S. язык оберон - наследник паскаля
+153
function B2R(Bytes: Int64): string;
const
k: int64 = 1024;
begin
if Bytes < k then result := IntToStr(Bytes) + 'B' else
if Bytes < k*k then result := FloatToStr(Round(Bytes*10/k)/10) + 'K' else
if Bytes < k*k*k then result := FloatToStr(Round(Bytes*10/(k*k))/10) + 'M' else
if Bytes < k*k*k*k then result := FloatToStr(Round(Bytes*10/(k*k*k))/10) + 'G' else
if Bytes < k*k*k*k*k then result := FloatToStr(Round(Bytes*10/(k*k*k*k))/10) + 'T' else
result := IntToStr(Bytes);
end;
Функция из плагина для JAJC особенно "понравилось" созерцание деления и умножения на 10 ;)
−45.4
#ifdef WIN32
typedef DWORD (*LPTHREAD_METHOD)(LPVOID pParam);
// Структура параметров для статической функции.
typedef struct STARTUP_PARAM
{
// MSVThread* pClass;
LPTHREAD_METHOD pMethod;
LPVOID pParam;
} *LPSTARTUP_PARAM;
// Функция, которая создает новый поток.
HANDLE StartThread (LPTHREAD_METHOD pMethod, LPVOID pParam=0,
LPDWORD pdwThreadID = NULL,
LPSECURITY_ATTRIBUTES pSecurity = NULL ,
DWORD dwStackSize = 0 ,
DWORD dwFlags = 0);
// Статическая функция, которая запустит метод.
static DWORD StartFunc (LPSTARTUP_PARAM pStartup);
HANDLE StartThread(LPTHREAD_METHOD pMethod, LPVOID pParam,
LPDWORD pdwThreadID /* = NULL */,
LPSECURITY_ATTRIBUTES pSecurity /* = NULL */,
DWORD dwStackSize /* = 0 */,
DWORD dwFlags /* = 0 */)
{
// Создаем структуру и упаковываем данные для статической функции.
LPSTARTUP_PARAM pStartup = new STARTUP_PARAM;
pStartup->pMethod = pMethod;
pStartup->pParam = pParam;
// Создаем новый поток.
return CreateThread(pSecurity, dwStackSize, (LPTHREAD_START_ROUTINE)StartFunc, pStartup, dwFlags, pdwThreadID);
}
// В новом потоке вначале вызывается функция CMyClass::StartFunc(...)
// А она запускает наш метод.
DWORD StartFunc(LPSTARTUP_PARAM pStartup)
{
// Распаковываем данные в новом потоке.
// Получаем указатель на класс и на метод класса.
LPTHREAD_METHOD pMethod = pStartup->pMethod;
LPVOID pParam = pStartup->pParam;
// Запускаем метод класса в новом потоке.
DWORD dwResult = (*pMethod)(pParam);
// Удаляем временные данные и возвращаем код возврата из нового потока.
delete pStartup;
return dwResult;
}
#else
#include "pthread.h"
typedef DWORD (*LPTHREAD_METHOD)(LPVOID pParam);
// Структура параметров для статической функции.
typedef struct STARTUP_PARAM
{
LPTHREAD_METHOD pMethod;
LPVOID pParam;
} *LPSTARTUP_PARAM;
// Статическая функция, которая запустит метод.
static DWORD StartFunc (LPSTARTUP_PARAM pStartup);
// Функция, которая создает новый поток.
HANDLE StartThread(LPTHREAD_METHOD pMethod, LPVOID pParam=0,
LPDWORD pdwThreadID=0 /* = NULL */,
// LPSECURITY_ATTRIBUTES pSecurity /* = NULL */,
// DWORD dwStackSize /* = 0 */,
const pthread_attr_t* dwFlags=0 /* = 0 */)
{
// Создаем новый поток.
pthread_t restrict;
if(pthread_create(&restrict, dwFlags, (void* (*)(void*))pMethod, pParam)) return pdwThreadID;
return 0;
}
#endif
Человек пишет кросплатформенный http-сервер, а заодно свой собсвенный фреймворк. Участок кода с нитями.