Archive

Archive for the ‘Tech.Notes’ Category

javascript对时间格式化

June 17th, 2008 BianJiang No comments

JavaScript通过原型函数的封装对時間格式化函數:

<script>
    Date.prototype.format = function(format)
    {
        var o = {
            "M+" : this.getMonth()+1, //month
            "d+" : this.getDate(),    //day
            "h+" : this.getHours(),   //hour
            "m+" : this.getMinutes(), //minute
            "s+" : this.getSeconds(), //second
            "q+" : Math.floor((this.getMonth()+3)/3), //quarter
            "S" : this.getMilliseconds() //millisecond
        }
        if(/(y+)/.test(format)) {
            format=format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        }

        for(var k in o) {
            if(new RegExp("("+ k +")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
            }
        }
        return format;
    }

    showtime = new Date().format("yyyy-MM-dd hh:mm:ss");

    alert(showtime);
</script>

参考: http://www.javaeye.com/topic/183162

Categories: Tech.Notes Tags:

vim-tips

June 14th, 2008 BianJiang No comments

1   注释

a 单行注释:

0 行首
插入注释符

b 多行注释:

:m,ns/^/#/g
命令(:)从当前行(m)开始到(,)当前行的第n行(n),把行首标志(^)全部(g)替换(s) 成#(#)。
当前行可用 (.)表示。
#部分可以换成你自己想要注释符

如: java: // 可以转化为\/\/
    :m,ns/^/\/\//g

c 块注释一:

0 跳到行首
C-v 可视块模式
jjj 下移3行(即打算在这3行价注释)
I 进入插入模式(实际上是shift+i)
# 注释

再ESC一下,半秒过后就发现Visual Block的头部都出现#了!

d 块注释二:

Shift V 选中要修改的行,然后按::
:s/^/#/g

在用vi工作的时候用正则表达式,也是一件愉快的事。

另外,把选中行的前面#删除::

    :s/^#//g

Categories: Tech.Notes Tags: ,

django REMOTE_ADDR on nginx

June 14th, 2008 BianJiang No comments

1   现象

  1. Django 取得客户端IP,在本地测试良好,但是放到服务器上报错, 报错信息:

    Request Method:     POST
    Request URL:        http://www.b0rder.com/blog/8/comment/
    Exception Type:     KeyError
    Exception Value:    'REMOTE_ADDR'

错误代码:

remoteIP = request.META['REMOTE_ADDR']
  1. 服务器采用 nginx fastcgi 方式.

1.1   分析原因

  1. 报错信息KeyError,说明服务器中没有 ‘REMOTE_ADDR’, 但是我在服务器中通过 Django 自带的服务器运行正常显示:

    python manage.py runserver 7000
  2. 原因可能是 nginx 配置的问题。Google了一圈发现没有把fastcgi转换过来:

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;

1.2   解决

  1. 可以通过 nginx 的 include 简单处理:

    include /etc/nginx/fcgi.conf

1.3   我的nginx配置文件

server {
    listen 80;
    server_name www.b0rder.com b0rder.com;
    location ^~ /static  {
        alias /home/border/project/blog-app/media/;
        }
    location ^~ /media  {
        alias /home/border/lib/django/django/contrib/admin/media/;
        }
    location ^~ /books  {
        alias /home/border/books/;
        autoindex on;
        }
    location / {
        fastcgi_pass 127.0.0.1:9999;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_intercept_errors off;
        }
    access_log  /home/border/log/access.b0rder.log;
    error_log  /home/border/log/error.b0rder.log;
    }

1.4   感谢

  1. 感谢 Vingel (http://www.vingel.com/) 的友情支持。

–EOF–

Categories: Tech.Notes Tags: ,

Oracle-ORA-01045-错误

June 3rd, 2008 BianJiang No comments
  1. 问题:
    在用PL/SQL进行登录时,出现:”ora-01045 :user system lacks create session privilege; logon denied”。
  2. 原因:没有权限
    在Google找到这段的说明:
    What does “ORA-01045: user USERNAME lacks CREATE SESSION privilege;
    logon denied” mean?

    It means that the username and password with which you tried to login are known and accepted by the oracle server, but that the username doesn’t have permission to create a session. If you think this username should have permission to create sessions send mail to acisdba.

  3. 解决方法:
    用sys登入Oracle DB后,下grant create session to border;(border登录出错的用户名)

    –EOF–

Categories: Tech.Notes Tags: ,

Oracle计算时间差的方法

June 3rd, 2008 BianJiang No comments

Oracle计算时间差的方法。总结了一下:
天:
ROUND(TO_NUMBER(END_DATE - START_DATE))
小时:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24)
分钟:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60)
秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60)
毫秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 60)

–EOF–

Categories: Tech.Notes Tags: ,