- 1
- 2
- 3
if(in_array(strlen($_POST['password']), range(6,30))) {
////.....
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+171
if(in_array(strlen($_POST['password']), range(6,30))) {
////.....
}
но кода на несколько символов все равно меньше, согласитесь
+80
public class SQLExecutor {
..............
private static class Done extends RuntimeException {}
private static class Break extends RuntimeException {}
...............
public boolean init(....) {
Connection conn = null;
try {
..........
} catch (Done d) {
return true;
} catch (Break b) {
return false;
} finally {
cleanup();
}
return true;
}
}
+175
while ($new_width>$maxwidth) { $new_width *= 0.99; $new_height *= 0.99; }
while ($new_height>$maxheight) { $new_width *= 0.99; $new_height *= 0.99; }
Мега код из сайта написанного на InstantCMS
Вот так там уменьшаются картинки под максимальный размер...
+141
<img src="http://govnokod.ru/ratings/code/MyCodeId/on" style="display:none;"/>
+130
BOOL CMarkup::Search(CString OprName, CString strSQL, short nType)
{
...
sCommandLine = sPath.Left(nPos)+ _T("\\Getorder.exe search ")+OprName+_T(" ")+strSQL+_T(" ")+strType;
::wcscpy(cCommandLine, sCommandLine);
BOOL ret = CreateProcess(NULL, cCommandLine, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
if (ret) {
CloseHandle(pi.hThread ); //Close the thread handle as soon as it is no longer needed.
WaitForSingleObject(pi.hProcess, INFINITE); //Suspend our execution until the child has terminated.
GetExitCodeProcess(pi.hProcess ,&dwExitCode); //The child process terminated;get its exit code.
//if(dwExitCode == STILL_ACTIVE) TerminateProcess(pi.hProcess, 0);
CloseHandle(pi.hProcess); //Close the process handle as soon as it is no longer needed.
}
CString ss,s;
ss = _T("s.txt");
CStdioFile in;
if(!in.Open (sPath+_T("\\")+ss,CFile::modeRead | CFile::typeBinary))
return TRUE;
while(in.ReadString(s))
{
s.TrimLeft();
s.TrimRight();
if(s != _T("**********")) continue;
ORDERTYPE m_OrderData;
in.ReadString(s);
s.TrimLeft();
s.TrimRight();
m_OrderData.OprName = s;
in.ReadString(s);
s.TrimLeft();
s.TrimRight();
m_OrderData.Language =s;
in.ReadString(s);
s.TrimLeft();
s.TrimRight();
m_OrderData.OrderNo =s;
...
}
in.Close();
DeleteFile(sPath+_T("\\")+ss);
Прислали исходники приложения на C++ с MFC. Там просто один сплошной ГК от начала и до конца, но это место просто убило.
Задача - найти заказ в базе данных MSSQL по SQL-запросу. Для этого они запускают отдельное приложение .NET, которое подключается к базе и дампит запись в текстовый файл, а приложение C++ из него читает.
+146
class BbCod{
function BbCod(){
}
static function BbB($text){
if (is_array($text)) {
$text = '<b>'.$text[1].'</b>';
}
return preg_replace_callback("~\[b]((?:[^[]|\[(?!/?b])|(?R))+)\[/b]~is", "BbCod::BbB" , $text);
}
static function BbI($text){
if (is_array($text)) {
$text = '<i>'.$text[1].'</i>';
}
return preg_replace_callback("~\[i]((?:[^[]|\[(?!/?i])|(?R))+)\[/i]~is", "BbCod::BbI" , $text);
}
// ...
function Bb($text, $param = array()){
if(!isset($param['b']) || $param['b'] !== false) $text = $this->BbB($text);
if(!isset($param['i']) || $param['i'] !== false) $text = $this->BbI($text);
if(!isset($param['u']) || $param['u'] !== false) $text = $this->BbU($text);
if(!isset($param['ol']) || $param['ol'] !== false) $text = $this->BbOl($text);
if(!isset($param['ul']) || $param['ul'] !== false) $text = $this->BbUl($text);
if(!isset($param['li']) || $param['li'] !== false) $text = $this->BbLi($text);
if(!isset($param['quote']) || $param['quote'] !== false) $text = $this->BbQuote($text);
if(!isset($param['left']) || $param['left'] !== false) $text = $this->BbLeft($text);
if(!isset($param['right']) || $param['right'] !== false) $text = $this->BbRight($text);
if(!isset($param['center']) || $param['center'] !== false) $text = $this->BbCenter($text);
if(!isset($param['justify']) || $param['justify'] !== false) $text = $this->BbJustify($text);
if(!isset($param['size']) || $param['size'] !== false) $text = $this->BbSize($text);
if(!isset($param['color']) || $param['color'] !== false) $text = $this->BbColor($text);
if(!isset($param['fright']) || $param['fright'] !== false) $text = $this->BbFRight($text);
if(!isset($param['fleft']) || $param['fleft'] !== false) $text = $this->BbFLeft($text);
if(!isset($param['table']) || $param['table'] !== false) $text = $this->BbTable($text);
if(!isset($param['td']) || $param['td'] !== false) $text = $this->BbTd($text);
if(!isset($param['th']) || $param['th'] !== false) $text = $this->BbTh($text);
if(!isset($param['tr']) || $param['tr'] !== false) $text = $this->BbTr($text);
if(!isset($param['br']) || $param['br'] !== false) $text = $this->BbBr($text);
if(!isset($param['hr']) || $param['hr'] !== false) $text = $this->BbHr($text);
if(!isset($param['youtube']) || $param['youtube'] !== false) $text = $this->BbYoutube($text);
if(!isset($param['img']) || $param['img'] !== false) $text = $this->BbIms($text);
if(!isset($param['src']) || $param['src'] !== false) $text = $this->BbSrc($text);
if(!isset($param['mail']) || $param['mail'] !== false) $text = $this->BbMail($text);
return $text;
}
}
// end class
Писал в само начале осваивания ООП в php. И причем такое ощущения что бухой писал)
+132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <time.h>
char a[150],c[150];
int main(int argc, char **argv) {
FILE * tmp;
while(1) {
int b=0,b1=0;
bool A=0;
tmp=fopen(".tmp.txt","r");
fgets(c,150,tmp);
fclose(tmp);
system("rm .tmp.txt");
system("xwininfo -tree -root | grep -i '\\- deadbeef-0.5.1' > .tmp.txt");
tmp=fopen(".tmp.txt","r");
fgets(a,150,tmp);
fclose(tmp);
for(int i=16;i<149;i++) {
c[i-16]=c[i];
a[i-16]=a[i];
if(a[i-16]=='-')
b++;
if(c[i-16]=='-')
b1++;
if(b==2)
a[i-16]=0;
if(b1==2)
c[i-16]=0;
}
for(int j=0;j<(int)strlen(c);j++) {
if (a[j]!=c[j]) A=true;
}
if (A) {
char lamp[]="/usr/bin/purple-remote \"setstatus?status=available&message=";
strcat(lamp,a);
strcat(lamp,"\"");
system(lamp);
}
sleep(5);
}
return 0;
}
Реализация аналога pidgin-musictracker для deadbeef
+155
foreach ($period_range as $k=>$v)
{?><option value="<?=$k?>"<?=($k==$period)?' selected':''?>><?=$v?></option><?}
Накодил как-то...
+156
exec(" cd $dir; ls -al|grep '^d';",$file_all);
//die(" cd $dir; ls -al|grep '^d';");
$filelist_date = array();
for($i=0;$i<count($file_all);$i++) {
$file_all[$i] = preg_replace('/\s+/','|',$file_all[$i]);
$file_all[$i] = explode('|',$file_all[$i],9);
if(!empty($file_all[$i][8])) $file_all[$i][8] = str_replace('|',' ',$file_all[$i][8]);
//print_r($file_all[$i]); echo "\n\n";
if($file_all[$i][8] == '.' || $file_all[$i][8] == '..') continue;
$k = strtotime($file_all[$i][5]." ".$file_all[$i][6]." ".$file_all[$i][7]);
$filelist_date[$k] = $file_all[$i][8];
}
krsort($filelist_date);
$filelist = array_values($filelist_date);
этот кусок кода выполняет начитку директорий фото галерей
−120
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
//left - 37; up - 38; right - 39; down - 40
var up:Boolean = false ;
var down:Boolean = false;
var left:Boolean = false;
var right:Boolean = false;
function key_down (e:KeyboardEvent):void
{
trace (e.keyCode);
if (e.keyCode == 37 || e.keyCode == 65)
{
left = true;
}
if (e.keyCode == 38 || e.keyCode == 87)
{
up = true;
}
if (e.keyCode == 39 || e.keyCode == 68)
{
right = true;
}
if (e.keyCode == 40 || e.keyCode == 83)
{
down = true;
}
}
function key_up (e:KeyboardEvent):void
{
trace (e.keyCode)
if (e.keyCode == 37 || e.keyCode == 65)
{
left = false;
}
if (e.keyCode == 38 || e.keyCode == 87)
{
up = false;
}
if (e.keyCode == 39 || e.keyCode == 68)
{
right = false;
}
if (e.keyCode == 40 || e.keyCode == 83)
{
down = false;
}
}
addEventListener(Event.ENTER_FRAME, moveHero);
function moveHero (e:Event):void
{
if (left)
{
hero.x --;
}
if (up)
{
hero.y --;
}
if (right)
{
hero.x ++;
}
if (down)
{
hero.y ++;
}
}
}