2013年12月2日星期一

Underscore collection and array useful API

1. reduce 参数 (array, memo, val, default) 以memo为初始值遍历数组array每一个值val,可以传入function参数操作memo和val, default为memo初始值 如果default不传入或者不定义,使用array第一和第二个值作为function的初始参数.
array = [0,2,4,6,8]

var x = _.reduce(array, function(memo,val){
  if(val>memo) {return val}
  return memo
},0) 
2. map, flatten, pluck map:将目标映射入新的集合,可以附带function预操作 flatten: 去掉多维数组的维度 还原为1维, 如果附带第二个boolean参数false则只减掉一个维度 pluck: 将指定key的值从json格式的数据集合中拔出
    groupA = [{"name":"a1","data":101},{"name":"a2","data":102},{"name":"a3","data":103},{"name":"a4","data":104},]

    _.map(_.flatten(_.pluck(groupA,"data")),function(d){return d})


2013年10月28日星期一

[转贴]链接文件

  链接文件有点类似于Windows 的所谓快捷方式,但并不完全一样。链接有两种方式,软链接和硬链接。  软链接文件   软链接又叫符号链接,这个文件包含了另一个文件的路径名。可以是任意文件或目录,可以链接不同文件系统的文件。链接文件甚至可以链接不存在的文件,这就产生一般称之为"断链"的问题(或曰“现象",链接文件甚至可以循环链接自己。类似于编程语言中的递归。  
   [yaoyao@linux236 yaoyao]$ ls -l 
  total 0 
  lrwxrwxrwx 1 yaoyao yaoyao  5 Aug 6 17:39 1.txt ->; 3.txt 
  lrwxrwxrwx 1 yaoyao yaoyao  5 Aug 6 17:38 2.txt ->; 1.txt 
  lrwxrwxrwx 1 yaoyao yaoyao  5 Aug 6 17:39 3.txt ->; 2.txt  
上面的三个文件形成了一个递归,实质上没有任何作用。系统管理员应该避免系统出现断链或循环链接。  用ln -s 命令可以生成一个软连接,如下:  [root@linux236 test]# ln -s source_file softlink_file  在对符号文件进行读或写操作的时候,系统会自动把该操作转换为对源文件的操作,但删除链接文件时,系统仅仅删除链接文件,而不删除源文件本身。  硬链接文件   info ln 命令告诉您,硬链接是已存在文件的另一个名字(A "hard link" is another name for an existing file),这多少有些令人困惑。硬连接的命令是  ln -d existfile newfile  硬链接文件有两个限制  1、不允许给目录创建硬链接;   2、只有在同一文件系统中的文件之间才能创建链接。  对硬链接文件进行读写和删除操作时候,结果和软链接相同。但如果我们删除硬链接文件的源文件,硬链接文件仍然存在,而且保留了愿有的内容。这时,系统就“忘记”了它曾经是硬链接文件。而把他当成一个普通文件。

2013年10月20日星期日

Angular.js egghead tutorial outline

1. create a service, which can be initialised from a node
var app = angular.module("myApp", [dependencies]);

2. app exists, create a controller, controlling a node and its children
app.controller("nameCtrl", function($scope){  //xxxCtrl is naming convention
   //$scope can have function and attributes in json favor
   $scope.content = {message:"I am content"}
   $scope.foo=function(){...}
})
3. app, controler exist, directive is customised node/attribute
app.directive("name",function(){
   return {
     restrict: "E || A || M",
     $scope{ 

        element/attr : "@ || & || = ", // @attr, &attr, =attr


     }, //isolated scope, used in multiple instances of the directive

     template: '
Here is returned inner html, can do {{bindModule or value}}
', link:function(scope,element,attrs,[depended controller]) {...} //like the constructor controller: function() { foo1 = function(){} } // an API controller that other directive will depend on } }) app.directive("anotherName", function(){ require : 'name' link: function(scope,element,attrs, nameCtrl){...can invoke nameCtrl foo1} //nameCtrl - naming convention })

2013年10月10日星期四

Set proxy for npm behind corporate proxy

Use this line for http connections
$ npm config set proxy http://login:pass@host:port
Https connection simply use:
$ npm config set https-proxy http://login:pass@host:port

2013年10月9日星期三

Setting Maven behind corporate proxy

Under windows based infrastructure, the proxy setting can be found with opening  
Internet Explorer -> Tools -> Internet Options -> Connection -> LAN Settings

and there normally be a "xxxxx.xxxxx.pac' file in an entry field of the pane.

Open the file with browser and notepad if it prompts asking for what to open with and find this line at the bottom:

return "PROXY 10.65.32.100:8080";

This is the proxy setting that Maven needs to know, therefore, find the Maven setting.xml file under %M2_REPO% and add such section:


  
 
  amp
  true
  http
  JNGJSQ
  Welcome1
  10.65.32.100
  8080
  www.google.com|hub.amp.com.au
 
  
Thus the Maven should be able to connect to its central repository and starting downloading dependencies.

2013年5月30日星期四

Use one Bamboo job to call Maven build and deploy Mule applications

Bamboo normally suggests to generate artifacts in one job and consume the artifacts in the other job. In some case we need just use 1 job to do both, therefore a simple walk around will be use the command line script to directly copy the packaged zip artifacts from designated Maven 'target' locations. In a typical Mvn clean package scenariio, a Bamboo job is configured like:
A. check out codes from Stash (git based)
B. Call Maven builds for the zip artifacts
C. Copy over the code by scripts

2013年5月26日星期日

Billy Yarosh Blog: Grails Demo

Billy Yarosh Blog: Grails Demo: Developing a Grails Web Application Tutorial will : Walk through steps of creating a robust Grails web application. Application name: gr...

2013年2月25日星期一

MySql <> Progresql 自增字段问题

SERIAL类型的自增字段所使用的Postgres的序列,它从1开始,并在每次有一个SERIAL类型字段的记录插入时加一。然而,在我导入MySQL的dump文件时,这个 dump文件中的SQL将这个值定义为整型主键。我当时的情况是,我有一个到唯一主键已经到了60,而序列仍然是1。于是我的每一个插入命令都没法成功,因为根据序列产生的不是唯一ID。我当时用了一个很笨的方法解决这个问题,那就是运行了60次INSERT语句以将序列调整为适当的值,但是后来有一个熟悉Postgres的朋友教给我一个好方法。下面就是他所讲的方法:


使用telnet这样的终端程序连接到你的主机。然后启动psql程序。首先,确定表中ID的最大值。这可以用SELECT fieldname FROM tablename WHERE fieldname=MAX(fieldname);。然后使用DROP SEQUENCE table_colname_seq;删除有问题的序列,这儿table是表名,而colname是SERIAL字段的列名。然后使用CREATE SEQUENCE table_colname_seq START 61;重建序列,当然这儿的61应根据你的实际情况进行修改。
SERIAL类型的字段和MySQL中的自增唯一ID等价。当你在你的数据表中定义了一个SERIAL类型的列后,SERIAL的自增功能会被自动添加到数据库。当自增功能不能适应实际需求时,我们可以自定义唯一ID的逻辑。从MySQL向Postgres转输数据时,默认的功能已经足够了。

[zt]

2013年2月23日星期六

FuseESB Enterprise/ServiceMix安装配置

[ZT]http://www.myexception.cn/software-architecture-design/427047.html

ServiceMix安装配置:
1. 安装准备
    apache-servicemix-4.4.1-fuse-01-13.zip
    jdk.1.6.0_30(Java5不支持)
    Maven3.0.3
2. 安装配置
    解压apache-servicemix-4.4.1-fuse-01-13.zip至:C:\Apache-servicemix-4.4.1-fuse-01-13.

    默认解压后启动ServiceMix时,JBI容器时做为FuseESB的OSGi容器的一个子容器的,如果要禁用该功能,
    可进行下面的设置:
    (1) 如果已经启动过ServiceMix, 则需要删除安装目录下的data 文件夹;
    (2) 编辑etc/org.apache.karaf.features.cfg 文件,删除featuresBoot 属性中所有匹配
          jbi-*或servicemix-* 模式的值。
    (3) 重启ServiceMix。

    FuseESB默认采用的OSGi Framework是Equinox, 也可以改变为Fleix:
    修改etc/config.properties文件中的karaf.framework 属性为:felix即可。
3. 启动
    进入C:\Apache-servicemix-4.4.1-fuse-01-13\bin下,执行servicemix.bat;
4. 停止
    执行命令:
    osgi:shutdown或shutdown或Ctrl+D
5. 常见命令
    获取所有可用的命令:Tab;
    获取某一组下的可用命令:组标示符Tab(中间无空格), 如获取osgi组下的所有命令:osig"PressTab"
    获取某个命令的帮助:命令 --help, 如获取osig:shutdown命令帮助:osgi:shutdown --help
    查看FuseESB提供的例子的特性:features:list | grep examples
    安装某个例子特性:features:install examples-cxf-osgi
6. WebConsole
    默认情况下,WebConsole没有安装,可通过下面的命令检查是否安装:
    features:list | grep webconsole
    通过下面的命令进行安装:
    features:install webconsole
    浏览器访问路径:http://localhost:8181/system/console
    (1) 客制化端口:修改etc/org.ops4j.pax.web.cfg.empty.stub中: org.osgi.service.http.port=8181;

[NOTE] Different way to change http port number (from official site):

By default, the console runs on port 8181. You can change the port number by creating the properties file, etc/org.ops4j.pax.web.cfg, and adding the following property setting (changing the port number to whatever value desired):
org.osgi.service.http.port=8181


    (2) 客制化登录控制台用户名密码:修改etc/users.properties 文件, 默认用户名密码为:smx/smx.
7. 案例:部署WebService至FuseESB
    (1) 打包:
    cd C:\Apache-servicemix-4.4.1-fuse-01-13\examples\cxf-osgi
    mvn install
    执行该命令后将在当前目录产生target文件夹,并生成cxf-osgi-4.4.1-fuse-01-13.jar。
    (2) 部署:
    复制cxf-osgi-4.4.1-fuse-01-13.jar至ServiceMix安装目录的deploy 目录下;
    (3) 测试:
    查看WSDL文件:http://localhost:8181/cxf/HelloWorld?wsdl
    执行测试客户端:
    cd C:\Apache-servicemix-4.4.1-fuse-01-13\examples\cxf-osgi
    mvn compile exec:java
    执行结果:
    the response is =====>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <soap:Body>
             <ns2:sayHiResponse xmlns:ns2="http://cxf.examples.servicemix.apache.org/">
                  <return>Hello John Doe </return>
             </ns2:sayHiResponse>
         </soap:Body>
    </soap:Envelope>
8. 配置Eclipse Plugin:CIMERO及FuseIDE
    CIMERO :Configuration Interface for Message Routing, 一款针对与ServiceMix的Eclipse可视化工具。
    参考:http://servicemix.apache.org/cimero-editor.html
    FuseIDE : is a graphical, Eclipse-based tool for integrating software components that works
    withApache ServiceMix , Apache ActiveMQ , Apache Camel , and the FuseSource distributions.
    参考:http://fusesource.com/products/fuse-ide/
    安装:http://repo.fusesource.com/ide/

FuseESB Enterprise安装配置:
1. 安装需求:JDK1.6.0_18 or later,不支持Java5.
2. 环境变量:
    export JAVA_HOME=/usr/lib/jvm/java-1.6.0_30
    export M2_HOME=/opt/maven
    export PATH=$JAVA_HOME/bin:$PATH
    export PATH=$M2_HOME/bin:$PATH
    export MAVEN_OPTS=-Xmx512M
3. 下载安装:
    Fuse-ESB-Enterprise-7.0.0.fuse-beta-052-windows-installer.exe
    双击执行安装。
4. 启动ESB(Linux):
     (1) 启动方式1:进入安装目录下的bin目录下,执行:./fuseesb
     (2) 启动方式2-Server Mode:进入安装目录下的bin目录下,执行:./fuseesb server
     (3) 启动方式3-Client Mode: 进入安装目录下的bin目录下,执行:./fuseesb client
5. 关闭ESB(Linux):
     (1) Client或默认方式下启动时:shutdown -f或Ctrl+d;
     (2) Server方式下启动时:进入安装目录下的bin目录下,执行:./stop或./stop admin instanceName
     (3) 如果etc/org.apache.karaf.shell.cfg配置文件中的sshHost不是默认值:0.0.0.0,在关闭ESB时需要使用下
     面的方式:./stop -h hostName

New Start

I hope this blog will record my path to the ultimate goal of my career.