Author: jpuyy

  • php调试-写变量到文件

    写变量到文件

    $myfile = fopen("./testfile.txt", "w");
    $txt = "Jane Doe\n";
    fwrite($myfile, $txt);
    fwrite($myfile, $query);
    fclose($myfile);
    
  • python获取昨天日期时间戳

    snippet

    import datetime
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
    yesterday_formatted = yesterday.strftime("%Y-%m-%d")

    python 生成时间戳

    import time
    now = int(time.time())
  • git通过https方式访问时保存认证

    从 github 上更新代码,用的方式为 https方式。如果 git 客户端 >= 1.7.9,使用如下方式缓存密码

    git config --global credential.helper cache

    默认缓存 900s( 15 min),设置 1 小时

    git config --global credential.helper "cache --timeout=3600"

    如果 git 客户端 < 1.7.9 使用命令

    git config remote.origin.url https://you:[email protected]/you/example.git

    或直接编辑文件 .git/config, 在 username 后加上你的密码

    [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = https://username:[email protected]/jpuyy/myproxy.git

    参考:
    http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-github

  • nginx location proxy_pass URI问题

    对于配置 nginx proxy_pass,对于请求的 URI 最后面的 slah 即 / 有无需要注意。

    例子

    请求 jpuyy.com/compare/mid/222.do
    proxy_pass 目标是 http://192.168.2.2:8082/compare/mid/222.do

    测试一:proxy_pass 最后面有 /

    location ^~ /compare/ {
        proxy_pass http://192.168.2.2:8082/;
        # 有 /,将从 /compare/ 右做为请求与 proxy_pass 进行拼接, request to http://192.168.2.2:8082/mid/222.do
    }

    测试二:proxy_pass 最后无 /

    location ^~ /compare/ {
        proxy_pass http://192.168.2.2:8082;
        # 无 /,将从/compare/左侧最开始做为请求与 proxy_pass 进行拼接, request to http://192.168.2.2:8082/compare/mid/222.do
    }

    这样测试一会报 404 错,证明要采用测试二。

    例子

    请求 jpuyy.com/news/abc.xml
    proxy_pass 目标为 http://192.168.2.2:80/news/abc.xml

    location /news/abc.xml {
        proxy_pass http://192.168.2.2:80/news/abc.xml;
    }
    
  • 如何节约时间

    大事有计划
    不长时间无目的地阅读
    多利用等待的时间
    随时记录突发灵感
    紧急且重要事情优先
    巧妙地工作 而不仅仅是努力
    尽可能裁掉无结果的任务
    在早晨干有创造性的工作
    一次只专注一件事
    为事情设立最终期限
    尽可能多地授权给他人
    将小事集合起来一次解决