2012-11-29

蛋痛的 netty UDP receiveBufferSize

netty 的 NioDatagramWorker 中分配了接收包缓存的最大大小,默认是 768Bytes,蛋痛的是第一次接收 768B后第二次缓存被扩展到 768B*2 buffer 中前768B是第一个包的前面部分数据,后768B是第二个包的前部分数据。
比较奇怪的是:
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/socket/DatagramChannelConfig.html
里面说了个 receiveBufferSize,但是设置后无效,经过多次尝试后发现必须要设置 receiveBufferSizePredictor 或者 receiveBufferSizePredictorFactory 才能够改变这个接收包缓存的大小。
如:

bootstrap.setOption("receiveBufferSize", 1048576);
bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(1048576));
// bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(1048576));

吐槽 netty 另外一个蛋痛的地方。在接收到包回写返回包时没有强制发送的方法,必须要等整个 messageReceived 方法返回以后才会把包写出去。如:
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  ...
  e.getChannel().write(responsePacket); // not send out now
  Thread.sleep(30000L);
  ...
}
上面这块代码中 responsePacket 不是在回写的时候马上发出去的,而是要等 30秒方法结束后才发出去。
当然咯,这样也强制你在接收到包以后以新的线程来处理数据,但是至少在文档里也说清楚嘛。

//EOF Read More...

2012-10-17

Wireshark SMGP protocol decoder (lua)

Wireshark 解析中国电信的 SMGP 协议的 lua 脚本。

