2012年12月31日星期一

2012年度总结


广州昨晚很冷,但是九点多的时候我还是出去跑了一圈内环,回来再洗了个冷水澡。我想过为什么今年又能够像高中那样坚持冼冷水澡,应该是十月份天气开始转凉,周边同学开始冼热水澡时,而我觉得那样子的天气还没必要冼热水,然后冼着冼着好像就停不下来了,成为了习惯。跑内环也是,从夏天开始,已经将近半年,还有偶尔的健身,目的也达到了,体质加强了不少,最明显的一点是今年鼻炎有非常大的好转!超乎我的意料,上一年鼻塞得可真不好受。这两个习惯算是今年的一个变化,我也很欣喜有这种坚持,特别是越跑越来劲时,我才知道做事最怕心生欢喜!

如果按四季来分段总结过去的一年,冬季是最忙最为充实的季节,阅读到好文章和看到好书带来最多的快乐(推荐Mindfire: Big Ideas for Curious Minds by Scott Berkun);夏季却是最刻骨铭心的一段日子,发生在自己身上、身边的三件事,算不上彻底但也有很深地,改变了我,生活给予的这件礼物虽然包装真的很难看,但是又要真诚地微笑着感谢它,感谢它带来很积极、正面的影响!也是在那个时候,有机会有需求,看到《正念》一书(台译版的书名更有意境——《当下,繁花盛开》)不夸张地讲,真是解救我于水深火热之中。春秋是一个比较霸气的词,各取一半便是秦,可惜过去这一年的春秋两季过得较为平淡:-(

这一年英语有不小的进步,看过“外语学习的真实方法与误区分析”,有些观点确实很赞同也很受益。前天第一次看全英字幕的电影《东方承诺》,听懂没问题,这是另一个好的开始:-) 不知道你有没有觉得,有些英文语句还是不要翻译的好,就像新鲜的一道菜,翻炒一遍之后味道肯定有差,所以这也是看英文原版的好处之一。希望新年保持多看多听之外还要多写,用英文准确地表达自己的想法。

今年还有一个值得一提的改变是把自己笔记本的操作系统从原先的Fedora换成了Archlinux,没有DE,只有WM:Awesome,都是定位为lightweight级别的两样东西,用起来真的很棒!

好了,也评一下自己心中的各项年度之最:

  • 技术书:Programming From The Ground Up by Jonathan Bartlett 
  • 非技术书:正念 [作者]乔·卡巴金,[译者]雷叔云 
  • 设备:kindle3
  • 电影:饥饿游戏
  • 音乐:Sooner or Later - Mat Kearney
  • 软件:sshuttle
  • 比赛:曼联4:3纽卡斯尔 2012/12/26 
  • 笑话:“紫薇,嫁给我你一辈子姓福!”

希望新年看多些书、多写博客,努力“升级”,努力成为一个有趣的人!

2012年10月16日星期二

archlinux下的无线配置


在archlinux下把无线网络配置了一通,基本教程可参考arch wiki上的文章:
https://wiki.archlinux.org/index.php/Wireless_Setup
https://wiki.archlinux.org/index.php/Netcfg

以下说一下在配置过程中遇到的问题:
我用的是HP 4411s笔记本,在开始配置之前输入命令"ifconfig -a"可以看到wlan0接口,因此直接输入命令"ip link set wlan0 up"尝试将wlan0开启,但是遇到了第一个问题:“RTNETLINK answers: Operation not possible due to RF-kill”,原因是wlan0被关闭了,但是用"rfkill unblock all"命令之后虽然已经取消soft block,但是问题并没有得到解决,在网上查资料发现也有类似的情况,(在这里说明一下,输入rfkill list之后发现有两个wifi设备,一个是hp-wifi,另一个是phy0)解决办法是将hp-wifi关闭并取消phy0的hard block。将hp-wifi关闭的做法是在/etc/modprobe.d/modprobe.conf里加一句blacklist hp_wmi,表示在系统启动时不加载该模块。而在本机器上按Alt+F12组合键则可取消phy0的hard block。到此第一个问题得到解决。

然后输入"wifi-menu"并选择相应无线网络,可以正常连接。由于我需要设置静态IP,因此打算使用netcfg来管理相应网络,具体的说明文档可以参见这里,当我编写好相应的配置文件后输入"netcfg mynetwork"命令时遇到了第二个问题:adding gateway failed。在网上查资料发现有一样的问题,但是别人推荐的解决方法均没能解决我的问题,因此试着在配置文件里将路由器的配置换另一种方式:
#GATEWAY='xxx.xxx.xxx.xxx'
POST_UP='ip route add xxx.xxx.xxx.254/32 dev wlan0'
这个方法解决了第二个问题。

2012年9月15日星期六

《Programming From The Ground Up》摘录



