CentOS下搭建svn服务器


1.1
 安装SVN服务器端
yum install subversion
1.2 查看是否安装成功
svnserve –version
创建SVN版本库
mkdir /opt/svn
mkdir /opt/svn/repos
svnadmin create /opt/svn/repos
3 配置SVN
创建版本库后,在/opt/svn/repos目录下会生成配置文件目录conf
cd /opt/svn/repos/conf
该目录下有 authz passwd svnserve.conf 三个配置文件
3.1 svnserve.conf文件
分别配置以下5项(顶格写,行开始处不留空格,下同。注意:要在[general]下,不是文件结尾):
anon-access = none 设置未认证用户无访问权限
auth-access = write 设置认证用户具有写权限
password-db = passwd 指定用户文件,该文件保存用户名和密码
authz-db = authz 指定权限配置文件,该文件可以细粒度的控制版本库某个文件或目录的访问
realm = /opt/svn/repos 指定版本库的认证域(认证命名空间),即在登录时提示的认证域名称
3.2 passwd文件
设置用户名和密码
realwall = 111111
3.3 authz文件

[groups]
project_p = pm
project_s = server1,server2,server3
project_c = client1,client2,client3
project_t = test1,test1,test1

[/]
realwall = rw
@project_p = rw
* =

[/server]
@project_p = rw
@project_s = rw
* =

[/client]
@project_p = rw
@project_c = rw
* =

[/doc]
@project_p = rw
@project_s = r
@project_c = r
@project_t = r
* =

说明:以上信息表示,只有project_p用户组有根目录的读写权。r表示对该目录有读权限,w表示对该目录有写权限,rw表示对该目录有读写权限。最后一行的* =表示,除了上面设置了权限的用户组之外,其他任何人都被禁止访问本目录。这个很重要,一定要加上!

配置authz时,注意svnserve启动参数-r所指定的目录,设repos1版本库路径为/opt/svn/repos1。
a.当-r直接指定某版本库(称为单库svnserve模式),即svnserve -d -r /opt/svn/repos1
这种情况下一个svnserve只能为一个版本库工作,authz配置成
[repos1:/]
user1 = rw
就是错的,而应该是
[/]
user1 = rw
使用类似这样的URL:svn://192.168.0.1/ 即可访问repos1。
b.当-r指定到版本库的上级目录(称之为多库svnserve方式),即svnserve -d -r /opt/svn
这种情况,一个svnserve可以为多个版本库工作,这时如果想限制指定库的指定目录,就应该指定具体的库,像这样
[repos1:/]
如果此时你还用[/],则表示所有库的根目录,同理,[/src]表示所有库的根目录下的src目录。
使用类似这样的URL:svn://192.168.0.1/project1 即可访问project1。
此外,对中文目录进行权限控制时,要将权限文件authz改为无BOM的utf-8格式。

停止svnserve

ps aux | grep svnserve

kill -9 pid(即正在运行的svnserve对应的pid)

参考资料
http://blog.csdn.net/tianlesoftware/article/details/6119231
http://svndoc.iusesvn.com/svnbook/1.4/svn.serverconfig.svnserve.html
authz文件权限控制 http://doc.iusesvn.com/show-8-1.html

MATLAB读写视频文件

做视频实验最基本的就是视频的读写操作了,写了两个简单的函数来读写视频。

读视频函数readVideo输入读取文件的路径+文件名,输出帧结构数组,用官方的话说就是 Array of frame structures, each of which contains fields cdata and colormap.

%// read vedio
function source = readVideo(filePath)
readerobj = VideoReader(filePath);

%// Read in all video frames.
vidFrames = read(readerobj);

%// Get the number of frames.
% numFrames = get(readerobj, 'NumberOfFrames');
[d1, d2, d3, d4] = size(vidFrames);

%// Create a MATLAB movie struct from the video frames.
for k = 1 : d4
     source(k).cdata = vidFrames(:,:,:,k);
     source(k).colormap = [];
end

写视频函数,cutVideo截取源视频的某部分,写到目标路径,写入的视频格式为avi

%// cut and write video file 
%// srcFile can be avi or mpg, destFile to be avi
function cv = cutVideo(srcFile, destFile, startIndex, endIndex)

source = readVideo(srcFile);
source2 = source(startIndex:endIndex);
writerObj = VideoWriter(destFile);
open(writerObj);
writeVideo(writerObj,source2);
close(writerObj);

cv = source2;

 

参考文章:

http://www.mathworks.cn/cn/help/matlab/ref/videowriter.writevideo.html

JavaScript数组方法map

map方法是我最喜欢的方法了,虽然简单,但功能强大,用起来非常方便。在ECMPAScript 5中也添加了这个方法。

map()方法功能:将调用的数组的每个元素传递给指定的函数,并返回一个数组,该数组由函数的返回值构成。

注:map返回的是新数组,它不修改调用的数组。

为了兼容不支持map的浏览器,developer.mozilla.org上给出了map兼容性解决方法。

// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.com/#x15.4.4.19
if (!Array.prototype.map) {
  Array.prototype.map = function(callback, thisArg) {

    var T, A, k;

    if (this == null) {
      throw new TypeError(" this is null or not defined");
    }

    // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
    var O = Object(this);

    // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
    // 3. Let len be ToUint32(lenValue).
    var len = O.length >>> 0;

    // 4. If IsCallable(callback) is false, throw a TypeError exception.
    // See: http://es5.github.com/#x9.11
    if (typeof callback !== "function") {
      throw new TypeError(callback + " is not a function");
    }

    // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
    if (thisArg) {
      T = thisArg;
    }

    // 6. Let A be a new array created as if by the expression new Array(len) where Array is
    // the standard built-in constructor with that name and len is the value of len.
    A = new Array(len);

    // 7. Let k be 0
    k = 0;

    // 8. Repeat, while k < len
    while(k < len) {

      var kValue, mappedValue;

      // a. Let Pk be ToString(k).
      //   This is implicit for LHS operands of the in operator
      // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
      //   This step can be combined with c
      // c. If kPresent is true, then
      if (k in O) {

        // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
        kValue = O[ k ];

        // ii. Let mappedValue be the result of calling the Call internal method of callback
        // with T as the this value and argument list containing kValue, k, and O.
        mappedValue = callback.call(T, kValue, k, O);

        // iii. Call the DefineOwnProperty internal method of A with arguments
        // Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
        // and false.

        // In browsers that support Object.defineProperty, use the following:
        // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });

        // For best browser support, use the following:
        A[ k ] = mappedValue;
      }
      // d. Increase k by 1.
      k++;
    }

    // 9. return A
    return A;
  };      
}