-- SMGP.lua
-- SMGP protocol
-- author: h_Davy
do
 local p_SMGP = Proto("SMGP","SMGP","SMGP Protocol")
 local f_Length = ProtoField.uint32("SMGP.length","Packet Length",base.DEC)
 local f_CommandId = ProtoField.uint32("SMGP.RequestId","Request ID",base.HEX,{
  [1]="Login",      [0x80000001]="LoginResp",
  [2]="Submit",     [0x80000002]="SubmitResp",
  [3]="Deliver",    [0x80000003]="DeliverResp",
  [4]="ActiveTest", [0x80000004]="ActiveTestResp",
  [5]="Forward",    [0x80000005]="ForwardResp",
  [6]="Exit",       [0x80000006]="ExitResp",
  [7]="Query",      [0x80000007]="QueryResp"})
 local f_SequenceId = ProtoField.uint32("SMGP.sequenceId","Sequence ID",base.DEC);
 local f_ClientID = ProtoField.string("SMGP.ClientID","ClientID")
 local f_Authenticator = ProtoField.bytes("SMGP.Authenticator","Authenticator")
 local f_LoginMode = ProtoField.uint8("SMGP.LoginMode","Login Mode",base.DEC)
 local f_TimeStamp = ProtoField.uint32("SMGP.TimeStamp","TimeStamp",base.DEC)
 local f_Version = ProtoField.uint8("SMGP.Version","Version",base.HEX)
 local f_Status = ProtoField.uint32("SMGP.Status","Status",base.DEC,{[0]="OK"})
 local f_MsgType = ProtoField.uint32("SMGP.MsgType","MsgType",base.DEC,{[0]="MO",[6]="MT",[7]="P2P"})
 local f_NeedReport = ProtoField.uint32("SMGP.NeedReport","NeedReport",base.DEC,{[0]="N",[1]="Y"})
 local f_Priority = ProtoField.uint32("SMGP.Priority","Priority",base.DEC)
 local f_ServiceID = ProtoField.string("SMGP.ServiceID","ServiceID")
 local f_FeeType = ProtoField.string("SMGP.FeeType","FeeType")
 local f_FeeCode = ProtoField.string("SMGP.FeeCode","FeeCode")
 local f_FixedFee = ProtoField.string("SMGP.FixedFee","FixedFee")
 local f_MsgFormat = ProtoField.uint32("SMGP.MsgFormat","MsgFormat",base.DEC,{
  [0]="ASCII",[3]="Card",[4]="Binary",[8]="UCS2",[15]="GB18030",[246]="SIM"})
 local f_ValidTime = ProtoField.string("SMGP.ValidTime","ValidTime")
 local f_AtTime = ProtoField.string("SMGP.AtTime","AtTime")
 local f_SrcTermID = ProtoField.string("SMGP.SrcTermID","SrcTermID")
 local f_ChargeTermID = ProtoField.string("SMGP.ChargeTermID","ChargeTermID")
 local f_DestTermIDCount = ProtoField.uint32("SMGP.DestTermIDCount","DestTermIDCount",base.DEC)
 local f_DestTermID = ProtoField.string("SMGP.DestTermID","DestTermID")
 local f_MsgLength = ProtoField.uint8("SMGP.MsgLength","MsgLength",base.DEC)
 local f_MsgContent = ProtoField.string("SMGP.MsgContent","MsgContent")
 local f_MsgID = ProtoField.bytes("SMGP.MsgID","MsgID")
 local f_IsReport = ProtoField.uint8("SMGP.IsReport","IsReport",base.DEC)
 local f_RecvTime = ProtoField.string("SMGP.RecvTime","RecvTime")

 p_SMGP.fields = {f_Length,f_CommandId,f_SequenceId,f_ClientID,f_Authenticator,
 f_LoginMode,f_TimeStamp,f_Version,f_Status,f_MsgType,f_NeedReport,f_Priority,
 f_ServiceID,f_FeeType,f_FeeCode,f_FixedFee,f_MsgFormat,f_ValidTime,f_AtTime,
 f_SrcTermID,f_ChargeTermID,f_DestTermIDCount,f_DestTermID,f_MsgLength,f_MsgContent,
 f_MsgID,f_IsReport,f_RecvTime}

 local data_dis = Dissector.get("data")
 --
 local function SMGP_Login(buf,pkt,t)
  t:add(f_ClientID,buf(12,8))
  t:add(f_Authenticator,buf(20,16))
  t:add(f_LoginMode,buf(36,1))
  t:add(f_TimeStamp,buf(37,4))
  t:add(f_Version,buf(41,1))
 end
 --
 local function SMGP_LoginResp(buf,pkt,t)
  t:add(f_Status,buf(12,4))
  t:add(f_Authenticator,buf(16,16))
  t:add(f_Version,buf(32,1))
 end
 --
 local function SMGP_Submit(buf,pkt,t)
  t:add(f_MsgType,buf(12,1))
  t:add(f_NeedReport,buf(13,1))
  t:add(f_Priority,buf(14,1))
  t:add(f_ServiceID,buf(15,10))
  t:add(f_FeeType,buf(25,2))
  t:add(f_FeeCode,buf(27,6))
  t:add(f_FixedFee,buf(33,6))
  t:add(f_MsgFormat,buf(39,1))
  t:add(f_ValidTime,buf(40,17))
  t:add(f_AtTime,buf(57,17))
  t:add(f_SrcTermID,buf(74,21))
  t:add(f_ChargeTermID,buf(95,21))
  t:add(f_DestTermIDCount,buf(116,1))
  t:add(f_DestTermID,buf(117,21))
  local v_msgLen = buf(138,1)
  t:add(f_MsgLength,v_msgLen)
  v_msgLen = v_msgLen:uint()
  t:add(f_MsgContent,buf(139,v_msgLen))
 end
 --
 local function SMGP_SubDelvResp(buf,pkt,t)
  t:add(f_MsgID,buf(12,10))
  t:add(f_Status,buf(22,4))
 end
 --
 local function SMGP_Deliver(buf,pkt,t)
  t:add(f_MsgID,buf(12,10))
  local v_IsReport = buf(22,1)
  t:add(f_IsReport,v_IsReport)
  v_IsReport = v_IsReport:uint()
  t:add(f_MsgFormat,buf(23,1))
  t:add(f_RecvTime,buf(24,14))
  t:add(f_SrcTermID,buf(38,21))
  t:add(f_DestTermID,buf(59,21))
  local v_msgLen = buf(80,1)
  t:add(f_MsgLength,v_msgLen)
  v_msgLen = v_msgLen:uint()
  if v_IsReport == 1 then
   --
   t:add(f_MsgID,buf(84, 10)):append_text(' (Submit MsgID)')
   t:add(f_MsgContent,buf(94,v_msgLen-13))
  else
   t:add(f_MsgContent,buf(81,v_msgLen))
  end
 end
 --
 local function SMGP_dissector(buf,pkt,root)
  local buf_len = buf:len();
  if buf_len < 8 then return false end
  local v_length = buf(0,4)
  local v_command = buf(4,4)
  local v_sequenceId = buf(8,4)
  pkt.cols.protocol = "SMGP"
  local t = root:add(p_SMGP,buf(0,buf_len))
  t:add(f_Length,v_length)
  t:add(f_CommandId,v_command)
  t:add(f_SequenceId,v_sequenceId)
  --
  v_command = v_command:uint()
  if v_command == 1 then
   SMGP_Login(buf,pkt,t)
  elseif v_command == 2 then
   SMGP_Submit(buf,pkt,t)
  elseif v_command == 3 then
   SMGP_Deliver(buf,pkt,t)
  elseif v_command == 0x80000001 then
   SMGP_LoginResp(buf,pkt,t)
  elseif v_command == 0x80000002 then
   SMGP_SubDelvResp(buf,pkt,t)
  elseif v_command == 0x80000003 then
   SMGP_SubDelvResp(buf,pkt,t)
  elseif v_command > 0x80000000 then
   --
  else
   t:add(f_Data,buf(20,buf_len-20))
  end
  return true
 end
 --
 function p_SMGP.dissector(buf,pkt,root)
  if SMGP_dissector(buf,pkt,root) then
  else
   data_dis:call(buf,pkt,root)
  end
 end

 tcp_table = DissectorTable.get("tcp.port")
 tcp_table:add(8890,p_SMGP)
