Monthly Archives: October 2009 - Page 2

关于“字节序”

昨天纠正了长达几年的关于字节序的错误理解。

受到移位操作符的影响,一直认为在内存中数字的保存方式和显示的一样,比如一个2直接的short 9 ,保存在内存中应该是:

00 09 这种形式,因为这样移位才说的通。 否则如果按照低字节优先的方法 09 00 右移位就会出乱子了~

结果昨天研究和服务器socket通讯的例子中 发现了个陌生函数 :htonl  。

man (越来越喜欢命令行了)后发现是 host to network long(short) 的缩写 ,这下彻底困惑了。难道 c 在内存中的数据不是想象中的那样?

最后K大侠亲自上阵,示范了使用GDB debug ,也帮我验证了我多年的错误观点:

#include <stdio.h>
int main()
{
 int a = 8;
 char *p;
 p= (char*)&a;
 a = a>>1;
 char *k = &a;
 return 0;
}
  • gcc -g test.c   # -g 添加调试
  • gdb test.out   # init
  • b main          # add breakpoint at main function
  • run                 # just run until breakPoint occured
  • n                    # next

逐次打印出 p 指针的值 p *(p++)   , 发现果然是地位在最前面的。
不过对于移位操作就困惑了,难道这个操作不是直接在内存操作的?难道是先转成高位优先然后移位再转回来? Read more »

[iPhone]播放midi文件

iPhone 默认不带播放MIDI的框架,所以播放MIDI还得寻求第3方的库帮忙。

这里使用的库就是大名鼎鼎的 FMOD ,许多火爆游戏使用的都是这个库。开发者可以免费下载使用。

首先下载安装 FMOD API FOR IPHONE:
http://www.fmod.org/index.php/release/version/fmodapi42607iphone-installer.dmg

安装后可以在目录中看到不少示范代码,可惜没有MIDI。

自己写一个:)
感谢强大的api,写起来异常轻松。

  • 新建一个基于view项目
  • 修改项目属性,添加 Other Linker Flags 为 -lfmodexL_$PLATFORM_NAME
  • 添加 Header Search Paths :/Developer/FMOD\ Programmers\ API\ iPhone/api/inc  (默认是这个位置,修改成自己FMOD安装的目录)
  • 添加 Library Search Paths :/Developer/FMOD\ Programmers\ API\ iPhone/api/lib (同上)
  • 把 appDelegate 修改成 .mm 的后缀
  • MIDI 播放需要一个 DLS 文件, 在osx 下没找到,这里使用了xp 自带的 gm.dls 文件(3M 有点大~),拷贝到项目中。
  • 修改ViewController 代码如下 ,随便在xib文件中链接两个按钮action上即可
  • 运行(真机有效)

主要源码: Read more »

[转]软件公司是怎么死掉的

原始链接已经无法访问,此文转自robbin博客

软件公司怎么失控的和完蛋的?通常是来了一个有个性的管理人员,这老兄一看,这帮程序员怎么这么……不顺眼啊?脏兮兮,乱糟糟,不配合,他们看起来是多无趣的一群人啊!最糟糕的是,他们还笑话你!于是对他们进行管理……这下规范了,但是,程序员们被伤害了,他们被要求要参加会议,做计划,写报告,严格按照流程,千万千万不要去动别人的代码!程序员觉得自己就象过起了外星人的生活……于是,最好的程序员走了,有的开始怠工,甚至破坏……蜂房毁了。管理者舒服了,因为好像事情开始受控了,大家开始打领带了;但是Bug开始成堆出现,市场丢失,最后,关门大吉。

原文:

How Software Companies Die

By Orson Scott Card
The environment that nutures creative programmers kills management and marketing types – and vice versa. Programming is the Great Game. It consumes you, body and soul. When you’re caught up in it, nothing else matters. When you emerge into daylight, you might well discover that you’re a hundred pounds overweight, your underwear is older than the average first grader, and judging from the number of pizza boxes lying around, it must be spring already. But you don’t care, because your program runs, and the code is fast and clever and tight. You won. You’re aware that some people think you’re a nerd. So what? They’re not players. They’ve never jousted with Windows or gone hand to hand with DOS. To them C++ is a decent grade, almost a B – not a language. They barely exist. Like soldiers or artists, you don’t care about the opinions of civilians. You’re building something intricate and fine. They’ll never understand it.

BEEKEEPING

Here’s the secret that every successful software company is based on: You can domesticate programmers the way beekeepers tame bees. You can’t exactly communicate with them, but you can get them to swarm in one place and when they’re not looking, you can carry off the honey. You keep these bees from stinging by paying them money. More money than they know what to do with. But that’s less than you might think. You see, all these programmers keep hearing their parents’ voices in their heads saying “When are you going to join the real world?” All you have to pay them is enough money that they can answer (also in their heads) “Geez, Dad, I’m making more than you.” On average, this is cheap. And you get them to stay in the hive by giving them other coders to swarm with. The only person whose praise matters is another programmer. Less-talented programmers will idolize them; evenly matched ones will challenge and goad one another; and if you want to get a good swarm, you make sure that you have at least one certified genius coder that they can all look up to, even if he glances at other people’s code only long enough to sneer at it. He’s a Player, thinks the junior programmer. He looked at my code. That is enough. If a software company provides such a hive, the coders will give up sleep, love, health, and clean laundry, while the company keeps the bulk of the money.

