屠龙之技(一个有趣的签名档)

看到有个人的签名档是:

main(_) { for(--_;putchar(_++["J!Mpwf!Zpv\"\013\1"]-1);); }

这段代码能打印出 I Love You!。呵呵,分析了一下,_ 是 main() 的第一个参数,就是通常那个 argc,至于 i[p] 这个形式等价于 p[i],都是一样按指针加偏移计算的,以前在某个地方见过的。引号里面那段东西每个减去 1 就是 "I Love You!\n" 这个字符串了。写得规范一点就容易懂了:

#include <stdio.h>
int main(int argc, char **argv)
{
    char *s = "J!Mpwf!Zpv\"\013\1";
    for (--argc; putchar(s[argc++] - 1););
    return 0;
}

微软题,整数列的最大公约数

求一列整数的最大公约数,用 Python 写了,顺便还求了最小公倍数。没有考虑负数。

#!/usr/bin/env python

def gct(m, n):
'return gct and gxt'
if m > n:
a, b = m, n
else:
a, b = n, m
while 1:
r = a % b
if not r:
return b, (m*n)/b
else:
a = b
b = r

def gctArray(array):
if not array:
return None, None

x, y = array[0], array[0]
if len(array) < 2:
return x, y

for i in array[1:]:
x, unused = gct(x, i)
unused, y = gct(y, i)
return x, y

if __name__ == '__main__':
print gctArray((4, 12, 6, 8))
print gctArray((20, 12, 10, 14, 16))

运行结果:

wayman ~/t $ python gcd.py
(2, 24)
(2, 1680)

微软题,链表逆序

给定一单链表的表头指针和指向其中一个节点的指针,要求以该指针为头将原链表逆序排列,例如:

N1->N2->N3->N4->N5->NULL  pHEAD = N1,pSTART = N3,返回N3->N2->N1->N5->N4->NULL
N1->N2->N3->N4->N5->NULL  pHEAD = N1,pSTART = N5,返回这个N5->N4->N3->N2->N1->NULL
N1->N2->N3->N4->N5->NULL  pHEAD = N1,pSTART = N1,返回这个N1->N5->N4->N3->N2->NULL
不允许额外分配存储空间,不允许递归,可以使用临时变量。

没有去管 malloc() 的返回值,也没有管 free() 的问题,但是考虑了 pSTART 是空指针的问题。数据类型仅用了一个 char 来演示。NULL 用 0 写了,省事。逆序的思路是先把链表接成循环的,然后从 pStart 处开始前插。

#include <stdio.h>
#include <stdlib.h>

typedef struct link_st {
char c;
struct link_st *link;
} link_t;

link_t * new_node(char c)
{
link_t * node = malloc(sizeof(link_t));
node->c = c;
node->link = 0;
return node;
}

void print_link(const link_t * link)
{
while (link != 0) {
printf("%c ", link->c);
link = link->link;
}
printf("$\n");
}

link_t * reverse(link_t **head, link_t *start)
{
link_t *p, *q, *save;

/* make it be a circle link */
p = start != 0 ? start : *head;
while (p->link != 0)
p = p->link;
p->link = *head;

/* reverse, preinsert */
if (0 == start)
start = p;
save = p = start->link;
while (p != start) {
q = p->link;
p->link = start->link;
start->link = p;
p = q;
}

/* break the circle */
save->link = 0;

*head = start;
return *head;
}

int main()
{
int i;
link_t *h, *nhead;

h = new_node('A');
h->link = new_node('B');
h->link->link = new_node('C');
h->link->link->link = new_node('D');
h->link->link->link->link = new_node('E');

print_link(h);
nhead = reverse(&h, h->link->link->link);
print_link(h);

nhead = reverse(&h, 0);
print_link(h);

return 0;
}

运行结果:

wayman ~/t $ gcc -o link link.c
wayman ~/t $ ./link
A B C D E $
D C B A E $
E A B C D $

cpio usage

1. create (output) mode

find dir | cpio -ov -H ustar > foo.cpio

2. extract (input) mode

list content:

cpio -itv -H ustar < foo.cpio

extract:

cpio -idv -H ustar < foo.cpio

-d        create dir as needed
-E file filename that contains a list of file, each a line

3. copy dir, pass mode

cpio -pdmv dest-dir < name-list
find src-dir | cpio -pdmv dest-dir # create dest-dir/src-dir
cd src-dir; find . | cpio -pmdv dest-dir
-m    preserve mtime

