星期四, 十二月 22, 2011

html 模拟终端效果 style.

pre {
display: block;
width: 95%;
background: #222;
border-left: 6px solid #1664d9;
color: #0c0;
padding: 10px;
overflow:auto;
}

星期二, 十二月 13, 2011

Linux查询网络连接并搜索统计。

lsof -i4 |grep -c -E '10.1.11.12|10.1.11.24'
grep -E 选项可以同时搜索多个字符串,用符号 |隔开。

lsof -i4 只显示TCP IPV4的记录,也就是网络连接数目了。


星期二, 十一月 22, 2011

Android repo sync hang

可以利用:
repo --debug sync -j 12
来看看错误原因。
往往需要多次同步才可以。


星期六, 十月 29, 2011

How to fix problem of incompatibility between GCC 4.6 and Android 2.3

How to fix problem of incompatibility between GCC 4.6 and Android 2.3
http://buildall.wordpress.com/2011/05/27/how-to-fix-problem-of-incompatibility-between-gcc-4-6-and-android-2-3-gingerbread/

Hello everybody. Let's see how we can fix one problem that can happen when you try to compile the Android 2.3 after you already have installed GCC 4.6.

During Android compilation you can receive the following error message:

host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function 'void android::RefBase::weakref_type::trackMe(bool, bool)':
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing 'const android::RefBase::weakref_impl' as 'this' argument of 'void android::RefBase::weakref_impl::trackMe(bool, bool)' discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
make: *** Waiting for unfinished jobs....

To fix that, open a terminal and run (assuming you are in the folder android):

gedit frameworks/base/libs/utils/Android.mk

Change the line:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

To:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

After that, save the file and recompile the Android again.

That's it. See you next time.


星期二, 十月 25, 2011

如何安装Guest Addtions 在VirtualBox 和utunbu 11.10。

首先必须安装pae头文件


You can follow the steps below to install the guest additions program on your ubuntu 11.10:

1) Create a temp directory in your home directory
2) Copy the whole file into the temp directory from /media/VBo..
3) Sudo apt-get install linux-headers-3.0.0-12-generic-pae
 *Actually you get to make sure what kernel version on your machine
 *After that, make sure your get "linux-headers-3.0.0-12-generic-pae" tree in "usr/src"
4) Install the guest additions utility.

然后运行autorun.sh 编译并安装对应模块。
具体编译log可以查看/var/log/vboxadd-install.log
/usr/bin/VBoxClient× 系列软件,可以运行。
启动桌面后,即可粘帖了

星期一, 五月 23, 2011

window xp发现所有进程及其命令行参数

WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid



星期五, 五月 06, 2011

Java WebStart和可执行jar文件如何读取外部jar文件包含的资源。

如何使用classLoad 读取外部jar文件中的资源?

网络运行的Java Webstart的JNLP的写法里和可执行的jar文件里,都包含了对外部jar文件的依赖的语法
比如JNLP 语法:
 <jar href="lib/hsqldb.jar"/>

可执行jar文件MANIFEST.MF里包含的语句:
Class-Path:
lib/appframework-1.0.3.jar
lib/swing-worker-1.1.jar

常见的是把图片等其他非class文件组织打包成一个jar文件,方便程序中使用。

在可执行的jar文件中,只需要一行代码就可以得到这些资源。