end

//EOF Read More...

Wireshark SGIP protocol decoder (lua)

Wireshark 解析中国联通的 SGIP 协议的 lua 脚本。

-- SGIP.lua
-- SGIP protocol
-- author: h_Davy
do
 local p_SGIP = Proto("SGIP","SGIP","SGIP Protocol")
 local f_Length = ProtoField.uint32("SGIP.length","Message Length",base.DEC)
 local f_CommandId = ProtoField.uint32("SGIP.commandId","Command ID",base.HEX,{[1]="Bind",[0x80000001]="BindResp",[2]="UnBind",[3]="Submit",[0x80000003]="SubmitResp",[4]="Deliver",[0x80000004]="DeliverResp",[5]="Report",[0x80000005]="ReportResp"})
 local f_SequenceId = ProtoField.uint32("SGIP.sequenceId","Sequence ID",base.DEC);
 local f_Data = ProtoField.bytes("SGIP.Data","Data")
 local f_LoginType = ProtoField.uint8("SGIP.loginType","Login Type",base.HEX)
 local f_LoginName = ProtoField.string("SGIP.loginName","Login Name")
 local f_LoginPass = ProtoField.string("SGIP.loginPass","Login Pass")
 local f_Result = ProtoField.uint8("SGIP.result","Result",base.DEC,{[0]="OK"})
 local f_Text = ProtoField.string("SGIP.text")
 local f_SPNumber = ProtoField.string("SGIP.SPNumber","SP Number")
 local f_ChargeNumber = ProtoField.string("SGIP.ChargeNumber","Charge Number")
 local f_UserCount = ProtoField.uint8("SGIP.userCount","User Count",base.DEC)
 local f_UserNumber = ProtoField.string("SGIP.UserNumber","User Number")
 local f_CorpId = ProtoField.string("SGIP.CorpId","CorpId")
 local f_ServiceType = ProtoField.string("SGIP.ServiceType","Service Type")
 local f_FeeType = ProtoField.uint8("SGIP.FeeType","Fee Type")
 local f_FeeValue = ProtoField.string("SGIP.FeeValue","Fee Value")
 local f_GivenValue = ProtoField.string("SGIP.GivenValue","Given Value")
 local f_AgentFlag = ProtoField.uint8("SGIP.AgentFlag","Agent Flag")
 local f_MorelatetoMTFlag = ProtoField.uint8("SGIP.MorelatetoMTFlag","Morelateto MT Flag")
 local f_Priority = ProtoField.uint8("SGIP.Priority","Priority")
 local f_ExpireTime = ProtoField.string("SGIP.ExpireTime","ExpireTime")
 local f_ScheduleTime = ProtoField.string("SGIP.ScheduleTime","ScheduleTime")
 local f_ReportFlag = ProtoField.uint8("SGIP.ReportFlag","ReportFlag")
 local f_TP_pid = ProtoField.uint8("SGIP.TP_pid","TP_pid")
 local f_TP_udhi = ProtoField.uint8("SGIP.TP_udhi","TP_udhi")
 local f_MessageCoding = ProtoField.uint8("SGIP.MessageCoding","MessageCoding")
 local f_MessageType = ProtoField.uint8("SGIP.MessageType","MessageType")
 local f_MessageLength = ProtoField.uint8("SGIP.MessageLength","MessageLength")
 local f_MessageContent = ProtoField.string("SGIP.MessageContent","MessageContent")
 local f_SubmitSequenceNumber = ProtoField.uint32("SGIP.SubmitSequenceNumber","SubmitSequenceNumber")
 local f_ReportType = ProtoField.uint8("SGIP.ReportType","ReportType")
 --local f_UserNumber = ProtoField.string("SGIP.UserNumber","UserNumber")
 local f_State = ProtoField.uint8("SGIP.State","State")
 local f_ErrorCode = ProtoField.uint8("SGIP.ErrorCode","ErrorCode")
 --local f_TP_udhi = ProtoField.uint8("SGIP.TP_udhi","TP_udhi")

 p_SGIP.fields = {f_Length,f_CommandId,f_SequenceId,f_Data,f_LoginType,f_LoginName
 ,f_LoginPass,f_Result,f_Text,f_UserCount,f_SPNumber,f_ChargeNumber,f_UserNumber
 ,f_CorpId,f_ServiceType,f_FeeType,f_FeeValue,f_GivenValue,f_AgentFlag,f_MorelatetoMTFlag
 ,f_Priority,f_ExpireTime,f_ScheduleTime,f_ReportFlag,f_TP_pid,f_TP_udhi,f_MessageCoding
 ,f_MessageType,f_MessageLength,f_MessageContent,f_SubmitSequenceNumber,f_ReportType
 ,f_State,f_ErrorCode}

 local data_dis = Dissector.get("data")
 --
 local function SGIP_Bind(buf,pkt,t)
  --
  t:add(f_LoginType,buf(20,1))
  t:add(f_LoginName,buf(21,16))
  t:add(f_LoginPass,buf(37,16))
 end
 --
 local function SGIP_Submit(buf,pkt,t)
  t:add(f_SPNumber,buf(20,21))
  t:add(f_ChargeNumber,buf(41,21))
  local v_UserCount = buf(62,1)
  t:add(f_UserCount,v_UserCount)
  v_UserCount = v_UserCount:uint()
  -- 目标号码
  local v_curPos = 63
  for i=1,v_UserCount do
   t:add(f_UserNumber,buf(v_curPos,21))
   v_curPos = v_curPos+21
  end
  t:add(f_CorpId,buf(v_curPos,5))
  v_curPos=v_curPos+5
  t:add(f_ServiceType,buf(v_curPos,10))
  v_curPos=v_curPos+10
  t:add(f_FeeType,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_FeeValue,buf(v_curPos,6))
  v_curPos=v_curPos+6
  t:add(f_GivenValue,buf(v_curPos,6))
  v_curPos=v_curPos+6
  t:add(f_AgentFlag,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_MorelatetoMTFlag,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_Priority,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_ExpireTime,buf(v_curPos,16))
  v_curPos=v_curPos+16
  t:add(f_ScheduleTime,buf(v_curPos,16))
  v_curPos=v_curPos+16
  t:add(f_ReportFlag,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_TP_pid,buf(v_curPos,1))
  v_curPos=v_curPos+1
  t:add(f_TP_udhi,buf(v_curPos,1))
  v_curPos=v_curPos+1
  local v_MessageCoding=buf(v_curPos,1)
  t:add(f_MessageCoding,v_MessageCoding)
  v_MessageCoding = v_MessageCoding:uint()
  v_curPos=v_curPos+1
  t:add(f_MessageType,buf(v_curPos,1))
  v_curPos=v_curPos+1
  local v_MessageLength=buf(v_curPos,4)
  t:add(f_MessageLength,v_MessageLength)
  v_MessageLength=v_MessageLength:uint()
  v_curPos=v_curPos+4
  t:add(f_MessageContent,buf(v_curPos,v_MessageLength))
 end
 --
 local function SGIP_Deliver(buf,pkt,t)
  t:add(f_UserNumber,buf(20,21))
  t:add(f_SPNumber,buf(41,21))
  t:add(f_TP_pid,buf(62,1))
  t:add(f_TP_udhi,buf(63,1))
  local v_MessageCoding=buf(64,1)
  t:add(f_MessageCoding,v_MessageCoding)
  v_MessageCoding=v_MessageCoding:uint()
  local v_MessageLength=buf(65,4)
  t:add(f_MessageLength,v_MessageLength)
  v_MessageLength=v_MessageLength:uint()
  t:add(f_MessageContent,buf(69,v_MessageLength))
 end
 --
 local function SGIP_Report(buf,pkt,t)
  --t:add(f_SubmitSequenceNumber,buf(20,12))
  t:add(f_SubmitSequenceNumber,buf(28,4))
  t:add(f_ReportType,buf(32,1))
  t:add(f_UserNumber,buf(33,21))
  t:add(f_State,buf(54,1))
  t:add(f_ErrorCode,buf(55,1))
 end
 --
 local function SGIP_Response(buf,pkt,t)
  t:add(f_Result,buf(20,1))
 end
 --
 local function SGIP_dissector(buf,pkt,root)
  local buf_len = buf:len();
  if buf_len < 8 then return false end
  local v_length = buf(0,4)
  local v_command = buf(4,4)
  local v_sequenceId = buf(16,4)
  pkt.cols.protocol = "SGIP"
  local t = root:add(p_SGIP,buf(0,buf_len))
  t:add(f_Length,v_length)
  t:add(f_CommandId,v_command)
  t:add(f_SequenceId,v_sequenceId)
  --local dt = t:add(f_Data,buf(20,buf_len-20))
  v_command = v_command:uint()
  if v_command == 1 then
   SGIP_Bind(buf,pkt,t)
  elseif v_command == 3 then
   SGIP_Submit(buf,pkt,t)
  elseif v_command == 4 then
   SGIP_Deliver(buf,pkt,t)
  elseif v_command == 5 then
   SGIP_Report(buf,pkt,t)
  elseif v_command > 0x80000000 then
   SGIP_Response(buf,pkt,t)
  else
   t:add(f_Data,buf(20,buf_len-20))
  end
  return true
 end
 function p_SGIP.dissector(buf,pkt,root)
  -- 解析 SGIP
  if SGIP_dissector(buf,pkt,root) then
  else
   -- 使用默认输出
   data_dis:call(buf,pkt,root)
  end
 end

 tcp_table = DissectorTable.get("tcp.port")
 tcp_table:add(8801,p_SGIP)
