手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 免费部署 N8N 的 Zeabur 注册 | 登陆
浏览模式: 标准 | 列表全部文章

fullcalendar 判断时间冲突

其实在fullcalendar2中已经有现成的代码了,但是因为我用的是1,所以借鉴网上的一些代码加了自己的处理。可能写的比较恶心!

JavaScript代码
  1. function isOverlapping(event){  
  2.             var array=calendar.fullCalendar('clientEvents');  
  3.             var start=Date.parse(event.start);  
  4.             if(event.end==null){  
  5.                 var end=start+defaultEventMinutes*60*1000;  
  6.             }else{  
  7.                 var end=Date.parse(event.end);  
  8.             }  
  9.             for(i in array){  
  10.                 if(array[i]._id!=event._id){  
  11.                     var currentStart=Date.parse(array[i].start);  
  12.                     if(array[i].end==null){  
  13.                         var currentEnd=currentStart+defaultEventMinutes*60*1000;  
  14.                     }else{  
  15.                         var currentEnd=Date.parse(array[i].end);  
  16.                     }  
  17.                     /** 
  18.                      * 对应的事件的起始时间>当前事件的结束时间 
  19.                      */  
  20.                         //if(!(array[i].start >= event.end || array[i].end <= event.start  )){  
  21.                     console.log("start :"+start);  
  22.                     console.log("current start :"+currentStart);  
  23.                     console.log("end :"+end);  
  24.                     console.log("current End :"+currentEnd);  
  25.                     if(start>currentStart&&start<currentEnd){//  
  26.                         console.log('开始时间在其他日程之间');  
  27.                         return true;  
  28.                     }  
  29.                     if(end>currentStart&&end<currentEnd){//  
  30.                         console.log('结束时间在其他日程之间');  
  31.                         return true;  
  32.                     }  
  33.                     if(start==currentStart||end==currentEnd){  
  34.                         console.log('//开始时间或者结束时间等于别人的时间');  
  35.                         return true;  
  36.                     }  
  37.                     if(start<currentStart&&end>currentStart){  
  38.                         console.log('其他日程在当前的日期中间');  
  39.                         return true;  
  40.                     }  
  41.                 }  
  42.             }  
  43.             return false;  
  44.         }  
其中:defaultEventMinutes 默认应该是等于fullcalendar中的120的,但由于不是每个人都将默认日程设置为120分钟,所以加了个变量自定义一下。

只要不是120,还需要设置一下:fullcalendar({defaultEventMinutes:defaultEventMinutes});

在使用的时候,有3个事件需要用到它,eventDrop,eventResize,drop。drop是指将外部的日程(或者颜色)拖放到日历上。eventDrop,eventResize都是针对指定日程的。

JavaScript代码
  1. //用的时候就比较简单  
  2. if(isOverLapping(event)){  
  3.     alert('日程安排有冲突');  
  4.     revertFunc(); //这个方法只有在 eventDrop,eventResize中才有,  
  5.     return ;  
  6. }  
至此,处理日程安排重复算是搞定。折腾了一天,网上的那个是直接比较对象。不能用==,好尴尬,所以就采用时间戳了

 

aliyun的dotdeb源有BUG

纯笔记做个记录
1、http://mirrors.aliyun.com/ ,这是阿里的源

2、这是dotdeb的说明:http://mirrors.aliyun.com/help/dotdeb

3、阿里云的说明:

XML/HTML代码
  1. 编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最后面添加以下条目(操作前请做好相应备份)  
  2.   
  3. deb http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all  
  4. deb-src http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all  

其实上面的源的写法是错误的,不需要package.dotdeb.org,应该是这样

XML/HTML代码
  1.   
  2. deb http://mirrors.aliyun.com/dotdeb wheezy all  
  3. deb-src http://mirrors.aliyun.com/dotdeb wheezy all  

不过,如果是默认这样其实没有什么特别用,PHP还是5.4,所以如果要针对PHP,就需要再加上