最近阅读《Programming From The Ground Up》一书,虽然书中用的是汇编语言,但是涵盖了许多知识点,讲得很透彻,让人对计算机的认识更加深刻,每读完一章,阅读欲望更加强烈,这应该就是一本好书的魄力所在吧。下面是我阅读此书时做的一些摘录。

The kernel is both an fence and a gate. As a gate, it allows programs to access hardware in a uniform way. As a fence, the kernel prevents programs from accidentally overwriting each other’s data and from accessing files and devices that they don’t have permission to. 

In fact, in a computer, there is no difference between a program and a program's data except how it is used by the computer. They are both stored and accessed the same way.

Think of a register as a place on your desk - it holds things you are currently working on.

The size of a typical register is called a computer's word size.

Addresses which are stored in memory are also called pointers, because instead of having a regular value in them, they point you to a different location in memory.(A pointer is a register or memory word whose value is an address.)

Remember, computers can only store numbers, so letters, pictures, musics, web pages, documents, and anything else are just long sequences of numbers in the computer, which particular programs know how to interpret.

Think of a stack as a pile of papers on your desk which can be added indefinitely. You generally keep the things that you're working on toward the top, and you take things off as you're finished working with them.

Well, we say it's the top, but the "top" of the stack is actually the bottom of the stack's memory. In memory the stack starts at the top of memory and grows downward due to architectural consideration.

The base pointer(%ebp) is a special register used for accessing function parameters and local variables.
Parameter #N           <---  N*4 + 4(%ebp)
...
Parameter 2              <---  12(%ebp)
Parameter 1              <---  8(%ebp)
Return Address         <---  4(%ebp)
Old %ebp                  <---  (%ebp)
Local Variable 1        <---  -4(%ebp)
Local Variable 2        <---  -8(%ebp) and (%esp)

The only difference between the global and static variables is that static variables are only used by one function, while global variables are used by many functions. Assembly language treats them exactly the same, although most other languages distinguish them.

When a function is done executing, it does three things:
  1. It stores its return value in %eax.
  2. It reset the stack to what it was when it's called(it get rid of the current stack frame and put the stack frame of the calling code back into effect).
  3. It returns the control back to wherever it was called from. This is done using the ret instruction, which pops whatever value is at the top of the stack, and sets the instruction pointer, %eip, to that value.
The way that variables are stored and the parameters and return value are transferred by the computer varies from language to language. This variance is known as a a language's calling convention, because it describes how functions expect to get and receive data when they're called.

UNIX files, no matter what program created them, can all be accessed as a sequential stream of bytes.

A buffer is a continuous block of bytes used for bulk data transfer when you request to read a file, the operating system needs to have a place to store the data it reads. That place is called a buffer.

Linux program usually have at least three open file descriptors when they begin. They are: STDIN, STDOUT, STDERR.

Testing isn't just about making sure your program works, it's about making sure your program doesn't break.

..., all of the code was contained within the source file. Such programs are called statically-linked executable, because they contain all of the necessary functionality for the program that wasn't handled by the kernel. When use shared libraries, your program is then dynamically-linked, which means that not all of the code needed to run the program is actually contained within the program file itself, but in external libraries.

The reason that parameters are pushed in the reverse order is because of functions which take a variable number of parameters like printf. The parameters pushed in last will be in a known position relative to the top of of the stack. The program can then use these parameters to determine where on the stack the additional arguments are, and what type they are. For example, printf uses the format string to determine how many other parameters are being sent. If we pushed the known arguments first, you wouldn't be able to tell where they were on the stack.

Every piece of data on the computer not in a register has an address. The address of data which spans several bytes is the same as the address of its first byte.

A computer looks at memory as a long sequence of numbered storage locations.(These storage locations are called bytes.)

Every Memory Address is a Lie.
a).Physical memory refers to actual RAM chips inside your computer and what they contain.
b).Virtual memory is the way your program thinks about memory.

Before loading your program, Linux finds an empty physical memory space large enough to fit your program, and then tells the processor to pretend that this memory is actually at the address 0x08048000 to load your program into.

Virtual memory can be mapped to more that physical memory, it can be mapped to disk as well.[Swap partitions on Linux does this job.]

The pool of memory used by memory managers is commonly referred to as the heap.

The way a computer handles decimals is by storing them at a fixed precision(number of significant bits). A computer stores decimal numbers in two parts - the exponent and the mantissa.For example, 12345.2 is stored as 1.23452 * 10^4. The mantissa is 1.23452 and the exponent is 4. Now, the mantissa and the exponent are only so long, which leads to some interesting problems. For example, when a computer stores an integer, if you add 1 to it, the resulting number is one larger. This does not necessarily happen with floating point numbers. If the number is sufficiently big, like 5.234 * 10^5000, adding 1 to it might not even register in the mantissa (remember, both parts are only so long). This affects several things, especially order of operations. Let’s say that I add 1 to 5.234 * 10^5000 a few billion or trillion times. Guess what - the number won’t change at all. However, if I add one to itself enough times, and then add it to the original number, it might make a dent.