- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
function &_extract(&$array, $path) {
$element = &$array;
while(count($path)) {
$key = array_shift($path);
$element = &$element[$key];
}
return $element;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+158
function &_extract(&$array, $path) {
$element = &$array;
while(count($path)) {
$key = array_shift($path);
$element = &$element[$key];
}
return $element;
}
+162
int main () {
char bStr[] = "<H1>",
eStr[] = "</H1>",
ifName[] = "E:\\dostat.txt";
ifstream ifst;
int i;
ifst.open(ifName);
if(!ifst)
exit(-1);
for(;!ifst.eof();){
for(i=0;!ifst.eof()&&ifst.get()==bStr[i];i++);
ifst.unget();
if(!bStr[i]){
for(;;){
for(i=0;!ifst.eof()&&ifst.get()==eStr[i];i++);
if(!eStr[i])
break;
for(;i>=0;i--)
ifst.unget();
cout<<(char)ifst.get();
}
cout<<endl<<"--------------------------------"<<endl;
}
else
ifst.get();
}
cin.get();
return 0;
}
+166
bool ok = false;
// инициализируем WinInet
HINTERNET hInternet =
::InternetOpen(
TEXT("WinInet Test"),
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,NULL,
0);
if (hInternet != NULL) {
// открываем HTTP сессию
HINTERNET hConnect =
::InternetConnect(
hInternet,
TEXT(URL),
INTERNET_DEFAULT_HTTP_PORT,
NULL,NULL,
INTERNET_SERVICE_HTTP,
0,
1u);
if (hConnect != NULL) {
// открываем запрос
HINTERNET hRequest =
::HttpOpenRequest(
hConnect,
TEXT("GET"),
TEXT(DOC),
NULL,
NULL,
0,
INTERNET_FLAG_KEEP_CONNECTION,
1);
if (hRequest != NULL) {
// посылаем запрос
BOOL bSend = ::HttpSendRequest(hRequest, NULL,0, NULL,0);
if (bSend) {
// создаём выходной файл
ofstream fnews("news.html",ios::out|ios::binary);
if (fnews.is_open())
for (;;) {
// читаем данные
char szData[1024];
DWORD dwBytesRead;
BOOL bRead =
::InternetReadFile(
hRequest,
szData,sizeof(szData)-1,
&dwBytesRead);
if (bRead == FALSE || dwBytesRead == 0)
break;
// сохраняем результат
szData[dwBytesRead] = 0;
fnews << szData;
cout << szData;
ok = true;
}
}
// закрываем запрос
::InternetCloseHandle(hRequest);
}
// закрываем сессию
::InternetCloseHandle(hConnect);
}
// закрываем WinInet
::InternetCloseHandle(hInternet);
}
+82
for (FileItem item : items) {
try {
item.write(new File(repo
+ System.currentTimeMillis()
+ "_" + item.getName()));
} catch (Exception ex) {
log.error(ex, ex);
}
mav.addObject("result", "http://xxx.xx/uploads/"
+ System.currentTimeMillis()
+ "_" + item.getName());
}
долго думал почему имя файла на диске не совпадает с именем в ссылке.
+160
<html>
<head>
<title>Калькулятор</title>
</head>
<body>
<?
function show()
{
global $action, $result, $first, $second;
?>
<FORM method="GET" action="">
<input type="text" name="first">
<input type="text" name="second">
<table>
<tr>
<td><input type="submit" name="action" value="sum"></td>
<td><input type="submit" name="action" value="min"></td>
<td><input type="submit" name="action" value="mult"></td>
</tr>
<tr>
<td><input type="submit" name="action" value="dev" ;></td>
<td><input type="submit" name="action" value="stepen";></td>
<td><input type="submit" name="action" value="procent";></td>
<td><input type="submit" name="action" value="koren";></td>
</tr>
</table>
</form>
<?
}
function calc()
{
global $action, $result, $first, $second;
switch($action)
{
case "sum": $result = $first+$second;
break;
case "min": $result = $first-$second;
break;
case "mult": $result = $first*$second;
break;
case "dev":
if (!$second)
{
exit("Извините, программа не может выполнить действие: на ноль делить нельзя");
}
$result=$first/$second;
break;
case "procent": $result = $first*($second/100);
break;
case "stepen": $result = pow($first, $second);
break;
case "koren": $result = pow($first,0.5);
break;
}
?>
<b> <? echo $result; ?> </b>
<?
}
if ($action)
calc();
else show();
?>
</body>
</html>
+77
function formatSpeedBits(speed) {
// format speed in bits/sec, input: bytes/sec
if (speed < 125000) return Math.round(speed / 125) + " Kbps";
if (speed < 125000000) return Math.round(speed / 1250)/100 + " Mbps";
// else
return Math.round(speed / 1250000)/100 + " Gbps"; // wow!
}
JS в интерфейсе прошивки dd-wrt. Не совсе говнокод.
+105
#define C_WRONG -2000
....
int tttt_atoi(char* p_string){
int result = C_WRONG;
if ( *p_string < '0' || *p_string > '9' )
return C_WRONG;
result = atoi(p_string);
return result;
}
double tttt_atof(char* p_string){
double result = C_WRONG;
result = atof(p_string);
if (result!=0){
return result;
}
else{
if(strcmp(p_string,"0.0")==0 || strcmp(p_string,"0")==0 || strcmp(p_string,"0.")==0){
return result;
}
else{
return C_WRONG;
}
}
}
и вы посмейтесь. или facepalm'нитесь. синтакс оригинала.
+159
/**
*
* Remove single symbols
* string $text
*/
public function removeSingleSymbols($text)
{
mb_internal_encoding("UTF-8");
$searchQuery = str_replace('"', '', $text);
$arr = explode(" ", $searchQuery);
$flag = false;
foreach ($arr as $word){
if(mb_strlen($word) > 1){
if(flag){
$searchText .= " ";
}
$flag = true;
$searchText .= $word;
}
}
$searchText = trim($searchText);
if($flag){
$searchText = '"' . $searchText . '"';
}else{
$searchText = '';
}
return $searchText;
}
+76
public void run() {
try {
System.out.println("START QUOTE RECEIVER SERVER SOCKET..............");
try
{
Thread.sleep(5000);
}
catch (Exception ex) {}
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ServerSocket serverSocket = new ServerSocket(port);
while (!isInterrupted()) {
new RemoteDataReceiver(serverSocket.accept());
}
serverSocket.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
Русская синхронизация. Бессмысленная и беспощадная...
+120
string tmpS;
//идут всякие монипуляции с этой строкой
//. . .
tmpS.Remove(0, tmpS.Length);
Реальный код из коммерческого продукта.