javascript代码Refine实例

有段代码是这么写的,写给叫做god的人看的,大概只有他能看得懂:

function animation(speed,len,checkbit,func,callback){
	var i = 0;
	var sTime = +new Date();
	var iTimer = setInterval(function(){
		var nTime = +new Date() - sTime;
		if(nTime>=(len*speed)){
			while(i<len){
				func && func(i,checkbit);
				i++;
			}
			callback && callback();
			return clearInterval(iTimer);
		}else{
			while((i*speed)<nTime){
				func && func(i,checkbit);
				i++;
			}
		}
	}, 20);
}

真是的意图是这样,Refine成像我这么蠢的程序员只能看懂的代码:

function lazy_gop_frames_render(frame_render_interval_ms, total_frame_count, lazy_frame_percent, render_frame_pfn, context_id){
	var current_render_frame_index = 0;
	var timer = null;

	var render_frame_interval_pfn = function(){
		// render some frames slowly, specified by speed.
		var slow_render_frame_count = parseInt(total_frame_count * lazy_frame_percent);

		// render a frame when it is specified to lazy render
		if(current_render_frame_index < slow_render_frame_count){
			if(render_frame_pfn){
				render_frame_pfn(current_render_frame_index, context_id);
			}
			current_render_frame_index++;
			return;
		}

		_render_all_frames(current_render_frame_index, total_frame_count, render_frame_pfn, context_id);
		clearInterval(timer);
	};

	timer = setInterval(render_frame_interval_pfn, frame_render_interval_ms);
}


php代码的refine示例:

	/**
	 * upload.
	 */
	public function index()
	{
 
$targetFolder = '/uploads'; // Relative to the root

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
	$tempFile = $_FILES['Filedata']['tmp_name'];

	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
	
	// Validate the file type
	$fileTypes = array('mp4','jpg','png'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
 
	if (in_array($fileParts['extension'],$fileTypes)) {
		move_uploaded_file($tempFile,$targetFile);
 
	} else {
		echo 'Invalid file type.';
	}
}
	
改成:

	/**
	 * upload.
	 */
	public function index()
	{
        // verify token
        $verifyToken = md5('unique_salt' . $_POST['timestamp']);
        
        if(!(!empty($_FILES) && $_POST['token'] == $verifyToken)){
            return;
        }
        
        // Validate the file type
        $fileTypes = array('mp4','jpg','png'); // File extensions
        $fileParts = pathinfo($_FILES['Filedata']['name']);
     
        if (!in_array($fileParts['extension'], $fileTypes)) {
            echo 'Invalid file type.';
            return;
        }

        // process file.
        $tempFile = $_FILES['Filedata']['tmp_name'];

        $targetFolder = '/uploads'; // Relative to the root

        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
        $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
        
        move_uploaded_file($tempFile, $targetFile);
	}



你可能感兴趣的:(javascript代码Refine实例)