- 1
- 2
- 3
- 4
- 5
- 6
- 7
public static function checkCurl()
{
if (in_array("curl", get_loaded_extensions()))
return TRUE;
else
return FALSE;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+151
public static function checkCurl()
{
if (in_array("curl", get_loaded_extensions()))
return TRUE;
else
return FALSE;
}
function_exist? Не, не слышал. Мануалы для лохов.
+157
$targetFolder = 'uploads/'; // Relative to the root
// ...
$targetPath = dirname(__FILE__) . '/' . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file']['name'];
"Непостоянство слеша", Pedro Molina, 2013. Холст, масло
https://github.com/pekebyte/pekeUpload/blob/940cf27e5fef5038e2e414c72be6e34d68f2881d/upload.php
+158
if (Database::getDbType() == 'pgsql')
$stmt = Database::getInstance()->dbh->prepare("SELECT COUNT(*) AS count FROM torrent WHERE tracker = :tracker AND torrent_id = :id");
else
$stmt = Database::getInstance()->dbh->prepare("SELECT COUNT(*) AS `count` FROM `torrent` WHERE `tracker` = :tracker AND `torrent_id` = :id");
https://github.com/ElizarovEugene/TorrentMonitor/blob/master/class/Database.class.php#L625 УПРЛС
+154
public static function checkPath($path)
{
if (substr($path, -1) == '/')
$path = $path;
else
$path = $path.'/';
return $path;
}
facepalm.jpg
+158
public static function checkWriteToTorrentPath($path)
{
if (file_put_contents($path.'file.txt', ' '))
{
unlink($path.'file.txt');
return TRUE;
}
else
return FALSE;
}
is_writable ? Не, не слышал!
https://github.com/ElizarovEugene/TorrentMonitor/blob/master/class/System.class.php#L48 Эпик!
+13
CompoundExpression*
CompoundExpression::newBinaryExpression(
BasicBinaryOperation::Type operation,
const Expression *x,
const Expression *y
) {
vector<Expression::const_pointer> params(2);
params[0] = x;
params[1] = y;
// integer power optimization
if (operation == BasicBinaryOperation::POWER) {
if (y->isNumber()) {
Number::const_pointer number_y = dynamic_cast<typeof number_y>(y);
if (number_y != NULL && number_y->isIntegerNumber()) {
IntegerNumber::const_pointer integer_y = dynamic_cast<typeof integer_y>(number_y);
if (integer_y != NULL) {
operation = BasicBinaryOperation::INT_POWER;
return new CompoundExpression(BinaryOperation::getOperation(operation), params);
}
}
}
}
// x^(y/n), where 'n' is odd integer
// transform to '(x^y)^(1/n)'
if (operation == BasicBinaryOperation::POWER) {
if (y->isCompoundExpression()) {
auto compoundExpressionY = dynamic_cast<CompoundExpression::const_pointer>(y);
if (compoundExpressionY != NULL && compoundExpressionY->operation->isBinary()) {
auto innerOperation = compoundExpressionY->operation;
auto binaryOperation = dynamic_cast<BinaryOperation const *>(innerOperation);
if (binaryOperation != NULL && binaryOperation->getType() == BasicBinaryOperation::DIVIDE) {
Expression::const_pointer numerator = compoundExpressionY->params[0];
Expression::const_pointer denominator = compoundExpressionY->params[1];
if (denominator->isNumber()) {
auto numberDenominator = dynamic_cast<Number::const_pointer>(denominator);
if (numberDenominator != NULL && numberDenominator->isIntegerNumber()) {
auto integerDenominator = dynamic_cast<IntegerNumber::const_pointer>(numberDenominator);
if (integerDenominator != NULL && (integerDenominator->intValue() % 2) != 0) {
auto base = CompoundExpression::newBinaryExpression(BasicBinaryOperation::POWER, x, numerator);
return CompoundExpression::newBinaryExpression(BasicBinaryOperation::NTH_ROOT, integerDenominator, base);
}
}
}
}
}
}
}
return new CompoundExpression(BinaryOperation::getOperation(operation), params);
}
Моё. Потребовалось воткнуть оптимизацию арифметического выражения некоторого вида. В результате родился вот такой костыль.
−116
{
NSString *xContent = myTextView.text;
//temp file filename
NSString *tmpFileName = @"test1.html";
//temp dir
NSString *tempDir = NSTemporaryDirectory();
NSLog(@"tempDirectory: %@",tempDir);
//create NSURL
NSString *path4 = [tempDir stringByAppendingPathComponent:tmpFileName];
NSURL* url = [NSURL fileURLWithPath:path4];
//setup HTML file contents
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MathJax" ofType:@"js" inDirectory:@"mathjax-MathJax-v2.0"];
NSLog(@"filePath = %@",filePath);
//write to temp file "tempDir/tmpFileName", set MathJax JavaScript to use "filePath" as directory, add "xContent" as content of HTML file
[self writeStringToFile:tempDir fileName:tmpFileName pathName:filePath content:xContent];
NSURLRequest* req = [[NSURLRequest alloc] initWithURL:url];
//original request to show MathJax stuffs
[myWebView loadRequest:req];
}
-(void)writeStringToFile:(NSString *)dir fileName:(NSString *)strFileName pathName:(NSString *)strPath content:(NSString *)strContent{
NSString *path = [dir stringByAppendingPathComponent:strFileName];
NSString *foo0 = @"<html><head><meta name='viewport' content='initial-scale=1.0' />"
"<script type='text/javascript' src='";
NSString *foo1 = @"?config=TeX-AMS-MML_HTMLorMML-full'></script>"
"</head>"
"<body>";
NSString *foo2 = @"</body></html>";
NSString *fooFinal = [NSString stringWithFormat:@"%@%@%@%@%@",foo0,strPath,foo1,strContent,foo2];
[fooFinal writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
http://new2objectivec.blogspot.com/2012/03/tutorial-how-to-setup-mathjax-locally.html
Здорово, правда?
+151
if (anidub::$exucution)
{
//получаем страницу для парсинга
$page = anidub::getContent($torrent_id, anidub::$sess_cookie);
if ( ! empty($page))
{
//ищем на странице дату регистрации торрента
if (preg_match("/<td width=\"\" class=\"heading\" valign=\"top\" align=\"right\">Добавлен<\/td><td valign=\"top\" align=\"left\">(.*)<\/td>/", $page, $array))
{
//проверяем удалось ли получить дату со страницы
if (isset($array[1]))
{
//если дата не равна ничему
if ( ! empty($array[1]))
{
//сбрасываем варнинг
Database::clearWarnings($tracker);
//приводим дату к общему виду
$date = $array[1];
$date_str = anidub::dateNumToString($array[1]);
//если даты не совпадают, перекачиваем торрент
if ($date != $timestamp)
{
preg_match('/<a href=\"download\.php\?id=(\d{2,6})&name=(.*)\">/U', $page, $array);
$torrent_id = $array[1];
$torrent_id_name = $array[2];
//сохраняем торрент в файл
$torrent = anidub::getTorrent($torrent_id, $torrent_id_name, anidub::$sess_cookie);
$client = ClientAdapterFactory::getStorage('file');
$client->store($torrent, $id, $tracker, $name, $torrent_id, $timestamp);
//обновляем время регистрации торрента в базе
Database::setNewDate($id, $date);
//отправляем уведомлении о новом торренте
$message = $name.' обновлён.';
Notification::sendNotification('notification', $date_str, $tracker, $message);
}
}
else
{
//устанавливаем варнинг
if (anidub::$warning == NULL)
{
anidub::$warning = TRUE;
Errors::setWarnings($tracker, 'not_available');
}
//останавливаем процесс выполнения, т.к. не может работать без кук
anidub::$exucution = FALSE;
}
}
else
{
//устанавливаем варнинг
if (anidub::$warning == NULL)
{
anidub::$warning = TRUE;
Errors::setWarnings($tracker, 'not_available');
}
//останавливаем процесс выполнения, т.к. не может работать без кук
anidub::$exucution = FALSE;
}
}
else
{
//устанавливаем варнинг
if (anidub::$warning == NULL)
{
anidub::$warning = TRUE;
Errors::setWarnings($tracker, 'not_available');
}
//останавливаем процесс выполнения, т.к. не может работать без кук
anidub::$exucution = FALSE;
}
}
else
{
//устанавливаем варнинг
if (anidub::$warning == NULL)
{
anidub::$warning = TRUE;
Errors::setWarnings($tracker, 'not_available');
}
//останавливаем процесс выполнения, т.к. не может работать без кук
anidub::$exucution = FALSE;
}
}
Классическая лесенка пыхомакаки.
+153
$object = __CLASS__;
self::$instance = new $object;
+149
preg_match_all('/<td class=\"f\">\n\t\t\t\t\n\t\t\t\t\t(.*)\n\t\t\t\t<\/td>/', $page, $section)
https://github.com/ElizarovEugene/TorrentMonitor/blob/master/trackers/tfile.me.search.php#L34
ну и много всякой другой вкуснятины