比如在lib/appframework-1.0.3.jar包含一个打印格式文件jrxml
都放在report/目录下,一个工作单打印文件WorkOrder.jrxml.

 必须使用Thread.currentThread().getContextClassLoader()定制的ClassLoader来调用
  或this.getClass().getClassLoader()

  注意this的意思必须是个运行时的类实例,而不能是静态类的.class.getClass()的方法。

        InputStream test=null;
        try
        {
        test = Thread.currentThread().
getContextClassLoader().getResourceAsStream("report/WorkOrder.jrxml"); 
或者:
        test =new YouCurrentClassName().getClass().getClassLoader().
getResourceAsStream("report/WorkOrder.jrxml"); 
        if(test!=null)
        {  
        InputStreamReader inr=new InputStreamReader(test,"UTF-8");
        BufferedReader br=new BufferedReader(inr);
        String line="";
        while( (line=br.readLine())!=null)
        {
         System.out.println(line);  
        }


另外不在classpath里的jar包的资源调用。

可以使用java.net.URL("jar:file://d:/temp/test.jar!");的语法来读取。
    public JarFile tJar = null;
    public JarURLConnection uc = null;
   String resourcepath="image/log.jpg";

          URL u = new URL("jar:file:lib/ReportResource_jrxml.jar!/");
            uc = (JarURLConnection)u.openConnection();
            tJar = uc.getJarFile();
//            Enumeration entries = tJar.entries();
//            while (entries.hasMoreElements()) {
//                ZipEntry entry = (ZipEntry) entries.nextElement();
//                System.out.println(entry.getName());
//
//            }
            input = tJar.getInputStream(tJar.getEntry(resourcepath));

星期四, 五月 05, 2011

判断内部IP地址和外部IP地址(private IP address or public IP Address)

/*
* Judge IP Address is private or public address
*/

public static boolean isInnerIP(String ipAddress){    
        boolean isInnerIp = false;    
        long ipNum = getIpNum(ipAddress);    
        /**   
        私有IP:A类  10.0.0.0-10.255.255.255   
               B类  172.16.0.0-172.31.255.255   
               C类  192.168.0.0-192.168.255.255   
        当然,还有127这个网段是环回地址   
        **/
   
        long aBegin = getIpNum("10.0.0.0");    
        long aEnd = getIpNum("10.255.255.255");    
        long bBegin = getIpNum("172.16.0.0");    
        long bEnd = getIpNum("172.31.255.255");    
        long cBegin = getIpNum("192.168.0.0");    
        long cEnd = getIpNum("192.168.255.255");    
        isInnerIp = isInner(ipNum,aBegin,aEnd) || isInner(ipNum,bBegin,bEnd) || isInner(ipNum,cBegin,cEnd) || ipAddress.equals("127.0.0.1");    
        return isInnerIp;               
}   

private static long getIpNum(String ipAddress) {    
    String [] ip = ipAddress.split("\\.");    
    long a = Integer.parseInt(ip[0]);    
    long b = Integer.parseInt(ip[1]);    
    long c = Integer.parseInt(ip[2]);    
    long d = Integer.parseInt(ip[3]);    
   
    long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;    
    return ipNum;    
}   


private static boolean isInner(long userIp,long begin,long end){    
     return (userIp>=begin) && (userIp<=end);    
}  

星期五, 四月 15, 2011

改变JDE(julian)日期为标准ISO 格式(年-月-日)

这里:WATRDJ  是Order Date.
WASTRT 是Order StartDate,都是6个长度的numberic 的字段。
通过下列表达式可以将其转换为标准的 yyyy-MM-dd格式。

TIMESTAMP(DATE(DIGITS(DEC(WATRDJ + 1900000,7,0))),TIME('00:00:00')) as t1 ,
char(DATE(CHAR(DEC(WASTRT + 1900000,7,0))),iso)

星期五, 三月 25, 2011

如何删除JDialog右上角的X 关闭按钮

<code>
import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Testing
{
public void buildGUI()
{
JDialog.setDefaultLookAndFeelDecorated(true);

JDialog d = new MyDialog();
d.setModal(true);
d.getRootPane().setDefaultButton(null);


JPanel p = new JPanel(new GridBagLayout());

JButton btn = new JButton("Exit");

p.add(btn,new GridBagConstraints());

d.getContentPane().add(p);

d.setSize(400,300);

d.setLocationRelativeTo(null);

btn.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

System.exit(0);

}

});

d.setVisible(true);

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable()
{
public void run(){
new Testing().buildGUI();
}
});
}
}
class MyDialog extends JDialog
{
public MyDialog()
{
System.out.println("....");
removeX(this);
}
public void removeX(Component comp)
{
if (comp instanceof JButton)
{
System.out.println("..."+comp);
Icon i=((JButton)comp).getIcon();
System.out.println("..2."+i.getClass());

//System.out.println("...2"+(AbstractButton)comp.getDefaultIcon());
comp.getParent().remove(comp);
}

if (comp instanceof Container)
{
Component[] comps = ((Container)comp).getComponents();
for(int x = 0, y = comps.length; x < y; x++)
{
removeX(comps[x]);
}
}
}
}
</code>

星期一, 二月 07, 2011

VIM 大小写不敏感搜索.

一个是用全局变量:
:set ic  (:set ignorecase) 忽略大小写
:set noic (:set noignorecase) 大小写敏感

或者使用:
/\cword.用前置模式来搜索,也可以


星期三, 一月 12, 2011

ECL 10.7.1 如何才能正确打印出汉字

ecl.exe>(load "d:\\temp\\foo.lsp" :external-format :CP936)

foo.lsp文件内容
;foo.lsp
(ext::stream-external-format-set *standard-input* :CP936)
(ext::stream-external-format-set *standard-output* :CP936)

(print (length "好吧"))

(print "TEST" *standard-output*)
(princ "好吧" *standard-output*)
(format t "~%汉字来也")

这个代码只能在文件中执行,如果在ecl console里逐行敲入这些代码,反而出现错误:
ECL (Embeddable Common-Lisp) 10.7.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level in: #<process TOP-LEVEL>.
> (ext::stream-external-format-set *standard-input* :CP936)

> (ext::stream-external-format-set *standard-output* :CP936)

> (format t "汉字来也")
鹤酪
NIL
> (format t "汉字来也")
鹤酪
NIL
>

星期四, 一月 06, 2011

LISP在package如何访问TOPLEVEL定义的全局变量(Global Variable)?

如果在一个main.lisp中分别(load "*....lisp"),载入定义的package或者一些全局的数据.
往往会出现如下场景类似的问题:

 CL-USER> (defvar foo 108) FOO CL-USER> foo 108 CL-USER>
CL-USER> (in-package :asdf) #<PACKAGE "ASDF"> ASDF>
The variable FOO is unbound. [Condition of type UNBOUND-VARIABLE]

避免这个情况,就是用如下引用方式:
ASDF> cl-user::foo 108 ASDF>