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


星期三, 一月 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>

星期三, 十二月 29, 2010

ECL 10.4.1 在window 用 mingw 3.4.5 编译

ECL 10.4.1 compile under mingw for window.

first download gc 7.2
http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.2alpha4.tar.gz
展开。
然后进入msys
cd d:/gc-7.2alpha4
敲入命令:
1.首先配置
./configure --enable-shared=no --enable-static=yes --enable-cplusplus --enable-large-config --enable-parallel-mark --enable-threads=win32;make
2.开始编译
 make
3.安装到/usr/local目录下,实际的msys local目录下

success then.

cd d:/ecl-10.4.1
//./configure --prefix=/usr/local  --enable-boehm=system --enable-longdouble --enable-gengc --enable-precisegc --enable-threads --enable-unicode  CPPFLAGS=-ID:\\gc-7.2alpha4\\include LDFLAGS=-LD:\\gc-7.2alpha4\\.libs
make clean;./configure --prefix=/usr/local --enable-threads -enable-boehm  --enable-unicode ;make

MSVC:
nmake ECL_UNICODE=1 ECL_DEBUG=0

#include <ecl/ecl.h>
# include <unistd.h>
# include <pthread.h>
int main(int argc, char **argv)  {
  cl_boot(argc, argv);
  cl_object obj=c_string_to_object("\"
Hello world\"");
  cl_pprint(1,obj);
  cl_shutdown();
}
(ext::stream-external-format-
set *standard-input* :utf-8)
(ext::stream-external-format-
set *standard-output* :utf-8)

--build=pentium4-pc-mingw32
如何使用ecl.dll
使用
ecl-config --cflagsecl-config --ldflags 得到你需要传递给你的编译器的变量

发布使用ecl.dll的程序。
必须包含ecl.dll 和ucd.dat 两个文件同执行文件在同一个目录下

ucd.dat
显示汉字:

 cl_object obj=c_string_to_object("\"
Hello world你好\"");
   wxMessageBox(wxString(ecl_
base_string_pointer_safe(obj),wxConvUTF8));

ECL生成独立的可执行文件.
1.新建hello.lisp文件,包含如下代码
  (princ "Hello world!")
 (terpri)
 (quit)
2.生成object文件
(compile-file "hello.lisp" :system-p t) 
3.link成可执行文件
 (c:build-program "hello" :lisp-files '("hello.o"))

4../hello.exe


星期四, 十二月 23, 2010

如何用一个字符串作为Lisp Hashtable的key?

Lisp Hashtable默认的比较是用equa 函数,更换比较函数即可。

(setq table (make-hash-table)) =>  #<HASH-TABLE EQL 0/120 46142754>
 (setf (gethash "one" table) 1) =>  1
 (gethash "one" table) =>  NIL, false

 (setq table (make-hash-table :test 'equal)) =>  #<HASH-TABLE EQUAL 0/139 46145547>
 (setf (gethash "one" table) 1) =>  1
 (gethash "one" table) =>  1, T
 (make-hash-table :rehash-size 1.5 :rehash-threshold 0.7)

Lisp 如何得到函数返回的多个值?

 LISP很多函数返回几个值,默认是得到第一个值。其他的返回值如何得到呢?
比如parse-integer 返回2个值。
如果想的到第二个返回值,可以用(nth-value (parse-integer "20") 1)
得到2,字符串索引。

还有其他函数可以得到所有返回值。

 nth-value [already mentioned and only pertaining to multiple-vals]
 multiple-value-bind [no such thing as multiple-value-let]
 multiple-value-call
 multiple-value-setq
(multiple-value-list (floor 5 2))
得到:(2 1)

星期一, 十二月 20, 2010

Lisp打开跟踪,输出到log文件

(dribble  "c:\\temp\\output.txt") ;打开跟踪文件,所有输出都定位到c:\temp\output.text
(dribble) ;关闭跟踪输出。