end

//EOF Read More...

Rust

Rust是由Mozilla开发的专门用来编写高性能应用程序的系统编程语言。

(2006年开始,到2012年10月还是0.4版)

Rust创建的目的是用于替换C/C++。
有更优秀的堆栈内存管理特性。
有更简明的语法特性。

http://www.rust-lang.org

//EOF Read More...

2012-03-14

带领技术团队真难

今天才发现带领一个技术团队真难……
各种各样的问题都来了。

//EOF Read More...

2012-02-22

恒星流

恒星流,被吞噬。 //EOF Read More...

2012-02-15

PHP判断是否是移动设备

//判断是否属手机
function is_mobile() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
    $is_mobile = false;
    foreach ($mobile_agents as $device) {
        if (stristr($user_agent, $device)) {
            $is_mobile = true;
            break;
        }
    }
    return $is_mobile;
}
// EOF Read More...

2012-02-09

效率,灵活,抽象,生产率

如果把我们的对编程语言的需求总结为四个:效率,灵活,抽象,生产率。那么,C语言玩的是前两个,而C++玩的是前三个,Java和C#玩的是后两个(抽象和生产率) http://www.infoq.com/cn/news/2012/02/2012-cpp-to-learn-or-not //EOF Read More...

2010-02-24

狼性领导十大原则