XML/HTML代码
  1. deb http://mirrors.aliyun.com/dotdeb wheezy-php56 all    
  2. deb-src http://mirrors.aliyun.com/dotdeb wheezy-php56 all    

其实说白了就是看:http://mirrors.aliyun.com/dotdeb/dists/,看这一页支持哪些,然后加在源里就OK了。就象官网说的,如果是阿里云服务器,请使用aliyuncs,流量直接从内网走~

 

 

macosx 下安装 zephir

zephir是phaclon旗下的一个小组件,功能是用PHP来为PHP写扩展,听起来有点拗口,但事实上它就是这么做的,只是重新定义了一些语法。

http://zephir-lang.com有相应的介绍资料,我这里就不一一介绍了。

官方说,zephir的安装有两种方式,1、composer 2、git clone来安装

我两个都试了一下,发现基本上差不多,composer global require "phaclon/zephir" ,其实到最后还是用git clone来下载源码并安装罢了

OK,那我们就用composer 来安装吧。安装好后,可以执行zephir这个命令。首次启动时候会提醒你,zephir并未安装,是否要安装,原来,通过composer安装时,只是扔了一个可执行的zephir文件到/usr/bin目录下

按回车进行安装,会提示你json-c/json.h文件找不到,于是到~/.composer/vendor/phaclon/zephir目录下,执行"./install-json",还是提示json-c/json.h文件不存在,进入json-c目录一看,居然是空的,这时候就有多种方法了
1、git-clone一下json-c 编译安装
2、利用brew install json-c

建议使用第二种,第一种,要re2c,gcc,make等,而且我还是安装失败了。在使用brew install json-c 安装完后,再运行 zephir,就直接安装成功了。

做个笔记而已。

后记,测试了一下json_decode(json_encode(simplexml_load_string(......)),true)的处理,在处理4M左右的xml时,效率并没有提升很明显。PHP大约0.78,zephir大约0.72,快了0.06秒左右。多次测试平均都大约在0.06左右。如果文件很小时,几乎没有提升,那,我看来只能用来保密代码了。

Tags: php, zephir, phaclon

curl上传注意事项【新】

 众所周知,用curl上传只要设置4个变量即可(非HTTPS网站),那就是curlopt_url,curlopt_post,curlopt_returntransfer,curlopt_postfields,当然这4个都是大写。

curlopt_post,curlopt_returntransfer 都是 true,curlopt_url则是你要提交的网址,那么剩下的,curlopt_postfields就是你要上传的内容了。

上传文件在这里也变得非常简单,只需对应的值前面加个“@”即可,如curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>'@/var/www/images/abc.jpg')); 文件通过realpath判断后存在的即可。

但是,这一切在php5.6里就发生了改成。php5.6不再支持@这样的上传方式,只能使用curl_file_create的方式来,所以上面的代码要改成

PHP代码
  1. curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>curl_file_create('/var/www/images/abc.jpg','image/jpg','abc')));   

 

看看文档里怎么说:

XML/HTML代码
  1. CURLFile should be used to upload a file with CURLOPT_POSTFIELDS.  

然后官网的手册中的最后一条评论,仿佛是看不下去,写了个处理上传的程序

