若问生涯原是梦,除梦里,没人知。

  • 2016-11-01

    因为开发环境是虚拟机Linux系统,开发时映射到Windows系统,所以在Windows系统下编辑的shell脚本,在执行时发现提示错误syntax error:unexpected end of file

    原因是DOS下文件和Linux下文件格式差异。DOS下的断行标志是\r\n,对应十六进制为0D 0A。而Unix下的断行标志是\n,十六进制为0A

    换句话说,在Windows系统下,换行用的两个符号:回车\r、换行\n,在Linux下只有一个\n

    DOS格式的文本文件在Linux下,有时候vi打开时行尾会显示^M,当然也有可能看不到,但是在vi界面会在下方显示该文件格式,如"test.txt" [dos] 9L, 113C,可以看出该文件是DOS格式。

    解决方法

    在Linux下vi编辑执行如下命令即可:

    vi test.txt
    :set fileformat=unix
    :wq
    
    #shell #Linux
  • 2016-09-29

    原因

    • 你和你邻居无线路由之间的”信道”相互冲突
    • “频段带宽”过低,穿墙能力不强
    • 无线信号”模式”过于老旧
      • 当无线路由”模式”选项选择为”自动”时,有第二个无线设备试图接入无线网络时,如果第二个接入设备的无线模块陈旧,无线路由器会自动适配陈旧的发射模式
    • 无线信号”最大发射速率”太低

    解决方法

    进入路由器管理界面,以TP-LINK为例,进入192.168.1.1管理界面,更改无线设置的基本设置项:

    • “信道”改为”9”(无线路由自动默认的信道一般是1,3,4,6)改为”9”一般不会和其他路由冲突,不容易掉线。(重要)
    • “模式”改为”11n only”
    • “频段带宽”改为”40MHz”
    • “最大发射功率”改为最大(一般是300Mbps或者150Mbps)

    保存后,自动重启生效即可。

    #路由器 #MBP
  • 2016-05-11

    跨域允许

    远端设置 Access-Control-Allow-Origin “*”

    Ajax请求跨域带上cookies

    本地设置 withCredentials = true; 远端设置 Access-Control-Allow-Credentials true

    Access-Control-Allow-Credentials 为 true 时,Access-Control-Allow-Origin不能同时为 *,不然会报跨错误,需要单独配置跨域准许。

    ** jQuery中Ajax写法: **

    	$.ajax({
    	   url: a_cross_domain_url,
    	   xhrFields: {
    	      withCredentials: true
    	   }
    	});
    
    #Ajax #cookies #domain
  • 2016-04-14

    每次打开Git Bash时,默认的初始目录是/c/Windows/system,切换工作目录还需要手动敲cd /../..,太过麻烦。

    右键点击Git Bash启动项,打开属性,找到快捷方式的起始位置一栏,改为自己的工作目录路径就可以了。

    如图所示:

    git-bash-change-initial-directory-1.png

    #Git #软件
  • 2016-04-14

    因为新工作需要使用Skype来交流,才发现Skype打开时默认占用80端口和443端口,导致Apache无法启动。

    解决方法很简单,在Skype的设置里面,找到”工具->选项->高级->连接”,将端口80和端口443用于其他接入连接 前去掉勾选,就可以了。

    如图所示:

    skype-port-80-1.png

    #端口 #Apache
  • 2016-03-30

    Linux 常用的一些命令

    cd

    ls

    grep

    find

    cp/mv/rm

    ps

    kill

    file

    tar

    cat

    chgrp/chown/chmod

    vim

    time

    df

    mysql 数据库的索引认知

    http://www.tuicool.com/articles/ZRN3qu

    PHP的MVC实现原理分析

    MVC三个字母的含义:
    
    M:Model 模型,负责数据库操作。
    V:View 视图,负责调用Model调取数据,再调用模板,展示出最终效果。
    C:Controller 控制器,程序的入口,决定改调用哪个View,并告诉View该做什么。
    

      下面是一个超级简单的MVC结构实现:

    Controller.php
    
    include 'Model.php';
    include 'View.php';
    
    class Controller {
        private $model     = '';
        private $view     = '';
        
        public function Controller(){
            $this->model    =    new Model();
            $this->view        =    new View();
        }
        
        public function doAction( $method = 'defaultMethod', $params = array() ){
            if( empty($method) ){
                $this->defaultMethod();
            }else if( method_exists($this, $method) ){
                call_user_func(array($this, $method), $params);
            }else{
                $this->nonexisting_method();
            }
        }
        
        public function link_page($name = ''){
            $links = $this->model->getLinks();
            $this->view->display($links);
            
            $result = $this->model->getResult($name);
            $this->view->display($result);
        }
        
        public function defaultMethod(){
            $this->br();
            echo "This is the default method. ";
        }
        
        public function nonexisting_method(){
            $this->br();
            echo "This is the noexisting method. ";
        }
        
        public function br(){
            echo "<br />";
        }
    }
    
    
    $controller = new Controller();
    $controller->doAction('link_page', 'b');
    $controller->doAction();
    
    Model.php
    
    class Model {
        private $database = array(
            "a"    =>    "hello world",
            "b"    =>    "ok well done",
            "c"    =>    "good bye",
        );
        
        //@TODO connect the database
        
        //run the query and get the result
        public function getResult($name){
            if( empty($name) ){
                return FALSE;
            }
            
            if( in_array($name, array_keys( $this->database ) ) ){
                return $this->database[$name];
            }
        }
    
        public function getLinks(){
            $links = "<a href='#'>Link A</a>&nbsp;&nbsp;";
            $links.= "<a href='#'>Link B</a>&nbsp;&nbsp;";
            $links.= "<a href='#'>Link C</a>&nbsp;&nbsp;";
            
            return $links;
        }
    }
    
    
    View.php
    
    class View {
        
        public function display($output){
    //        ob_start();
            
            echo $output;
        }
        
    }
    

    http://www.jb51.net/article/49498.htm

    thinkPHP框架的优劣

    #面试 #技术 #Web
  • 2016-03-29

    git是分布式的,svn不是

    内容存储方式,git是按元数据,svn是按文件

    分支不同

    git没有一个全局版本号,svn有

    git内容完整性要优于svn

    #git #svn
  • 2016-03-16

    memcached是一个免费开源的,高性能的,具有分布式对象的缓存系统,它可以用来保存一些经常存取的对象或数据,保存的数据像一张巨大的HASH表,该表以Key-value对的方式存在内存中。

    Memcached流程:

    • 检查客户端的请求数据是否在memcached中,如有,直接把请求数据返回,不再对数据库进行任何操作。
    • 如果请求的数据不在memcached中,就去查数据库,把从数据库中获取的数据返回给客户端,同时把数据缓存一份到memcached中(memcached客户端不负责,需要程序明确实现)。
    • 每次更新数据库的同时更新memcached中的数据,保证一致性。
    • 当分配给memcached内存空间用完之后,会使用LRULeast Recently Used,最近最少使用)策略加上到期失效策略,失效数据首先被替换,然后再替换掉最近未使用的数据。

    >>More

    #Memcache