狼性领导十大原则



狼性原则之一:忍辱负重
领导者必须懂得从小到大是一个对伟大原则的培育过程,要像一个母亲一样勇于牺牲。
狼性原则之二:整体至上
领导者最大的使命就是使员工听到公司强大的声音中也有自己的那一份。

狼性原则之三:自知之明
领导者必须懂得专注于一点可以使自己成为这一领域的老虎。

狼性原则之四:顺水行舟
领导者必须永远懂得是时势造英雄,而不是英雄造时势。

狼性原则之五:血浓于水
领导者必须懂得斗志是用鲜血激发出来的,鲜血形成团队牢不可破的信赖。

狼性原则之六:表里如一
领导者必须懂得所谓职业化就是利益背后的原则高于一切,法不容情。

狼性原则之七:知己知彼
领导者必须明白胜利并不是说明自己强大,而是说明自己比对手更用心。

狼性原则之八:原则第一
领导者绝不把精力放在落后的员工身上,而是把精力放在表现不错的员工身上。

狼性原则之九:团队精神
领导者必须懂得通过尊重、鼓励其他成员表现自我,整个集体定会变得强大而令人敬畏。

狼性原则之十:持续基因
领导者必须懂得超越利益的文化才是一个团队凝聚的核心。


Read More...

2009-11-29

