Ubuntu 11.10外接显示器遇到的问题

因为自己用的T61笔记本,总感觉显示太小,于是在公司就使用外接显示器,一方面双屏可以提高效率,而且大显示器看着也舒服,但回到家中就不能用外接现实器了,有时候在公司也会连接投影仪,前不久发现一个问题,接上外部显示器开机,出现以下提示:

后来回想起来,在台式机的Ubuntu 11.04的时候也出现过这样的情况。
google一翻,大概明白了原因.
Ubuntu在开机进入桌面的时候,会调用gnome-setting-deamon 这个程序,这个程序调用当前用户的一些设置,比如字体,显示器,开机运行的程序,等等。
Could not apply the stored configuration for monitors
上面这个弹出窗口的意思是,不能应用当前monitor的设置,也就是显示器的设置有错误。
个人分析,因为我在公司使用的是双屏幕现实,在显卡自己做了设置,在关机的时候,gnome-setting-deamon 会保存上一次的设置,生成一个monitors.xml的文件。在用户目录下$user.home/.config/monitors.xml,要解决上面的问题,最简单的办法就是删除这个monitors.xml文件,重启一下电脑.

一个常见的算法题目

/**
* 假设两个字符串中所含有的字符和个数都相同我们就叫这两个字符串匹配,
* 比如:abcda和adabc,由于出现的字符个数都是相同,
* 只是顺序不同,所以这两个字符串是匹配的,
* 要求高效.
*/
public class CompareString{
    public static void main(String args[]){
       System.out.println(compare(args[0],args[1]));
    }
    public static char[] copyNew(char[] src,int exclude){
        char[] n = new char[src.length-1];
        int i=0,j=0;
        for(; i<src.length ;i++){
            if(i != exclude){
                n[j] = src[i];
                j++;
            }
        }
        return n;
    }

    public static boolean compare(String str1,String str2){
        char [] char1 = str1.toCharArray();
        char [] char2 = str2.toCharArray();
        if(char1.length != char2.length ){
            return false;
        }
        char[] _char = new char[char1.length];
        char[] tmp = char2;
        for(int i=0;i< char1.length;i++){
            int j=0;
            for(;j< tmp.length;j++){
                if(char1[i] == tmp[j]){
                   tmp = copyNew(tmp,j);
                   //处理下一个
                   break;
                }
                if(j == tmp.length-1){
                  //在第二个数组没找到相同的
                   return false;
                }
            }
        }
        return true;
    }
}
//=================
这道题有一个陷阱,上面这个解法显然不是高效的,我从编程之美中学到一个思路,
就是通过比较字符串对应的ASCII码的和,来判断

public class CompareString{
    public static void main(String args[]){
       System.out.println(compare(args[0],args[1]));
    }
    public static boolean compare(String str1,String str2){
        char [] char1 = str1.toCharArray();
        char [] char2 = str2.toCharArray();
        if(char1.length != char2.length ){
            return false;
        }
        int sum1=0,sum2=0;
        for(char c:char1){
            sum1 = sum1+(int)c;
        }
        for(char c:char2){
            sum2 = sum2+(int)c;
        }
        if(sum1 == sum2){
            return true;
        }
        return false;
    }
}
</pre>

算法小练

1.统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数

import java.io.*;
import java.util.*;
import java.lang.*;
/**
*   统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数
*/
public class TextStatisticsMain{
    public static void main(String args[]){
        TextStatisticsMain tm = new TextStatisticsMain(args[0]);
        tm.print();
    }
    private List textStatistics = new ArrayList();
    private String rootPath;
    public TextStatisticsMain(String file){
        this.rootPath = file;
    }

    public void print(){
         statistics(new File(this.rootPath));
          System.out.println("==== Statistics ====");
          System.out.println("                     ");
        for(TextStatistics t:textStatistics){
            System.out.println("File: "+t.getFileName());
            System.out.println("letCount: "+ t.getLetCount());
            System.out.println("numCount: "+ t.getNumCount());
            System.out.println("spaceCount: "+t.getSpaceCount());
            System.out.println("lines: "+t.getLines() );
            System.out.println("----------------------------");
        }
    }
    private  void statistics(File file){
        if(file.isDirectory()){
        //是目录
            for(File f:file.listFiles()){
                statistics(f);
            }
        }else{
        //是文件
          try{
            FileReader fread = new FileReader(file);
            BufferedReader lnf = new BufferedReader(fread);
            String b;
            String fileName = file.getPath();
            int letCount=0, numCount=0,spaceCount=0, lines=0;
            while ((b = lnf.readLine()) != null) {
                lines++;
                for(char c:b.toCharArray()){
                  //对比ASCII码
                  if((int)c>=48 && (int)c<=57){
                  //是数字
                   numCount++;
                  }else if((int)c==32){
                  //空格
                    spaceCount++;
                  }else if((int)c>=65 && (int)c<=90){
                  //大写字母
                    letCount++;
                  }else if((int)c>=97 && (int)c<=122){
                  //小写字母
                    letCount++;
                  }
                }
            }
                textStatistics.add(new TextStatistics(fileName,letCount,numCount,spaceCount,lines));
            }catch(Exception e){
                System.out.println(e);
            }

        }
    }
}
public class TextStatistics{
    private String fileName;
    private int letCount;
    private int numCount;
    private int spaceCount;
    private int lines;
    public TextStatistics(String fileName,int letCount,int numCount,int spaceCount,int lines ){
        this.fileName=fileName;
        this.letCount=letCount;
        this.numCount=numCount;
        this.spaceCount=spaceCount;
        this.lines=lines;
    }
    public String getFileName(){
        return this.fileName;
    }
    public int getLetCount(){
        return this.letCount;
    }
    public int getNumCount(){
        return this.numCount;
    }
    public int getSpaceCount(){
        return this.spaceCount;
    }
    public int getLines(){
        return this.lines;
    }

}

