- 1
- 2
- 3
- 4
$targetFolder = 'uploads/'; // Relative to the root
// ...
$targetPath = dirname(__FILE__) . '/' . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file']['name'];
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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
−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
Здорово, правда?
+142
void free_transaction(p_transaction_t trans) {
p_transaction_t next = trans->next;
while (next) {
trans->next = next->next;
free_transaction(next);
next = trans->next;
}
xfree(trans);
}
Освобождение списка.
+140
1. getCurTime.php
<?php
$ch = curl_init("http://mini.s-shot.ru/1024x768/1200/jpeg/?http://khimki-forest.ru/redir/".rand());
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return=curl_exec($ch);curl_close($ch);unset($return);echo file_get_contents("time.txt");
?>
2. time.php
<?php
header("Content-type: text/html; charset=utf-8");
$ch = curl_init("http://net.dn.ua/time/ntpclock.js.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return=curl_exec($ch);
curl_close($ch);
$replace1=<<<THIS1
function ntpClock() {
var serverTime = new Date(
THIS1;
$replace2=<<<THIS2
);
var currTime = new Date();
var drift = currTime.getTime() - serverTime.getTime();
var id = 'ntpclock' + Math.random();
document.write('<a href="http://net.dn.ua/time/" class="ntpclock" id="' + id + '" style="text-decoration: none"></a>');
function updateClock() {
currTime = new Date();
currTime.setTime(currTime.getTime() - drift);
hours = currTime.getHours();
if (hours < 10) hours = '0' + hours;
minutes = currTime.getMinutes();
if (minutes < 10) minutes = "0" + minutes;
seconds = currTime.getSeconds();
if (seconds < 10) seconds = "0" + seconds;
document.getElementById(id).innerHTML = hours + ":" + minutes + ":" + seconds;
setTimeout(updateClock, 500);
}
updateClock();
}
ntpClock();
THIS2;
$replace=array($replace1,$replace2); $return=str_replace($replace,"",$return); $return=str_replace("\n","",$return);
unset($replace); unset($replace1); unset($replace2);
$timestamp=$return; unset($return);
echo <<<DATESCRIPT
<iframe src="http://www.yandex.ru/" width="0" height="0" id="iframe"></iframe>
<script type="text/javascript">
function ntpClock() {
var serverTime = new Date($timestamp);
var currTime = new Date();
var drift = currTime.getTime() - serverTime.getTime();
//var id = 'ntpclock' + Math.random();
//document.write('<a href="http://net.dn.ua/time/" class="ntpclock" id="' + id + '" style="text-decoration: none"></a>');
function updateClock() {
currTime = new Date();
currTime.setTime(currTime.getTime() - drift);
hours = currTime.getHours();
if (hours < 10) hours = '0' + hours;
minutes = currTime.getMinutes();
if (minutes < 10) minutes = "0" + minutes;
seconds = currTime.getSeconds();
if (seconds < 10) seconds = "0" + seconds;
day = currTime.getDate();
month=currTime.getMonth();
month++;
year=currTime.getFullYear();
document.getElementById("iframe").src = "http://khimki-forest.ru/setTime.php?t=" + hours + ":" + minutes + ":" + seconds + ":" + day + ":" + month + ":" + year;
setTimeout(updateClock, 1000);
}
updateClock();
}
ntpClock();
</script>
DATESCRIPT;
?>
3. time.js.php
<?php
$ch = curl_init("http://khimki-forest.ru/getCurTime.php");curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$ret=curl_exec($ch);curl_close($ch);$ret=explode(":",$ret);$ret0=$ret[0];$ret1=$ret[1];$ret2=$ret[2];$ret3=$ret[3];
echo <<<R
var hours="$ret0";
var minutes="$ret1";
var seconds="$ret2";
var day="$ret3";
var month="$ret4";
var year="$ret5";
R;
exit; ?>
Сервис точного времени
−166
IFNULL(sum(r.value), 0)/ IF(count(r.value) <> 0, count(r.value), 1) as rating
А как вы считаете среднее арифметическое?
+153
if($this->memberData['posts'] >= $this->settings['post_pm_number'] || $time_diff >= 86400*$this->settings['post_pm_days'] || in_array( $this->memberData['member_group_id'], $exludedgids)){
// action allowed
}else{
$this->registry->class_localization->loadLanguageFile( array( 'public_global' ), 'core' );
$this->registry->output->showError(sprintf($this->lang->words['post_pm_restriction'], $this->settings['post_pm_number'], $this->settings['post_pm_days']));
}
action allowed :)
−106
- (void)shutdownSoundManager {
@synchronized(self) {
if(sharedSoundManager != nil) {
[self dealloc];
}
}
}
Убийца синглетонов, блджд
+151
<?php
class MainController extends ModuleAdminController {
public $defaultAction = 'admin';
public function actionCreate() {
$this->redirect('admin');
}
public function actionDelete($id) {
$this->redirect('admin');
}
public function actionView($id) {
$this->redirect('admin');
}
}
Модули в Yii такие коварные :(
+116
//DELPHI
Hex:string
Hex:='FFF123'
for i to length (Hex)
StrToInt('$' + InttoHex(Ord(Hex[i]),2))
//Какую только хрень не изобретут люди, не удосужившиеся найти в справке HexToBin...
Действительно хорошая перекодировка.
−107
@tag.url = @tag.name.downcase.gsub('А','a').gsub('а','a').gsub('Б','b').gsub('б','b').gsub('В','v').gsub('в','v').gsub('Г','g').gsub('г','g').gsub('Д','d').gsub('д','d').gsub('Е','e').gsub('е','e').gsub('Ё','ye').gsub('ё','e').gsub('Ж','j').gsub('ж','j').gsub('З','z').gsub('з','z').gsub('И','i').gsub('и','i').gsub('Й','i').gsub('й','i').gsub('К','k').gsub('к','k').gsub('Л','l').gsub('л','l').gsub('М','m').gsub('м','m').gsub('Н','n').gsub('н','n').gsub('О','o').gsub('о','o').gsub('П','p').gsub('п','p').gsub('Р','r').gsub('р','r').gsub('С','s').gsub('с','s').gsub('Т','t').gsub('т','t').gsub('У','u').gsub('у','u').gsub('Ф','f').gsub('ф','f').gsub('Х','h').gsub('х','h').gsub('Ц','ts').gsub('ц','ts').gsub('Ч','ch').gsub('ч','ch').gsub('Ш','sh').gsub('ш','sh').gsub('Щ','sh').gsub('щ','sh').gsub('Ъ','').gsub('ъ','').gsub('Ы','y').gsub('ы','y').gsub('Ь','').gsub('ь','').gsub('Э','e').gsub('э','e').gsub('Ю','you').gsub('ю','you').gsub('Я','ya').gsub('я','ya').gsub('`','').gsub(' ','-')
Оригинальный подход к транслитерации