磁盘完整映像的mount

磁盘完整映像的mount


在linux下我们常常用dd来对硬盘进行完整备份.本文告诉你如何把这个完整备份文件,mount到系统中加以利用.
dd做出来的备份,虽然没有压缩,体积巨大, 但是,我们可以把它的分区mount到系统中处理它的数据.

要mount磁盘映像,就要用到mount的-o office参数来指定分区的开始位置. offset的参数的单位是字节.
我们只要找到分区的开始位置字节数, 就能顺利的mount这个磁盘映像的分区.

可以使用fdisk来看每个分区的起始逻辑扇区号,扇区号乘以512就是我们所要的偏移值,
由下面的例子,我们可以看出有2个主分区,第2个是有效的,偏移分别是
hda1=2048*512=1048576,hda2=13672448*512=7000293376
因此mount命令分别是:
mount -o loop,offset=1048576 hda.img /mnt/hda1
mount -o loop,offset=7000293376 hda.img /mnt/hda2 

#fdisk -l -u -C 1  hda.img

Disk hda: 0 MB, 0 bytes
255 heads, 63 sectors/track, 1 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot      Start         End      Blocks   Id  System
  hda1            2048    13672447     6835200   27  Unknown
Partition 1 does not end on cylinder boundary.
  hda2   *    13672448   117208191    51767872    7  HPFS/NTFS
Partition 2 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(7295, 222, 31)


原文:http://www.anheng.com/news/29/1137.html



Read More...

2009-07-25

生日

又是一个生日了,今天去了灵隐寺爬山。
在山脚下碰到一个奸商花了我十块钱买了把香,没走几步又碰到一个奸商花了我一百换了一把香。
其实我是不想买的,不过只是他说的一句话让我买了。他说:“今天是佛的生日……”其它还说了什么我就不知道了,也没兴趣听。我只是想,既然佛和我是一天生日,那就给他施舍点好了,于是就花费了那一百。
其实,根本用不着,到山顶就丢掉了。

