星期三, 七月 25, 2012

如何用SVG显示汉字。只需要注意HTML需要用UTF-8格式保存即可.

<html> 
<body> 
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas> 
<script> 
var canvas = document.getElementById("canvas"); 
var ctx = canvas.getContext("2d"); 
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" + 
             "<foreignObject width='100%' height='100%'>" + 
               "<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px;color:red'>" + 
                 "<em>I</em> like <span style='color:white; text-shadow:0 0 2px blue;'>网络的上面</span>" + 
               "</div>" + 
             "</foreignObject>" + 
           "</svg>"; 
var svg = new (self.BlobBuilder || self.MozBlobBuilder || self.WebKitBlobBuilder); 
var DOMURL = self.URL || self.webkitURL || self; 
var img = new Image(); 
svg.append(data); 
var url = DOMURL.createObjectURL(svg.getBlob("image/svg+xml;charset=utf-8")); 
img.onload = function() { 
    ctx.drawImage(img, 0, 0); 
    DOMURL.revokeObjectURL(url); 
}; 
img.src = url; 
</script> 
</body> 
</html>

星期一, 七月 16, 2012

tcpdump debug http traffic and dns query.

tcpdump -vvv -s 0 -l port 53

windump -i \Device\NPF_{CDF6DEBB-8C8E-49EF-91D5-CF6A69F1FE81} -n port 80 or port 443 or port 53

adb shell tcpdump -i  wlan0 -n port 80 or port 443 or port 53

星期五, 六月 08, 2012

Android memory usage

2.名词解释
App:Application
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)

tcpdump syntax

http://danielmiessler.com/study/tcpdump/

星期二, 四月 03, 2012

POI 3.7如何实现cell的填充颜色。

类似Excel 右上角填充颜色的效果。
必须在setCellValue之后,再调用setCellStyle的语句。
顺序不能错误,否则效果不如意。
        style = wb.createCellStyle();
        style.setFillForegroundColor(HSSFColor.YELLOW.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cell = row.createCell((short) 2);
        cell.setCellValue("X");
        cell.setCellStyle(style);

如何在JSP里实现Streaming content,流失内容,让内容逐渐显示

<%@page buffer="none"%>
2.在out.println一些之后使用out.flush().

这样在浏览器内就显示出来效果了,逐渐显示,而不是全部一下显示了。


星期二, 三月 06, 2012

如何制作Android显示百分比数字的状态条。

main.xml

<?xml version="1.0" encoding="utf-8"?>
<!--  -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:padding="0dip"
>
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:indeterminateOnly="false"
android:layout_height="30dip"  />
<TextView
android:id="@+id/perc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#ff0000"
android:textStyle="bold"
/>
</RelativeLayout>

代码:
package wxk.com;

import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
public class ThreadDemoActivity extends Activity {
    ProgressBar bar;
    TextView percent;
    Handler handler=new Handler() {
    @Override
    public void handleMessage(Message msg) {
    bar.incrementProgressBy(5);
    percent.setText(String.format("%03d%%", bar.getProgress()));
    }
    };
    boolean isRunning=false;
    @Override
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    bar=(ProgressBar)findViewById(R.id.progress);
    percent=(TextView)findViewById(R.id.perc);
    }
    public void onStart() {
    super.onStart();
    bar.setProgress(0);

    Thread background=new Thread(new Runnable() {
    public void run() {
    try {
    for (int i=0;i<20 && isRunning;i++) {
    Thread.sleep(1000);
    handler.sendMessage(handler.obtainMessage());
    }
    }
    catch (Throwable t) {
    // just end the background thread
    }
    }
    });
    isRunning=true;
    background.start();
    }
    public void onStop() {
    super.onStop();
    isRunning=false;
    }
}

星期五, 二月 24, 2012

Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)

Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)

The default shell on most Linux operating systems is called Bash. There are a couple of important hotkeys that you should get familiar with if you plan to spend a lot of time at the command line. These shortcuts will save you a ton of time if you learn them. 

 



Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L               Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let's you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Tab Auto-complete files and folder names

星期四, 十二月 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.用前置模式来搜索,也可以