KEEP K.I.S.S.

tk's blog

Debian 6.0 'Squeeze' KDE 备忘

先贴几张配置之后的图看看。

文件管理器 Dolphin:

终端 Konsole:

'开始菜单' Kickoff:

系统设置:

////*************************************************************************************////

其实是在虚拟机里安装的,所以就没有驱动配置的烦恼,好在主机性能不错,打开bios里的虚拟化之后,Debian的系统运行速度很不错,可以说是相当的快速。

安装CD是从官网下载的 KDE 整合的,http://cdimage.debian.org/debian-cd/6.0.2.1/i386/iso-cd/
目录的下方会有一个 debian-6.0.2.1-i386-kde-CD-1.iso

安装的过程中就不叙述了,应该没有什么大问题。

下面说一下安装后进入系统需要做的工作:

  1. 源。参考文章:Debian6 安装小记 http://www.bentutu.com/2011/05/debian6-install-note/
    乱码问题没有出现,首先是解决源的问题:
    打开 Konsole 终端,输入命令 su 进入 root 权限,需要输入安装时候设置的 root 密码。
    更改 /etc/apt/sources.list 权限: chmod 666 /etc/apt/sources.list
    然后使用KDE自带编辑器 Kwrite 编辑 /etc/apt/sources.list 文件, 先将所有未注释的行全部注释(头部加 '#'),然后添加源,这里使用 163 的源。 保存之后,再把文件权限更改回来: chmod 644 /etc/apt/sources.list, 然后 apt-get update 更新一下,这样就可以使用 apt-get 或者 aptitude 来安装软件了。
    deb http://mirrors.163.com/debian squeeze main non-free contrib
    deb http://mirrors.163.com/debian squeeze-proposed-updates main contrib non-free
    deb http://mirrors.163.com/debian-security squeeze/updates main contrib non-free
    deb-src http://mirrors.163.com/debian squeeze main non-free contrib
    deb-src http://mirrors.163.com/debian squeeze-proposed-updates main contrib non-free
    deb-src http://mirrors.163.com/debian-security squeeze/updates main contrib non-free
    deb http://http.us.debian.org/debian squeeze main contrib non-free
    deb http://non-us.debian.org/debian-non-US squeeze/non-US main contrib non-free
    deb http://security.debian.org squeeze/updates main contrib non-free
  2. sudo。 依然参照 bentutu 的这文章,先安装 sudo : apt-get install sudo, chmod 644 /etc/sudoers 来增加写权限,在 root ALL=(ALL) ALL 语句下添加 username ALL=(ALL) ALL , username 为你当前非root账户用户名。 然后保存并修改权限:chmod 0440 /etc/sudoers 。
  3. locales。参考 http://easwy.com/blog/archives/chinese_in_debian_lenny/ 。
    终端命令输入 sudo dpkg-reconfigure locales 来配置locales。 
    跟文章中一样选择 locales : 
    en_US.ISO-8859-1
    en_US.UTF-8
    zh_CN.GB2312
    zh_CN.GB18030
    zh_CN.UTF-8
    zh_CN.GBK
    zh_TW.BIG5
    zh_TW.UTF-8设置为
    默认 locale 设置为zh_CN.UTF-8
  4. KDE 中文化。参考 http://www.linuxsir.org/bbs/showthread.php?p=1757986。这个时候在 KDE 的设置里,选择 语言为中文会没有什么效果,也无法添加中文支持,因为需要下载 中文语言支持文件。
    在终端输入命令:sudo aptitude install kde-i18n-zhcn . 安装完成后就可以在 KDE 设置面板里 选择中文了。
  5. man 中文包。 终端命令:  sudo apt-get install manpages-zh
     
  6. 可选的 windows 字体'支持' 。 把 win 下的几个常用字体拷贝过来,使用 KDE 自带的字体安装器安装(需要root 密码),推荐一个 等宽字体 Droid Sans Mono,免费的字体,显示的也很漂亮。 安装字体后,在 KDE 的设置,外观中,调整所有字体,建议使用微软雅黑,因为看起来真的很好很强大,就如上面的图一样。
  7.  Chrome 的安装。下载 Chrome 的 Deb 包,然后在终端里 输入命令: sudo dpkg -i xxx.deb 来安装这个 deb 包,但是安装过程中会提示有依赖未安装,所以还需要一个命令:sudo apt-get -f install 来解决问题,然后 
    chrome 就可以用了。PS 最好更改下 Chrome 的字体。。。。
  8.  输入法。我使用的是 iBus, 安装命令为: sudo aptitude install ibus-pinyin。 KDE 貌似还没有用源生的输入法,不管 ibus 还是 scim 都是基于 Gtk 的,在kde下使用虽然没多少问题,但是那个界面实在是简陋。。。不过好像可以通过设置 gtk 主题来解决。