OUT OF CONTROL

Here’s the problem that ends up killing company after company. All successful software companies had, as their dominant personality, a leader who nurtured programmers. But no company can keep such a leader forever. Either he cashes out, or he brings in management types who end up driving him out, or he changes and becomes a management type himself. One way or another, marketers get control. But…control of what? Instead of finding assembly lines of productive workers, they quickly discover that their product is produced by utterly unpredictable, uncooperative, disobedient, and worst of all, unattractive people who resist all attempts at management. Put them on a time clock, dress them in suits, and they become sullen and start sabotaging the product. Worst of all, you can sense that they are making fun of you with every word they say.

SMOKED OUT

The shock is greater for the coder, though. He suddenly finds that alien creatures control his life. Meetings, Schedules, Reports. And now someone demands that he PLAN all his programming and then stick to the plan, never improving, never tweaking, and never, never touching some other team’s code. The lousy young programmer who once worshiped him is now his tyrannical boss, a position he got because he played golf with some sphincter in a suit. The hive has been ruined. The best coders leave. And the marketers, comfortable now because they’re surrounded by power neckties and they have things under control, are baffled that each new iteration of their software loses market share as the code bloats and the bugs proliferate. Got to get some better packaging. Yeah, that’s it.

老忘记各种事情

不好意思说自己健忘,但事实上自己经常会发生忘记本来打算干什么的。

就比如刚才,想起一个叫马日拉的人。要找到这个人首先得先找到韩寒。

于是在输入 blog.sina 后浏览器自动给补全了某朋友的博客,于是便链接了过去。

幸亏想起自己要干啥,重新手动输链接。还是熟悉的音乐熟悉的文字。

10分钟过去。。

30分钟过去。。

关闭页面。。

觉得有点不对劲。。

想。。。

想起来了。。哈哈。。

还好这次幸亏心里觉得不踏实幸亏想起来要干嘛了。

我发誓忘记报名参加考试这事情再也不会发生了。恩。

[烂]ccav再次糟蹋好东西

10年前那次唯一的印象是阿姨对着电视拍照片留念。
显然最后底片上只会留下晃动的残影。

这次在家期待能震撼下自己,结果还是边看边骂。比奥运开幕式那次还糟糕。
给各位欣赏下人家的视频,就一个位置都能剪辑成这境界。

China’s 60th Anniversary national day – timelapse and slow motion – 7D and 5DmkII from Dan Chung on Vimeo.

这里还有牛文一篇:从专业人员角度看这次阅兵转播的业余

Read more »

[Rails]学生教务管理系统

[todo: 截图here  这个项目应该可以找到,记得还写过文档~~]
项目描述:学生教务信息管理系统
项目时间:08年11月6日
项目周期:2天(一晚上ps界面 +html+css ,一天时间code)
项目功能:[todo:等找到文档后补上]

[todo:找到文档了,得安装个iwork才能打开~~]

源码下载:StudentPlanet

[Flash]转盘抽奖系统客户端

展示界面

展示界面

全站外貌

全站外貌

版权关系只提供 Flash 端代码。

写这个东西设计上出了点漏洞,回顾代码整个项目只有一frame 。所以浪费了很多代码控制各个组件 visible 属性。

还有在如何控制指针缓慢停下到最后位置的设计也有点赶巧,一开始为了节约设计时间直接凑了几个数字做时间关键字。结果效果不理想,调整了很久才勉强看起来自然点。如果一开始就用物理方法计算估计效率会高很多。

附源码,有debug模式,单机也可以玩玩~

开发环境: Flex3(代码) + Flash10(界面)

项目时间:2009年3月20日

开发时间:一周(服务端和客户端) Read more »

命令行的伟大

曾经用Ruby 写了个脚本用来统计项目中文件行数,没事打发下时间顺便满足下小小的虚荣感。

发于cocoaChina论坛中(http://cocoachina.com/bbs/read.php?tid-8266.html)。

结果惨遭鄙视。

原来用 bash 一句话就可以搞定 !(用Ruby还写了那么多代码~悲剧了~)

find . -name '*.m' -exec cat {} \; | wc -l
find . -name '*.h' -exec cat {} \; | wc -l
find . -name "*.m"  |xargs wc -l

掌握一些常用命令还是很能提高工作效率的。学习中。

[C/CPP]HNU.ACM.ACCEPT.CODES

[todo: 这里添加一张照片]

此为偶然一次参加学校acm比赛并得奖后在校培训班时期写的一些ac代码。

持续更新中,包括ac代码,资料。

在线答题网址:http://acm.hnu.cn

项目地址:http://github.com/xhan/HNU_ACM_AC_Codes

[Flex + Rails]茶餐厅(在线购物)网

来源老博客

首页截图

flex+rails-index

购物界面截图(主要功能了)

flex+rails-shopping

后台有两个,一个是简单的rails写的。另一个也用 flex 完成,包括订单管理,商品管理,类别管理。(可能还有,忘记了)

Read more »