IBM 笔试

今天去参加了 IBM 笔试,包括 IPAT(Information Processing Aptitude Test) 和技术类考 试。

这个所谓 IPAT,我做的感觉这根本不是考察我是不是够聪明,而是感觉在耍我!把一个矩阵的行列元素颠来倒去,然后问你什么哪行哪列是什么,那个字母在某个对角线 上没有出现;给你一列数,让你按照隐含的规律写出下一个数;给你出一些小学题,稍微绕上一绕,等等,我不相信有人做不对这种题!无非是时间长短罢了,那个 趾高气扬的 HR 部门的人叫什么苏什么的来着,给他四分钟让他来做做看!反正我是不够聪明了,做得一塌糊涂。技术类考试也够变态的,什么都考,除了 Java/C++ 是可选,其他考的有 UML、XML、设计模式、HTML、CSS、SQL、数据结构……,偏偏我熟悉的 Unix、Network 都不考,靠,怎么感觉象是微软出题呀。C++中考语法的也具变态,int p = 1, q = 1; 然后给你 p = q = 3 + q = 1; 问你p现在等于几?这个是编译通不过的,骗不了我。但哪个会这么写代码?老子第一个扁他!总之这个笔试我是一定要被鄙视的了,罢了,如果他们需要的只是这些方面的知识,去不了也没什么可惜的。

General Tips To Overcome An Interview

http://freshersworld.com/oldq/..%5Cinterview%5Cinterview.html

Powered by Google

General Tips To Overcome An Interview

Campus So what if you are not a mountaineer. Or a keen hiker. You still cannot treat your interview like a careless morning trot along a jogger's path. Your jaw-jaw at the interview table is nothing less than a cautious climb up a mountain trail--which begins around your early childhood and meanders through the years at the academia before reaching a new summit in your career.And as you retrace your steps down memory lane make sure that you post flags at important landmarks of your life and career, so that you can pop them before the interview panel scoops them out of you. You don't want to be at the receiving end, do you?

Face the panel, but don't fall of the chair in a headlong rush-and-skid attempt to tell your story. Take one step at a time. If you place your foot on slippery ground, you could be ejecting out on a free fall.

So prepare, fortify your thoughts, re-jig your memory, and script and design your story (without frills and falsity). Without the right preparation and storyboard, you could be a loser at the interview. Here are a few preparation tips that books on interviews sometimes overlook.

Before the interview

1. Chronological Outline of Career and Education Divide your life into "segments" defining your university, first job, second job. For each stage, jot down :

The reason for opting certain course or profession; Your job responsibilities in your previous/current job; Reason of leaving your earlier/current job. You should be clear in your mind where you want to be in the short and long term and ask yourself the reason why you would be appropriate for the job you are being interviewed for and how it will give shape to your future course.

2. Strengths and Weaknesses

You should keep a regular check on your strengths and weaknesses. Write down three (3) technical and three (3) non-technical personal strengths. Most importantly, show examples of your skills. This proves more effective than simply talking about them. So if you're asked about a general skill, provide a specific example to help you fulfil the interviewer's expectations. It isn't enough to say you've got "excellent leadership skills". Instead, try saying:

"I think I have excellent leaderships skills which I have acquired through a combination of effective communication, delegation and personal interaction. This has helped my team achieve its goals."

As compared to strengths, the area of weaknesses is difficult to handle. Put across your weakness in such a way that it at leaset seems to be a positive virtue to the interviewer. Describe a weakness or area for development that you have worked on and have now overcome.

3. Questions you should be prepared for

Tell us about yourself.
What do you know about our company?
Why do you want to join our company?
What are your strengths and weaknesses?
Where do you see yourself in the next five years?
How have you improved the nature of your job in the past years of your working? Why should we hire you?
What contributions to profits have you made in your present or former company? Why are you looking for a change?

Answers to some difficult questions :

Tell me about yourself ?
Start from your education and give a brief coverage of previous experiences. Emphasise more on your recent experience explaining your job profile.

What do you think of your boss?
Put across a positive image, but don't exaggerate.

Why should we hire you? Or why are you interested in this job?
Sum up your work experiences with your abilities and emphasise your strongest qualities and achievements. Let your interviewer know that you will prove to be an asset to the company.

How much money do you want?
Indicate your present salary and emphasise that the opportunity is the most important consideration.