////**************************************************************//////

其实我开始是想用 openSUSE 的,但是那个安装包,太大了。然后就选择了 Debian,毕竟 Ubuntu 对 KDE 支持很不好。KDE 的确很好用,个人觉得界面什么的比 Gnome 要美观很多,至少风格是以明亮为主。还有一点就是 gnome 使用的是上下双'任务栏',个人觉得很占屏幕空间。。。 

设计模式

最近突然开始看设计模式了,原因很简单,自己写的一个程序写大了过于复杂,想分成各个类的时候比较纠结,不清楚如何分配各个功能,更要命的是,对于实际需求的分析能力还不够,慢慢学习吧。。。。

几篇易懂的文章推荐

当然最好的还是去看“官方书籍” 设计模式-可复用面向对象软件的基础

如何使用Qt Creator 开发普通C++项目

相信很多人有这样的需求吧

推荐使用 Qt Creator 2.1 以上版本,因为自带了 Class View ,不需要第三方的插件就可以看Symbol了。

新建项目里,选择 Other Project 然后是 Import Existing Project,建立项目后添加文件,最后需要的是自己写一个 Makefile, 而且默认的 Build 目标是 all,注意 GNU make 的文件格式,命令行开头需要一个完整的 TAB

针对最简单的单文件,比如 main.cpp ,makefile 可以这样写

 

all:
	g++ -o  main main.cpp          

然后就可以了。

如果你自己添加的第三方库也可以提供自动补全功能,但是需要能搜索到这个库目录,我用的是 Mingw ,直接把第三方库放到 Mingw 对应的 include 和 lib 目录了,引用头文件之后自动补全很好很强大。应该也有环境变量来设置的,不过暂时不大清楚如何操作。

Euler Project Problem 14 with Ruby

看题

 


The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)
n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

NOTE: Once the chain starts the terms are allowed to go above one million.

 

Ruby 代码 这个速度还算可以了 4秒之内出结果

 

#!/d/ruby192/bin/ruby
#coding:utf-8

# get the next num of the chain
def next_num(num)
  if num.even?
    num/2
  else
    num*3+1
  end
end

$cache = Hash.new(0)

def get_len(num)
  if $cache.include?(num)
    res = $cache[num]
  else
    res = get_len(next_num(num))+1
    $cache[num] = res
  end
  res
end
$cache[1] = 1
$cache[2] = 2
$cache[4] = 3

$max,$most = 1,1
# from 1 to 1 million, so that the $cache may be used the most
(1...1_000_000).each do |num|
  if $max < get_len(num)
    $max = get_len(num)
    $most = num
  end
end  
puts $most,$max

Euler Project Problem 11 with Ruby

不多说了,题目

 

In the 20×20 grid below, four numbers along a diagonal line have been marked in red.

08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

The product of these numbers is 26 × 63 × 78 × 14 = 1788696.

What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20×20 grid?

我的 Ruby 解法代码,

 

#!/d/ruby192/bin/ruby
#coding:utf-8

grid = %Q{
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48}

$array = grid.scan(/\d\d/)

def get_value(x, y)
  ret = $array[y*20+x]
  if ret
    ret.to_i
  else
    0
  end
end

def get_most(x,y)
  m = []
  m << get_value(x,y)*get_value(x+1,y)*get_value(x+2,y)*get_value(x+3,y) 
  m << get_value(x,y)*get_value(x,y+1)*get_value(x,y+2)*get_value(x,y+3)
  m << get_value(x,y)*get_value(x+1,y+1)*get_value(x+2,y+2)*get_value(x+3,y+3)
  m << get_value(x,y)*get_value(x+1,y-1)*get_value(x+2,y-2)*get_value(x+3,y-3)
  m.max
end
$most = 0
for x in 0...20 
  for y in 0...20
    if $most < get_most(x,y)
      $most = get_most(x,y)
    end
  end
end

puts $most
   
   

不过感觉这写的还是不够优雅。。。。