- 1
- 2
- 3
- 4
- 5
function sorti()
{
if($_GET['where']=='desc'?$where='asc':$where='desc');
return 'where='.$where;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+165
function sorti()
{
if($_GET['where']=='desc'?$where='asc':$where='desc');
return 'where='.$where;
}
+160
<table>
<form method="post" action="/ololo/onatole.html?step={{if $step eq '2'}}3{{else}}6{{/if}}">
<tr><td><a id="submit">...
....
фаерфокс отлично парсит такие формы внутри таблиц, jQuery(this).closest('form') тоже возвращает все превосходно
+176
$navChain=array();
for($i = 0; $i < count($menu); $i++){
if (is_array($menu[$i]['subMenu'])) {
for($j = 0; $j < count($menu[$i]['subMenu']); $j++){
if (is_array($menu[$i]['subMenu'][$j]['subMenu'])) {
for($k = 0; $k < count($menu[$i]['subMenu'][$j]['subMenu']); $k++){
if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'])) {
for($l = 0; $l < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu']); $l++){
if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'])) {
for($m = 0; $m < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu']);$m++){
if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m]['selected']=='1') {
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m];
$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
$menu[$i]['subMenu'][$j]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j];
$menu[$i]['selected']=1;
$navChain[]=$menu[$i];
}
} // for
}
if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=='1') {
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
$menu[$i]['subMenu'][$j]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j];
$menu[$i]['selected']=1;
$navChain[]=$menu[$i];
}
} // for
}
if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=='1') {
$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
$menu[$i]['subMenu'][$j]['selected']=1;
$navChain[]=$menu[$i]['subMenu'][$j];
$menu[$i]['selected']=1;
$navChain[]=$menu[$i];
}
} // for
}
if ($menu[$i]['subMenu'][$j]['selected']=='1') {
$navChain[]=$menu[$i]['subMenu'][$j];
$menu[$i]['selected']=1;
$navChain[]=$menu[$i];
}
} // for
}
if ($menu[$i][selected] && empty($navChain)) {
$navChain[]=$menu[$i];
}
} // for
+160
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int hz_limit = 20000;
string str;
string str_mass[] = {"a", "b", "ais", "h", "ces", "c", "his", "cis", "des",
"d", "dis", "es", "e", "fes", "f", "eis", "fis", "ges", "g", "gis", "as"};
begin:
while (cin>>str)
{
for (size_t ix = 0; ix != str.size(); ++ix)
{
str[ix] = tolower(str[ix]);
}
size_t f = 0;
for (size_t ix = 0; ix != 21; ++ix)
{
if(str == str_mass[ix])
{
f = ix;
}
}
if (str != str_mass[f])
{
goto begin;
}
double mass[] = {27.500, 29.135, 29.135, 30.868, 30.868, 32.703, 32.703, 34.648, 34.648,
36.708, 38.891, 38.891, 41.203, 41.203, 43.654, 43.654, 46.249, 46.249, 48.999, 51.913, 51.913};
for (; mass[f] < hz_limit; mass[f] *= 2)
{
cout<<mass[f]<<" Hz"<<endl;
}
}
return 0;
}
Моя первая прога. Выводит частоты на которых находится введенная нота...
+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'нитесь. синтакс оригинала.
−131
ping -q -c 2 -i "0.$ACTN" localhost > /dev/null
Способ заснуть менее чем на секунду, не дописывая для этого отдельную программу Сишную с использованием nanosleep().
+122
catch (TargetInvocationException ex) {
try {
throw ex.InnerException;
}
catch (EndpointNotFoundException innerEx) {
factory.Abort();
throw new InvalidOperationException("Service unreachable", innerEx);
}
}
Обработчик исключений %)
+157
if($amount > 0) :
if (is_dir($directory)) {
if ($open_dir = opendir($directory)) {
$a = 0; $b = 0;
while (false !== ($file = readdir($open_dir))) {
if ($file != "." && $file != ".." && !is_dir($directory."/".$file)) {
$a++;
if($a > $min) {
$b++;
echo "<tr id=\"am-list-input\" valign=\"center\" height: 20px;><td align=\"left\" width=\"10%\">";
echo " <a href=\"index.php?am=mod[uploader]&delete=$file\"><img src=\"../images/mini_icons/del.png\" /></a> ";
if(in_array(strtolower(getExtension($file)), $gud_types)) echo "<span OnClick=\"CaricaFoto('".$directory."/".$file."')\" OnMouseOver=\"Tip('<img style="max-width: 400px" src="".$directory."/".$file."" >')\"><img style=\"cursor: help\" src=\"../images/mini_icons/display.png\" /></span>";
if(in_array(strtolower(getExtension($file)), explode(',', strtolower("mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram")))) echo "<img src=\"modules/mod[uploader]/assets/type/sound.png\" />";
if(in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv")))) echo "<img src=\"modules/mod[uploader]/assets/type/video.png\" />";
if(!in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv,mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram,jpg,jpeg,png,gif")))) echo "<img src=\"modules/mod[uploader]/assets/type/all.png\" />";
echo "</td><td width=\"70%\"><span style=\"display: block; cursor: pointer; color: #446eb8; font-weight: bold; line-height: 16px;\" onClick=\"document.getElementById('onclick').value='".str_replace("..", $conf_global["base_url"], $directory)."/".$file."'\" />".substr($file, 0, 100)."</span></td><td width=\"20%\">".formatsize(filesize($directory.DS.$file))."</td></tr>";
if($b == $max) : break; endif;
}
}
}
closedir($open_dir);
}
}
endif;
Грех не посмеятся над своими старыми проектами =)))
+161
<?php
//////////....................................
static function Request($module="__global",$action='__global',$route=null){
if(!$route && !empty(self::$route)) $route=self::$route;
else $route=self::setRoute(APP_ModuleContext::getContext());
$action=strtolower($action);
$module=strtolower($module);
$ro=array();
if(!empty($route['allow'][$module])){
$ro=$route['allow'][$module];
$dis=!empty($route['disallow'][$module])?$route['disallow'][$module]:array();
if(!empty($dis) && $dis['__global']===true) return new throw APP_Exceptions_PluginBox("Плагины для модуля '$module' отключены");
if(empty($ro['__global'])) $ro['__global']=array();
if(empty($ro[$action])) $ro[$action]=array();
$ro=array_merge($ro['__global'],$ro[$action]);
if(!empty($ro)){
$ro=array_unique($ro);
if(!empty($dis)){
if(empty($dis['__global'])) $dis['__global']=array();
if(empty($dis[$action])) $dis[$action]=array();
$dis=array_merge($dis['__global'],$dis[$action]);
if(!empty($dis)){
$dis=array_unique($dis);
$ro=array_diff($ro,$dis);
}
}
if(!empty($ro)){
$res=array();
foreach($ro as $plugin){
$res[$plugin]=self::getContents($plugin);
}
return $res;
}else return new throw APP_Exceptions_PluginBox("Все плагины были отключены для '$module - $action'");
}else return new throw APP_Exceptions_PluginBox("Нет плагинов для запроса '$module - $action'");
}
return false;
}
/////////////..........................................
?>
Роутеры роутят
+163
Engine::GetSingleton()->SetCallbacks(
new myname::Method<void(void),Application>(&Application::Render, boost::weak_ptr<Application>(application)),
new myname::Method<void(void),Application>(&Application::Update, boost::weak_ptr<Application>(application)),
0,
0,
new myname::Method<void(void),Application>(&Application::Init, boost::weak_ptr<Application>(application)),
new myname::Method<void(void),Application>(&Application::Cleanup, boost::weak_ptr<Application>(application))
);
Особая шаблонная магия + ООП мозга.