//EOF Read More...

2009-07-15

Nokia E71

又换了手机,这次是Nokia 的E71。
总体来说还不错,商务机,可以使用WLAN上网很好很强大。
不过细节上来说还是比不上以前的小西贴心咯,西门子的
细节上做得很人性化。
还是智能手机用起来舒服啊。花费了我2000多大洋还是比较值的。
装一个Opera Mini,装一个搜狗输入法,上网一条腿啊!我现在就是在用手机发的这篇博客。

//EOF Read More...

2009-04-11

动态创建 style 节点

在 IE 中 DOM 方式创建页面内 style 节点有点问题~ (创建出来的东西是不能修改内容的)
可用 document.createStyleSheet() 来解决:

// create style node
var _styleNode = _(u.STYLE_ID);
if (!_styleNode) {
 if (/*@cc_on!@*/0) { // is IE
  var ss = document.createStyleSheet();
  ss.cssText = _defaultStyleText;
  _styleNode = ss.owningElement; // the style node just created
  _styleNode.id = u.STYLE_ID;
 } else { // other browsers
  _styleNode = document.createElement("style");
  _styleNode.id = u.STYLE_ID;
  _styleNode.type = "text/css";
  _styleNode.innerHTML = _defaultStyleText;
  var head = document.getElementsByTagName("head")[0] || document.body;
  head.appendChild(_styleNode);
 }
}

另外,对于 link 引入 css 可用:
document.createStyleSheet("style.css");
对应:
var style = document.createElement("link");
style.href = "style.css";
style.rel = "stylesheet";
style.type = "text/css";
document.getElementsByTagName('head')[0].appendChild(style);

//EOF Read More...

2009-04-07

告别小西

清明的一个意外让我告别陪伴我四年的小西…… 伤感啊~

虽然之前也摔过很多次一点事也没有,但这次竟然摔坏了 55555……(这次也没多高的说,以前从上铺掉下去也没事的),这次摔后当时感觉没啥事,是在之后才表现出来的,估计是内伤吧~ 可怜我的小西啊!还苦苦支撑了那么久,一次关机后就再也开不了了。

要是平时我是不会这么快去买手机的(至少也要悼念我的小西一周嘛),但这段时间不能没有手机啊~

昨天就去买了个山寨的,结果没用一天我就后悔了,不能个性化刷机不说(我过多依恋小西了),竟然不支持Java(小西的很多功能都是靠Java来扩展的,Opera也用不了了),亮度调低后在阳光下根本看不见(小西背光0%在阳光下都可以看得一清二楚),…… 早知道就买之前看上的哪款 OPPO A100 了 虽然贵了好几百。

还有没有其他不爽的地方就不知道了,这些都够我不爽的了。

我估计这个我一定不会用上半年,之所以还要用半年是因为我还花了几百块钱哪,不用上半年怎么值呢 ~~!

还是老版的 SIEMENS 好,结实耐用(已经用了四年了又被摔过多次,要不是这次摔成内伤的话估计还可以继续用上两年),还可以自定个性化刷机!
被收购后的西门子怎么样就不知道了~

怀恋一下 西客站 之后可能不会有机会再去访问了~

//EOF Read More...

2009-04-04

挂青归来

在山上淋了两天雨 竟然没感冒 :D
我身体还不错嘛
//EOF Read More...

2009-03-31

Win32++: 在 Dialog 中使用 ListView

资源文件中有:

IDD_MAIN DIALOG 0, 0, 186, 95
...
{
  ...
  CONTROL         "", IDC_LSTMAIN, WC_LISTVIEW, WS_TABSTOP | WS_BORDER | LVS_ALIGNLEFT | LVS_REPORT, 7, 7, 118, 81, WS_EX_LEFTSCROLLBAR
}
另有 Dialog :
class CMainDialog : public CDialog
{
...
private:
    CListView   m_lsvMain;
};
则,在:
BOOL CMainDialog::OnInitDialog()
{
    // 加上下面这行:
    m_lsvMain.AttachDlgItem(IDC_LSTMAIN, this);
    // 用 AttachDlgItem(UINT nID, CWnd* pParent) 将Dialog的控件附加到CListView对象。
    ...

    // 添加列
    m_lsvMain.InsertColumn(0, _T("Column 0"), LVCFMT_LEFT, 60);
    //m_lsvMain.InsertColumn(1, _T("Column 1"), LVCFMT_LEFT, 60);

    // 添加项
    m_lsvMain.InsertItem(0, _T("Item 0"));
    m_lsvMain.InsertItem(1, _T("Item 1"));
    m_lsvMain.InsertItem(2, _T("Item 2"));
    m_lsvMain.InsertItem(3, _T("Item 3"));

}

注:
另外 641 中的 InsertColumn(int iCol, LPCTSTR pszColumnHeading, int iFormat, int iWidth, int iSubItem)InsertItem(int iItem, LPCTSTR pszText) 是有 BUG 的。
将 listview.h 更新到 SVN 里面最新的 749 后正常。

//EOF Read More...

2009-03-29

Win32++ CodeBlocks templates & wizard

Win32++ is a C++ library used to build windows GUI applications.
http://sourceforge.net/projects/win32-framework/
Win32 平台上的一个轻量级的 C++ GUI开发库,可以用在 GCC 编译器中。
document:
http://users.bigpond.net.au/programming/documentation.htm

自己花了点时间做了个简陋的 CodeBlocks 的新建 Win32++ 工程的模板向导。

下载:
http://dl.getdropbox.com/u/163800/libs/cxx/Win32%2B%2B/codeblocks_templ.zip

安装步骤:
1. 解包后将 wizard 下的 win32xx 目录放到 [CodeBlocks]\share\CodeBlocks\templates\wizard\ 去。
(其中 [CodeBlocks] 表示 CodeBlocks 的安装目录)
当然也可以放到用户目录中——具体参照 CodeBlocks 的 Wiki。

2. 在 [CodeBlocks]\share\CodeBlocks\templates\wizard\ 中找到 config.script 文件,用文本编辑器打开,在 function RegisterWizards() { ... } 里面加一行:

RegisterWizard(wizProject, _T("win32xx"), _T("Win32++ Application"), _T("GUI"));

3. 这样新建工程的 GUI 分类里面就有 "Win32++ GUI Application" 的选项了,按向导一步步走就可以了。
(当然,前提是你要将 Win32++ 的库引入哦!——在“编译器选项”->"Search directories"->"Compiler"里面加入)

//EOF Read More...

2009-03-28

SGU

说:"The only mission is survive!"
貌似 SGU 和 Revolution 都是 黑暗风格……
莫非是受到 BSG 的影响么?
//EOF Read More...

访问Windowz的共享

samba,当然是samba了。(好像我还没听说过不基于samba的访问方式。。。)
1.查看共享资源列表:(我这里好像匿名的不成啊!?)
$ smbtree -U username
这里username是对方的“共享用户”。默认(不使用"-U")是使用本机当前登录用户名,但注意密码还是要输入对方机器上该用户名的密码。
2.访问对方共享资源:
$ smbclient -U username //host/dir
这里username同上,"//host/dir"是用smbtree查看到的对方共享资源(光只"//host/"是不成的)。
这个smbclient是个像ftp一样的东西,如果你以前用过控制台下的ftp这个应该很容易上手 :)
(BTW:有人说可以# mount -t smbfs ...的,但我的不行啊,也没有smbmount -_-,其实我个人觉得smbclient也不错,至少我对它不算陌生)
===========================================
# mount -t smbfs ...需要在编译内核的时候加入CONFIG_SMB_FS支持 ---- 07-01-24
# mount -t cifs ... CONFIG_CIFS
//EOF Read More...

2009-03-23

格格来了

小侄女,几个月大,很漂亮,比她母亲漂亮。
今天早上教她吃面条,很可爱 :D

//EOF Read More...