2.现在一个表,有姓名、性别、年龄,字段分别为varchar(20),varchar(20),int,
现有表中已经有上百万条记录了,在姓名上建索引,现在有一个文本文件,已经格式化为姓名、性别、年龄,写一个函数,
怎么样一次性的将该文件中的数据以最快的速度导入到数据库中。
如有函数,实现该函数:
save(Connection c,File f)
{
//直接导入文件就行了,大概思路就是这样
Statement s = c.createStatement();
s.execute("LOAD DATA INFILE '"+f.getPath()+"' INTO TABLE tablename fields terminated by ',' lines terminated by '\n'");
}

[收藏] LINUX下的21个特殊符号

1. > 重定向输出符号。
2. >> 重定向输出符号,但有追加的功能。
3. 2> 错误重定向输出符号,覆盖原文件内容。
4. 2>> 错误重定向输出符号,有文件内容追加的功能。
5. * 匹配任意字符。
6. 匹配任意一个字符。
7. | 管道符号。
8. & 后台进程符。
9. &&l 逻辑与符号。用法:命令1 && 命令2 表示如果命令1执行成功,继续执行命令2。
10. || 逻辑或符号。用法:命令1 | | 命令2 表示如果命令1执行成功,不执行命令2;但如果命令1执行失败才执行命令2。
11.逻辑非符号。排除指定范围。
12. [x-y] 表示一定的范围。
13. # 注释符。
14. ” ” 双引号表示把它所包含的内容作为普通字符,但` ` $ \ ‘ ‘ 几个符号除外。
15. ’ ’ 单引号表示把它所包含的内容作为普通的字符,无特殊例外。
16. $ 变量符。
17. \ 转义字符。
18. ’ ’ 倒引号,表示它所包含的内容。
19. 命令分隔符。
20. < 重定向输入符。
21. () 表示整体执行命令。

菜鸟学习awk

Linux下面,如果要处理格式化的文本数据,awk算是利器了,一般bash + awk 能写出神一般的处理程序,如果对awk还没有一点认识的,那么先

man awk

详细看完这个简单的教程。
简单的说,awk是一个简单的动态解释性脚本语言,数值比较,控制流,循环,数组,这些语法基本上和C语言一样,所以我只需要了解awk独特的地方就行了。
awk是按行和列来处理输入,简单地说awk是按照table的样式处理数据,就像我们excel数据一样。
有如下的测试数据:

It hurts to love someone and not
But what is more painful is to love someone
and never find the courage to let that

awk解析数据为表格格式:

|It  |hurts |to   |love |someone |and |not
|But |what  |is   |more |painful |is  |to  |love |someone
|and |never |find |the  |courage |to  |let |that

同时保存测试数据为 test.txt
我们来点实例:
假如只输出第二列数据,可以在控制台中:

cat test.txt|awk '{print $1}'

或者

awk '{print $1}' < test.txt

输出:

hurts
what
never

这里只是展示了awk在命令行下的运用,在命令行下
执行 awk 'expression' ,其中 expression 就是awk的语句,上面的例子只是简单的输出,awk还可以在开始读入数据的前后,做一些处理,例如:

cat test.txt|awk 'BEGIN {print "--START--"} {print $0} END { print "--END--"}'

输出:

--START--
It hurts to love someone and not
But what is more painful is to love someone
and never find the courage to let that
--END--

这里的 BEGIN 和 END 是awk的特殊语法
大家看到这里可能就应该知道awk脚本几个特殊的地方,比如上文种出现的 $0 ,$2,还有print,这些代表什么含义,上文我们说了awk的按行和列处理数据的,所以这里的 $ 是变量前缀,$0 代表整行,$1,代表第一个字段,也就是按照分割符的第一列数据,$2,$3...类推,这些都是awk内嵌变量。


参考:
http://www.grymoire.com/Unix/Awk.html

Page 1 of 1012345»...Last »