Login|Sign Up
大家每天都有一个好心情 :)

最新博文

rails中实现后台运行 定期运行     [ruby]

http://railscasts.com/episodes/127-rake-in-background

deliver mail in background

system("rake balhblahblah &") #直接系统调用后台运行

 

http://railscasts.com/episodes/128-starling-and-workling

Starling 

starling -d -P  tmp/pids/starling.pid -q log/

starling as a messagequeue # server / client memcache as the server

例子很cool starling 比较酷 

http://rubyforge.org/projects/starling #听说是推特的一个项目

 

 

http://railscasts.com/episodes/129-custom-daemon

BackgroundJob

BackgrounDRb

Background Fu

http://www.ibm.com/developerworks/cn/web/1003_yekai_railsarch/

# 介绍了一个实例

http://vanadiumlin.iteye.com/blog/1456947 # message queue的列表

 

https://github.com/robey/kestrel # starling的后续发展

 

https://github.com/jmettraux/rufus-scheduler # 定时功能,自我标榜没有替代产品,不过确实不错

2012-5-17 12:14:42

protobuf union example     [java]

https://developers.google.com/protocol-buffers/docs/techniques?hl=zh-CN#union

import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class Test {
	public static void main(String args[]) throws IOException{
		//Union.OneMessage.Type.FOO;
		
		//Union.OneMessage
		Union.OneMessage.Builder b = Union.OneMessage.newBuilder();
		b.setType(Union.OneMessage.Type.FOO);
		
		Union.Foo.Builder fb = Union.Foo.newBuilder();
		fb.setName("i try");
		
		b.setFoo(fb.build());
		
		Union.OneMessage msg = b.build();
		FileOutputStream fout = new FileOutputStream("c:/proto.txt");
		msg.writeTo(fout);
		fout.close();
		System.out.println("done");
		
		FileInputStream str = new FileInputStream("c:/proto.txt");

		Union.OneMessage msg2 = Union.OneMessage.parseFrom(str);
		//Union.OneMessage msg2 = Union.OneMessage.parseFrom(strContent.toString());
		System.out.println(msg2.getFoo().getName());
		
		
		
	}
}

// parse 的过程
public Builder clear() {
        super.clear();
        type_ = Union.OneMessage.Type.FOO;
        bitField0_ = (bitField0_ & ~0x00000001);
        if (fooBuilder_ == null) {
          foo_ = Union.Foo.getDefaultInstance();
        } else {
          fooBuilder_.clear();
        }
        bitField0_ = (bitField0_ & ~0x00000002);
        if (barBuilder_ == null) {
          bar_ = Union.Bar.getDefaultInstance();
        } else {
          barBuilder_.clear();
        }
        bitField0_ = (bitField0_ & ~0x00000004);
        if (bazBuilder_ == null) {
          baz_ = Union.Baz.getDefaultInstance();
        } else {
          bazBuilder_.clear();
        }
        bitField0_ = (bitField0_ & ~0x00000008);
        return this;
      }

可见使用union即便在开始的parse,效率也是个问题

至少要遍历所有的属性

http://lists.jboss.org/pipermail/netty-users/2010-January/001876.html # 有java代码

http://stackoverflow.com/questions/9121612/protocol-buffers-detect-type-from-raw-message # 推荐了三种实现

http://www.mail-archive.com/protobuf@googlegroups.com/msg03627.html # 还是推荐了union对于有限个类型

 

2012-5-10 16:50:55

protobuf java as3 自适应 description     [flash]

http://code.google.com/p/protobuf

https://developers.google.com/protocol-buffers/docs/techniques?hl=zh-CN#union
https://developers.google.com/protocol-buffers/docs/techniques?hl=zh-CN#self-description

http://code.google.com/p/protoc-gen-as3/wiki/FAQ
http://code.google.com/p/protoc-gen-as3/wiki/AdvancedUsage#AMF_Wrapper

 

//message.proto
import "options.proto";
message Person {
    option (as3_amf_alias) = "JK";
    required string name = 1;
    required int32 id = 2;
}

//Test.java
public class Test{
    public static void main(String args[]){
        Message.Person.Builder b = Message.Person.newBuilder();
        b.setName("hello world");
        b.setId(123);
        Message.Person p = b.build();
        byte [] bs = p.toByteArray();
        System.out.println(bs.length);
        for(int i = 0; i < bs.length; i++){
            System.out.print(Integer.toHexString(bs[i]));
            System.out.print(" , ");
        }
        System.out.println("");
        System.out.println(String.valueOf(bs));
        System.out.println("hello world");
    }
}

 生成protobuf的类

protoc --java_out=. message.proto

/usr/local/protobuf/bin/protoc --plugin=/home/kk.shen/mybin/protoc-gen-as3/protoc-gen-as3 --as3_out=. message.proto

# 需要options.proto protoc-gen-as3 项目中有 和google的proto 官方项目自带

javac -sourcepath . -classpath protobuf-java-2.4.1.jar -classpath protoc-gen-as3.jar Test.java
java -cp .:protobuf-java-2.4.1.jar Test

2012-5-7 16:53:40

安装使用postgresql     [数据库]

sudo emerge -av postgresql-server

http://www.postgresql.org/docs/9.1/interactive/index.html


sudo -u postgres initdb /var/lib/postgresql/9.1/data
sudo -u postgres postgres -D /var/lib/postgresql/9.1/data/
sudo -u postgres psql

psql -U postgres -h 127.0.0.1 mydb # psql会用当前用户作为用户名 psql --help

\? , \h , \h select , \q , \d TABLENAME , \d+ TABLENAME


\db # list tablespaces
http://www.postgresql.org/docs/9.1/interactive/tutorial-accessdb.html

create table  , drop table
http://www.postgresql.org/docs/9.1/interactive/tutorial-table.html

insert data
http://www.postgresql.org/docs/9.1/interactive/tutorial-populate.html

select data
http://www.postgresql.org/docs/9.1/interactive/tutorial-select.html

join table select
http://www.postgresql.org/docs/9.1/interactive/tutorial-join.html

postgresql 全文搜索
http://www.postgresql.org/docs/9.1/interactive/textsearch.html


碰到了很多问题,应该拿本书看看,学习学习

2012-4-26 14:36:41

 1 2 3 >  Last ›

 
Google 本站内容:
welcome
测试下新浪微博 @沈禾爸
 
Copyright (c) 2007-2012 kk. All Rights Reserved. 版权所有        联系邮箱:admin@kkito.cn    QQ29690087
沪ICP备07503863号        您是第 662242 位访客        RSS订阅
Powered by PHP && CodeIgniter && Zend Framework