Do you prefer to work in a group?
Be honest and give examples how you've worked by yourself and also with others. Prove your flexibility.

4. Questions to As

At the end of the interview, most interviewers generally ask if you have any questions. Therefore, you should be prepared beforehand with 2-3 technical and 2-3 non-technical questions and commit them to your memory before the interview.

Do not ask queries related to your salary, vacation, bonuses, or other benefits. This information should be discussed at the time of getting your joining letter. Here we are giving few sample questions that you can ask at the time of your interview.

Sample Questions

Could you tell me the growth plans and goals for the company?
What skills are important to be successful in this position?
Why did you join this company? (optional)
What's the criteria your company uses for performance appraisal?
With whom will I be interacting most frequently and what are their responsibilities and the nature of our interaction?
What is the time frame for making a decision at this position?
What made the previous persons in this position successful/unsuccessful?

5. Do your homework

Before going for an interview, find out as much information on the company (go to JobsAhead Company Q and A) as possible. The best sources are the public library, the Internet (you can check out the company's site), and can even call the company and get the required information. The information gives you a one-up in the interview besides proving your content company or position.

Clearing the interview isn't necessarily a solitary attempt. Seek assistance from individuals who are in the profession and whose counsel you value most. Be confident in your approach and attitude; let the panel feel it through your demeanour, body language and dressing.

Getting prepared for your interview is the best way to dig deep and know yourself. You will be surprised that it would breed a new familiarity become more familiar with your own qualifications that will be make you present yourself better. All the best and get ready to give a treat.

hping2 complation problem on solaris

I encountered errors when compling hping2 on my solaris x86 box. I spent some time to find out what's the matter and finally got it solved.

libpcap_stuff.c
net/bpf.h not found.

To work around: just remove "#include <net/bpf.h>", 'cos it is changed to pcap-bpf.h and included by pcap.h

ars.h
error: parse error before "u_int8_t"

To work around: just add these to ars.h:

#define u_int8_t unsigned char
#define u_int16_t unsigned short
#define u_int32_t unsigned int

See also: hping open bugs

也开始准备找工作了

开始找工作了,别人都已经如火如荼疯狂投简历了,比如zby 都已经投了 20 多个了,我也不能坐等对不对。要准备笔试面试要看一大堆的书,操作系统,组成原理,数据结构,TCP/IP,C++,Java,……。今天上图书馆借了 TCP/IP 详解,这套书现在要开始认真的看了,上星期与 zyk 讨论,IP 报文中 frag_offset 要乘以 8 我都不知道,丢脸啦。特意又去看了 yxn 去年找工作的经历,激励一下自己,呵呵。嗯,抽空还要去拜拜 offer 寺,:),祝我好运。

Solaris amd64: howto switch system from 64-bit mode to 32-bit mode

To determine computer/OS is 64 bit or 32 bit:

isainfo -b
isainfo -kv
To switch from 64-bit mode to 32-bit mode:

Press 'e' in grub menu while computer booting up, edit the default line
kernel /platform/i86pc/multiboot
change to
kernel /platform/i86pc/multiboot kernel/unix
Or edit /boot/grub/menu.lst to add a permanet entry.

Alternative method:

set related variable "boot-file" in eeprom after enter ok prompt mode (sparc) or edit /boot/solaris/bootenv.rc (x86) and add a line:

setprop boot-file kernel/unix

Update on Oct. 26, 2005: Another method:

reboot -- -D kernel/unix

Solaris crontab 的用法

blogspot 解禁之后换到这里,一直也没好好记。最近帮 Eric 配置 clone gate,用到 rsync 和 crontab。rsync 是个好东西,用来同步两台机器的目录再好不过,用法还没整理,先总结 crontab。

crontab [file]

加载定时任务。file 缺省时从 stdin 读取,文件格式是:

min hour day month weekday command
前 5 个字段表示日期及时间,可用:
*        任意匹配
m-n 范围
i,j,k 序列

command 最好用绝对路径,如果是脚本,也要注意 PATH 的问题。

Update on Oct. 26, 2005: 一旦提交就会生效,重启也不会丢失。

crontab -l

列出当前用户的任务

crontab -r

清除当前用户的任务

/var/cron/log

日志文件。发现任务没有按时启动时可检查这个日志,我把 clone 误写成 colne 结果任务一直没有启动,郁闷了好久,后来就是看这个才查到的

← Previous  1 … 21 22 23 24 25 26 Next →