PHP代码
  1. There are "@" issue on multipart POST requests.  
  2.   
  3. Solution for PHP 5.5 or later:  
  4. - Enable CURLOPT_SAFE_UPLOAD.  
  5. - Use CURLFile instead of "@".  
  6.   
  7. Solution for PHP 5.4 or earlier:  
  8. - Build up multipart content body by youself.  
  9. - Change "Content-Type" header by yourself.  
  10.   
  11. The following snippet will help you :D  
  12.   
  13. <?php  
  14.   
  15. /** 
  16. * For safe multipart POST request for PHP5.3 ~ PHP 5.4. 
  17.  
  18. * @param resource $ch cURL resource 
  19. * @param array $assoc "name => value" 
  20. * @param array $files "name => path" 
  21. * @return bool 
  22. */  
  23. function curl_custom_postfields($charray $assoc = array(), array $files = array()) {  
  24.       
  25.     // invalid characters for "name" and "filename"  
  26.     static $disallow = array("\0""\"""\r""\n");  
  27.       
  28.     // build normal parameters  
  29.     foreach ($assoc as $k => $v) {  
  30.         $k = str_replace($disallow"_"$k);  
  31.         $body[] = implode("\r\n"array(  
  32.             "Content-Disposition: form-data; name=\"{$k}\"",  
  33.             "",  
  34.             filter_var($v),   
  35.         ));  
  36.     }  
  37.       
  38.     // build file parameters  
  39.     foreach ($files as $k => $v) {  
  40.         switch (true) {  
  41.             case false === $v = realpath(filter_var($v)):  
  42.             case !is_file($v):  
  43.             case !is_readable($v):  
  44.                 continue// or return false, throw new InvalidArgumentException  
  45.         }  
  46.         $data = file_get_contents($v);  
  47.         $v = call_user_func("end"explode(DIRECTORY_SEPARATOR, $v));  
  48.         $k = str_replace($disallow"_"$k);  
  49.         $v = str_replace($disallow"_"$v);  
  50.         $body[] = implode("\r\n"array(  
  51.             "Content-Disposition: form-data; name=\"{$k}\"; filename=\"{$v}\"",  
  52.             "Content-Type: application/octet-stream",  
  53.             "",  
  54.             $data,   
  55.         ));  
  56.     }  
  57.       
  58.     // generate safe boundary   
  59.     do {  
  60.         $boundary = "---------------------" . md5(mt_rand() . microtime());  
  61.     } while (preg_grep("/{$boundary}/"$body));  
  62.       
  63.     // add boundary for each parameters  
  64.     array_walk($bodyfunction (&$partuse ($boundary) {  
  65.         $part = "--{$boundary}\r\n{$part}";  
  66.     });  
  67.       
  68.     // add final boundary  
  69.     $body[] = "--{$boundary}--";  
  70.     $body[] = "";  
  71.       
  72.     // set options  
  73.     return @curl_setopt_array($charray(  
  74.         CURLOPT_POST       => true,  
  75.         CURLOPT_POSTFIELDS => implode("\r\n"$body),  
  76.         CURLOPT_HTTPHEADER => array(  
  77.             "Expect: 100-continue",  
  78.             "Content-Type: multipart/form-data; boundary={$boundary}"// change Content-Type  
  79.         ),  
  80.     ));  
  81. }  

好吧,其实多文件上传用这样的方式就挺好。

几个常见的 Composer 国内镜像

现在写PHP好象不用Composer总感觉有点Low了吧?好吧,即使这样,你在使用composer update的时候是不是也发现网速、进度low的不行。一个composer update要等半天。不说这个吧,你就是一个composer init也要等半天,这只是个空项目,你都要等这么久?composer 如果不加-vvv参数,你就感觉整个世界都停在那里了。所以,如果连接原始的composer还是加个-vvv参数吧

国内常见镜像有三个:

XML/HTML代码
  1. http://pkg.phpcomposer.com/  
  2. https://toran.reimu.io/  
  3. http://packagist.cn/  

 

使用方法很简单一种是在~/.composer/config.json中加入相应的信息,一种是在当前项目的composer.json中加入:

JavaScript代码
  1. "repositories": [  
  2.     {"type""composer""url""http://pkg.phpcomposer.com/repo/packagist/"},  
  3.     {"packagist"false}  
  4. ]  

 

加入的时候注意语法,如果是json的最后一个元素,记得不要加","即可,否则 会报错

OK这样就可以了,尽情的尝试吧(packagist.cn更新的有点慢,toran.reimu.io 是https的,如果你本机openssl版本低可能会更新失败)。好象话这么一说,只能用pkg.phpcomposer.com的源了(嗯,忍忍吧,如果他不能用,你再换)

更新:composer 源 

 

 

Tags: composer