<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>以太之内 生存之上 &#187; Coding</title>
	<atom:link href="http://ixhan.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://ixhan.com</link>
	<description>Live in your world, get owned in mine</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:09:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>关于豆瓣电台osx版</title>
		<link>http://ixhan.com/2010/07/about-douban-radio-osx/</link>
		<comments>http://ixhan.com/2010/07/about-douban-radio-osx/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 07:36:47 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[douban]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=370</guid>
		<description><![CDATA[突发奇想为什么不做个豆瓣电台的osx版本呢 于是就有了这个开源的项目 http://ixhan.com/project/douban-fm-osx/ 后发现Du Song同学的FanRadio: Free Music For Mac 已做的无懈可击，同时twitter上朋友告诉我dashboard已经支持后台的音乐播放了。 有点多此一举的感觉。= = 不过个人还是喜欢一个原生的播放器浮在桌面上的感觉拉。 原计划0.2版本中会提供解析当前歌手名，歌曲名并可以同步更新至adium的状态，以及歌词显示功能。 坏消息是今天发现从flash中获取到内容相当困难。 好消息是通过抓包发现了豆瓣电台的接口，相当简单。可以做不少好玩的东西去。 Related Posts豆瓣电台mac版]]></description>
			<content:encoded><![CDATA[<p>突发奇想为什么不做个豆瓣电台的osx版本呢</p>
<p>于是就有了这个开源的项目 <a href="http://ixhan.com/project/douban-fm-osx/">http://ixhan.com/project/douban-fm-osx/</a></p>
<p>后发现<cite><a rel="external nofollow" href="http://blog.rollingcode.org/">Du  Song</a></cite>同学的<a rel="bookmark" href="http://blog.rollingcode.org/2010/06/20/fanradio-1/">FanRadio:  Free Music For Mac </a>已做的无懈可击，同时twitter上朋友告诉我dashboard已经支持后台的音乐播放了。</p>
<p>有点多此一举的感觉。= =</p>
<p>不过个人还是喜欢一个原生的播放器浮在桌面上的感觉拉。</p>
<p>原计划0.2版本中会提供解析当前歌手名，歌曲名并可以同步更新至adium的状态，以及歌词显示功能。</p>
<p>坏消息是今天发现从flash中获取到内容相当困难。</p>
<p>好消息是通过抓包发现了豆瓣电台的接口，相当简单。可以做不少好玩的东西去。</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/project/douban-fm-osx/" title="豆瓣电台mac版">豆瓣电台mac版</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2010/07/about-douban-radio-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>栽大了之Objc过度释放对象</title>
		<link>http://ixhan.com/2009/11/shit-on-objc-object-manager/</link>
		<comments>http://ixhan.com/2009/11/shit-on-objc-object-manager/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 09:37:28 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[决定]]></category>
		<category><![CDATA[内存管理]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=196</guid>
		<description><![CDATA[事情是这样的,4个月前我写了份实现类似下拉框选择操作的界面. 一个月前,发现了这个View 在dealloc 会crash掉. 多次调试无果,上 devForum.apple.com 询问也无人问津. 今天决定再次调试下,还是没找到哪里出问题. 最后决定求助 cocoachina 上的现场观众 最后开始一行一行的注释代码做终极调试. 离谱的事情发现了,只要我创建一个名为 mainText 的 UILabel ,在dealloc 中程序就会crash ,改成其他名字无事.难道是apple的bug? 新写了个view测试了,还是没问题. 接着接着就发现了在dealloc方法中: [mainText release] ,mainText = nil; // NSLog(@"release %@",bgView); [bgView release]; // NSLog(@"release %@",originView); [originView release]; // NSLog(@"release %@",labelArray); [labelArray release]; // NSLog(@"release %@",mainText); [mainText release]; 该死的,不知道当时那根神经错了,居然释放了两次,当然出错咯.问题也解决了. 所以在确认释放对象的情况下一定要写成: [instance release],instance = nil ; 个人经验是,对于objective-c的内存管理都是得经过磨练才出来的,前期多犯错误是好事情. 当然我认识一个朋友 [...]]]></description>
			<content:encoded><![CDATA[<p>事情是这样的,4个月前我写了份实现类似下拉框选择操作的界面.<br />
一个月前,发现了这个View 在dealloc 会crash掉.<br />
多次调试无果,上 devForum.apple.com 询问也无人问津.<br />
今天决定再次调试下,还是没找到哪里出问题.<br />
最后决定求助 cocoachina 上的现场观众<br />
最后开始一行一行的注释代码做终极调试.</p>
<p>离谱的事情发现了,只要我创建一个名为 mainText 的 UILabel ,在dealloc 中程序就会crash ,改成其他名字无事.难道是apple的bug? 新写了个view测试了,还是没问题.</p>
<p>接着接着就发现了在dealloc方法中:<br />
<code> [mainText release] ,mainText = nil;<br />
//	NSLog(@"release %@",bgView);<br />
[bgView release];<br />
//	NSLog(@"release %@",originView);<br />
[originView release];<br />
//	NSLog(@"release %@",labelArray);<br />
[labelArray release];<br />
//	NSLog(@"release %@",mainText);<br />
[mainText release];<br />
</code><br />
该死的,不知道当时那根神经错了,居然释放了两次,当然出错咯.问题也解决了.</p>
<p>所以在确认释放对象的情况下一定要写成:<br />
[instance release],instance = nil ;</p>
<p>个人经验是,对于objective-c的内存管理都是得经过磨练才出来的,前期多犯错误是好事情.<br />
当然我认识一个朋友 ,他不释放任何对象,因为反正关闭iPhone后系统会处理的.这种觉悟不是大部分程序员有的,大家还是稳步前进咯.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a href="http://ixhan.com/2010/04/apple-such-a-bitch/" title="Apple 发疯了">Apple 发疯了</a></li><li><a href="http://ixhan.com/2009/12/dec-review/" title="12月串烧-年轻人就要飘逸">12月串烧-年轻人就要飘逸</a></li><li><a href="http://ixhan.com/2009/11/things-ive-done-in-past-5-months/" title="Things I&#8217;ve done int past 5 months">Things I&#8217;ve done int past 5 months</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/11/shit-on-objc-object-manager/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>游戏开发牛书推荐</title>
		<link>http://ixhan.com/2009/11/yoooo/</link>
		<comments>http://ixhan.com/2009/11/yoooo/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 16:45:21 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[游戏开发]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=194</guid>
		<description><![CDATA[在看一本叫 Programming Game AI By Examples 的书 （本来打算买实体书的，后来想想不能破例，还是down了本电子书 &#8220;） 看完第二章后彻底折服了 ，写的这么好的书真是不多见的 这才是真正的设计模式 ，寥寥几行代码就把整个世界给建模了 结构异常清晰，细节异常周到 堪称完美的作品 自己曾设计了不少不成型的东西，这次能见大师级别的代码确实收获颇多。 觉得一下子成长了不少。 而且最兴奋的是发现许多设计上的结构在许多地方都是雷同的 包括 Objective-c ，Box2d ，之前还一直觉得 box2d 使用起来还真是繁琐 创建一个对象还得先 ref 后才能创建 简单的说设计模式就是通过规范的设计和规范的代码（当然带来的结果是繁琐的代码会多了不少）带给清晰的结构和逻辑。在代码和功能越来越多时便显的尤其重要了。 在虚拟机里面把书上的例子全跑了一遍，决心花半年时间把所有东西消化，这些demo太吸引人了。 我的终极目标是做一个架构师，不只是用户，程序员也会使用我的产品。努力奋斗，会来的。：） 需要电子书的朋友网上自行搜索把，很多资源的，官网并提供源码和例程下载。 Related Posts经不住的似水流年StarCraft2 beta coming soon?永远的扫雷英雄(开源) 登场12月串烧-年轻人就要飘逸]]></description>
			<content:encoded><![CDATA[<p>在看一本叫 Programming Game AI By Examples 的书<br />
（本来打算买实体书的，后来想想不能破例，还是down了本电子书 &#8220;）<br />
看完第二章后彻底折服了 ，写的这么好的书真是不多见的<br />
这才是真正的设计模式 ，寥寥几行代码就把整个世界给建模了<br />
结构异常清晰，细节异常周到  堪称完美的作品<br />
自己曾设计了不少不成型的东西，这次能见大师级别的代码确实收获颇多。<br />
觉得一下子成长了不少。<br />
而且最兴奋的是发现许多设计上的结构在许多地方都是雷同的<br />
包括 Objective-c ，Box2d ，之前还一直觉得 box2d 使用起来还真是繁琐<br />
创建一个对象还得先 ref 后才能创建</p>
<p>简单的说设计模式就是通过规范的设计和规范的代码（当然带来的结果是繁琐的代码会多了不少）带给清晰的结构和逻辑。在代码和功能越来越多时便显的尤其重要了。</p>
<p>在虚拟机里面把书上的例子全跑了一遍，决心花半年时间把所有东西消化，这些demo太吸引人了。</p>
<p>我的终极目标是做一个架构师，不只是用户，程序员也会使用我的产品。努力奋斗，会来的。：）</p>
<p>需要电子书的朋友网上自行搜索把，很多资源的，官网并提供源码和例程下载。</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2010/03/%e7%bb%8f%e4%b8%8d%e4%bd%8f%e7%9a%84%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4/" title="经不住的似水流年">经不住的似水流年</a></li><li><a href="http://ixhan.com/2010/02/starcraft2-beta-coming-soon/" title="StarCraft2 beta coming soon?">StarCraft2 beta coming soon?</a></li><li><a href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a href="http://ixhan.com/2009/12/dec-review/" title="12月串烧-年轻人就要飘逸">12月串烧-年轻人就要飘逸</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/11/yoooo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>小试Unity游戏引擎</title>
		<link>http://ixhan.com/2009/11/glance-at-unity/</link>
		<comments>http://ixhan.com/2009/11/glance-at-unity/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 09:42:00 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=159</guid>
		<description><![CDATA[大四第一学期曾在学校的数字媒体实验室工作了很短时间，第一次看到现场手绘，maya做动画，zbrush绘制高模，倍感荣幸。 其中还有部分人在把弄一个游戏引擎（忘记叫什么名字了），可以让机器人在里面蹦蹦跳跳的走路。 那一刻让我想起第一次玩准3D游戏「生化危机II」的场景，震撼，鸡东的整个人在颤抖。 随着年龄的增长，对游戏的感觉也从狂热渐渐变成消磨时间，甚至忘记了小时候的梦想。 第一次游戏行业距离我这么近，却因为心有余而力不足放弃了。 回到标题上，自从 Unity 推出了免费版后，蠢蠢欲动，今天终于下载把玩了下。 一打开默认有个island的项目，场景做的很细腻，令我惊讶的是点击运行无需等待即可在场景中测试，很棒。 一遍看教程一遍开始了第一个测试项目。专业词汇挺多，没法像看程式书那样一下子就消化一堆。 最后还是不费力的做好了第一个场景，放了个对象在自己的小岛上跑了一圈，incredible! 简直想象不到眼前的居然是我做的。hohoho 暂时对Unity的感觉是，很简单，很高效，而且做出来的效果比我想象中好很多，顺便说说它使用的脚本语言 Unity JavaScript ，但是我怎么看也和我的老朋友 ActionScript3 更相似些 ，好处是可以少浪费时间看新语法书了。 附xhan&#8217;s 终极防御要塞。 这里是更多图片 Related Posts解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误now or neverTutorial of kissXML(iPhone)经不住的似水流年]]></description>
			<content:encoded><![CDATA[<p>大四第一学期曾在学校的数字媒体实验室工作了很短时间，第一次看到现场手绘，maya做动画，zbrush绘制高模，倍感荣幸。</p>
<p>其中还有部分人在把弄一个游戏引擎（忘记叫什么名字了），可以让机器人在里面蹦蹦跳跳的走路。</p>
<p>那一刻让我想起第一次玩准3D游戏「生化危机II」的场景，震撼，鸡东的整个人在颤抖。</p>
<p>随着年龄的增长，对游戏的感觉也从狂热渐渐变成消磨时间，甚至忘记了小时候的梦想。</p>
<p>第一次游戏行业距离我这么近，却因为心有余而力不足放弃了。</p>
<p>回到标题上，自从 Unity 推出了免费版后，蠢蠢欲动，今天终于下载把玩了下。</p>
<p>一打开默认有个island的项目，场景做的很细腻，令我惊讶的是点击运行无需等待即可在场景中测试，很棒。</p>
<p>一遍看教程一遍开始了第一个测试项目。专业词汇挺多，没法像看程式书那样一下子就消化一堆。</p>
<p>最后还是不费力的做好了第一个场景，放了个对象在自己的小岛上跑了一圈，incredible! 简直想象不到眼前的居然是我做的。hohoho</p>
<p>暂时对Unity的感觉是，很简单，很高效，而且做出来的效果比我想象中好很多，顺便说说它使用的脚本语言 Unity JavaScript ，但是我怎么看也和我的老朋友 ActionScript3 更相似些 ，好处是可以少浪费时间看新语法书了。</p>
<p>附xhan&#8217;s 终极防御要塞。</p>
<p style="text-align: center;"><a rel="attachment wp-att-160" href="http://ixhan.com/2009/11/glance-at-unity/bird-view/"><img class="aligncenter size-full wp-image-160" title="bird-view" src="http://ixhan.com/wp-content/uploads/2009/11/bird-view.png" alt="bird-view" width="395" height="368" /></a></p>
<p>这里是更多图片</p>
<p><span id="more-159"></span>
<a href='http://ixhan.com/2009/11/glance-at-unity/bird-view/' title='bird-view'><img width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/bird-view-150x150.png" class="attachment-thumbnail" alt="bird-view" title="bird-view" /></a>
<a href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-3-16-54-pm/' title='Screen shot 2009-11-07 at 3.16.54 PM'><img width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-3.16.54-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 3.16.54 PM" title="Screen shot 2009-11-07 at 3.16.54 PM" /></a>
<a href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-31-52-pm/' title='Screen shot 2009-11-07 at 5.31.52 PM'><img width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.31.52-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.31.52 PM" title="Screen shot 2009-11-07 at 5.31.52 PM" /></a>
<a href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-33-03-pm/' title='Screen shot 2009-11-07 at 5.33.03 PM'><img width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.33.03-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.33.03 PM" title="Screen shot 2009-11-07 at 5.33.03 PM" /></a>
<a href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-33-28-pm/' title='Screen shot 2009-11-07 at 5.33.28 PM'><img width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.33.28-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.33.28 PM" title="Screen shot 2009-11-07 at 5.33.28 PM" /></a>
</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2010/02/solve-windows-7-connect-unity-asset-server-pg_hba/" title="解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误">解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误</a></li><li><a href="http://ixhan.com/2010/05/now-or-never/" title="now or never">now or never</a></li><li><a href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li><li><a href="http://ixhan.com/2010/03/%e7%bb%8f%e4%b8%8d%e4%bd%8f%e7%9a%84%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4/" title="经不住的似水流年">经不住的似水流年</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/11/glance-at-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>让iPhoneApp发送带图片附件的邮件</title>
		<link>http://ixhan.com/2009/10/iphone-app-send-email-with-image/</link>
		<comments>http://ixhan.com/2009/10/iphone-app-send-email-with-image/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 03:03:37 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=73</guid>
		<description><![CDATA[更新（Nov 9,2009）: 在3.0系统中，sdk 提供了 MFMailComposeViewController 来显示发件界面，并提供附件功能。 if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mcvc = [[[MFMailComposeViewController alloc] init] autorelease]; mcvc.mailComposeDelegate = self; [mcvc setSubject:@"Here's a great photo!"]; NSString *body = @&#8221;&#60;h1&#62;Check this out&#60;/h1&#62;&#60;p&#62;I selected this image from the &#60;code&#62;&#60;b&#62;UIImagePickerController&#60;/b&#62;&#60;/code&#62;.&#60;/p&#62;&#8221;; [mcvc setMessageBody:body isHTML:YES]; [mcvc addAttachmentData:UIImageJPEGRepresentation(image, 1.0f) mimeType:@"image/jpeg" fileName:@"pickerimage.jpg"]; [self presentModalViewController:mcvc animated:YES]; } 在程序中如何启动系统的Email程序并在内容中添加图片附件？ 以下是代码： - (NSString *) base64EncodingWithLineLength:(unsigned [...]]]></description>
			<content:encoded><![CDATA[<p>更新（Nov 9,2009）:</p>
<p>在3.0系统中，sdk 提供了 MFMailComposeViewController 来显示发件界面，并提供附件功能。</p>
<blockquote><p>if ([MFMailComposeViewController canSendMail])<br />
{<br />
MFMailComposeViewController *mcvc = [[[MFMailComposeViewController alloc] init] autorelease];<br />
mcvc.mailComposeDelegate = self;<br />
[mcvc setSubject:@"Here's a great photo!"];<br />
NSString *body = @&#8221;&lt;h1&gt;Check this out&lt;/h1&gt;&lt;p&gt;I selected this image from the &lt;code&gt;&lt;b&gt;UIImagePickerController&lt;/b&gt;&lt;/code&gt;.&lt;/p&gt;&#8221;;<br />
[mcvc setMessageBody:body isHTML:YES];<br />
[mcvc addAttachmentData:UIImageJPEGRepresentation(image, 1.0f) mimeType:@"image/jpeg" fileName:@"pickerimage.jpg"];<br />
[self presentModalViewController:mcvc animated:YES];<br />
}</p></blockquote>
<p>在程序中如何启动系统的Email程序并在内容中添加图片附件？<br />
以下是代码：</p>
<pre class="brush: cpp;">
- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength data:(NSData *)imgData {

static const char *encodingTable = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&quot;;
const unsigned char *bytes = [imgData bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:[imgData length]];
unsigned long ixtext = 0;
unsigned long lentext = [imgData length];
long ctremaining = 0;
unsigned char inbuf[3], outbuf[4];
short i = 0;
short charsonline = 0, ctcopy = 0;
unsigned long ix = 0;

while( YES ) {
ctremaining = lentext - ixtext;
if( ctremaining &amp;lt;= 0 ) break;

for( i = 0; i &amp;lt; 3; i++ ) {
ix = ixtext + i;
if( ix &amp;lt; lentext ) inbuf[i] = bytes[ix]; 			else inbuf [i] = 0; 		} 		 		outbuf [0] = (inbuf [0] &amp;amp; 0xFC) &amp;gt;&amp;gt; 2;
outbuf [1] = ((inbuf [0] &amp;amp; 0x03) &amp;lt;&amp;lt; 4) | ((inbuf [1] &amp;amp; 0xF0) &amp;gt;&amp;gt; 4);
outbuf [2] = ((inbuf [1] &amp;amp; 0x0F) &amp;lt;&amp;lt; 2) | ((inbuf [2] &amp;amp; 0xC0) &amp;gt;&amp;gt; 6);
outbuf [3] = inbuf [2] &amp;amp; 0x3F;
ctcopy = 4;

switch( ctremaining ) {
case 1:
ctcopy = 2;
break;
case 2:
ctcopy = 3;
break;
}

for( i = 0; i &amp;lt; ctcopy; i++ )
[result appendFormat:@&quot;%c&quot;, encodingTable[outbuf[i]]];

for( i = ctcopy; i &amp;lt; 4; i++ ) 			[result appendFormat:@&quot;%c&quot;,'=']; 		 		ixtext += 3; 		charsonline += 4; 		 		if( lineLength &amp;gt; 0 ) {
if (charsonline &amp;gt;= lineLength) {
charsonline = 0;
[result appendString:@&quot;\n&quot;];
}
}
}

return result;
}
</pre>
<pre class="brush: cpp;">
- (void) emailButtonPressed:(id)sender {

NSString *body = @&quot;&quot;;

NSData *imageData = nil ;
NSString* dataStr = nil ;
for (PhotoItem* item in _photoBoardView.itemsSelected) {
imageData = UIImageJPEGRepresentation(item.photo.image.image,0.9);
dataStr = [self base64EncodingWithLineLength:0 data:imageData];
body = [body stringByAppendingFormat:@&quot;&lt;strong&gt;&lt;img src=&quot;data:image/jpg;base64,%@&quot; alt=&quot; image&quot; /&gt;&lt;/strong&gt;&quot;,dataStr];
}
body = [body stringByAppendingString:@&quot;&quot;];

NSString *encoded = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *atitle = [[@&quot;&quot; stringByAppendingFormat:@&quot;title: %@&quot;, @&quot;Image &quot;] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString * urlString = [@&quot;&quot; stringByAppendingFormat:@&quot;mailto:%@?subject=%@&amp;amp;body=%@&quot;, @&quot;&quot;,atitle, encoded];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
</pre>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2010/05/now-or-never/" title="now or never">now or never</a></li><li><a href="http://ixhan.com/2010/04/a-new-approach-to-my-career/" title="A new approach to my career">A new approach to my career</a></li><li><a href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li><li><a href="http://ixhan.com/2010/02/what-is-ipad-all-about/" title="What is iPad All About?  ">What is iPad All About?  </a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/10/iphone-app-send-email-with-image/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>关于“字节序”</title>
		<link>http://ixhan.com/2009/10/little-about-byte-order/</link>
		<comments>http://ixhan.com/2009/10/little-about-byte-order/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 08:49:29 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[byte order]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=68</guid>
		<description><![CDATA[昨天纠正了长达几年的关于字节序的错误理解。 受到移位操作符的影响，一直认为在内存中数字的保存方式和显示的一样，比如一个2直接的short 9 ，保存在内存中应该是： 00 09 这种形式，因为这样移位才说的通。 否则如果按照低字节优先的方法 09 00 右移位就会出乱子了～ 结果昨天研究和服务器socket通讯的例子中 发现了个陌生函数 ：htonl  。 man （越来越喜欢命令行了）后发现是 host to network long(short) 的缩写 ，这下彻底困惑了。难道 c 在内存中的数据不是想象中的那样？ 最后K大侠亲自上阵，示范了使用GDB debug ，也帮我验证了我多年的错误观点： #include &#60;stdio.h&#62; int main() { int a = 8; char *p; p= (char*)&#38;a; a = a&#62;&#62;1; char *k = &#38;a; return 0; } gcc -g test.c   # [...]]]></description>
			<content:encoded><![CDATA[<p>昨天纠正了长达几年的关于字节序的错误理解。</p>
<p>受到移位操作符的影响，一直认为在内存中数字的保存方式和显示的一样，比如一个2直接的short 9 ，保存在内存中应该是：</p>
<p>00 09 这种形式，因为这样移位才说的通。 否则如果按照低字节优先的方法 09 00 右移位就会出乱子了～</p>
<p>结果昨天研究和服务器socket通讯的例子中 发现了个陌生函数 ：htonl  。</p>
<p>man （越来越喜欢命令行了）后发现是 host to network long(short) 的缩写 ，这下彻底困惑了。难道 c 在内存中的数据不是想象中的那样？</p>
<p>最后K大侠亲自上阵，示范了使用GDB debug ，也帮我验证了我多年的错误观点：</p>
<pre class="brush: cpp;">

#include &lt;stdio.h&gt;

int main()
{
 int a = 8;
 char *p;
 p= (char*)&amp;a;

 a = a&gt;&gt;1;
 char *k = &amp;a;

 return 0;
}
</pre>
<ul>
<li>gcc -g test.c   # -g 添加调试</li>
<li>gdb test.out   # init</li>
<li>b main          # add breakpoint at main function</li>
<li>run                 # just run until breakPoint occured</li>
<li>n                    # next</li>
</ul>
<p>逐次打印出 p 指针的值 p *(p++)   , 发现果然是地位在最前面的。<br />
不过对于移位操作就困惑了，难道这个操作不是直接在内存操作的？难道是先转成高位优先然后移位再转回来？<span id="more-68"></span></p>
<p>附一篇介绍比较详细的文章，<a href="http://www.blogjava.net/byterat/archive/2007/10/24/155471.html">来源</a></p>
<blockquote><p>BIG-ENDIAN（大字节序、高字节序）<br />
LITTLE-ENDIAN（小字节序、低字节序）<br />
主机字节序<br />
网络字节顺序<br />
JAVA字节序</p>
<p>1．BIG-ENDIAN、LITTLE-ENDIAN跟多字节类型的数据有关的比如int,short,long型，而对单字节数据byte却没有影 响。BIG-ENDIAN就是低位字节排放在内存的低端，高位字节排放在内存的高端。而LITTLE-ENDIAN正好相反。<br />
比如 int a = 0&#215;05060708<br />
在BIG-ENDIAN的情况下存放为：<br />
字节号 0 1 2 3<br />
数据 05 06 07 08<br />
在LITTLE-ENDIAN的情况下存放为：<br />
字节号 0 1 2 3<br />
数据 08 07 06 05</p>
<p>2．BIG-ENDIAN、LITTLE-ENDIAN、跟CPU有关的，每一种CPU不是BIG-ENDIAN就是LITTLE-ENDIAN、。IA 架构的CPU中是Little-Endian，而PowerPC 、SPARC和Motorola处理器。这其实就是所谓的主机字节序。而网络字节序是指数据在网络上传输时是大头还是小头的，在Internet的网络字 节序是BIG-ENDIAN。所谓的JAVA字节序指的是在JAVA虚拟机中多字节类型数据的存放顺序，JAVA字节序也是BIG-ENDIAN。</p>
<p>3．所以在用C/C++写通信程序时，在发送数据前务必用htonl和htons去把整型和短整型的数据进行从主机字节序到网络字节序的转换，而接收数据 后对于整型和短整型数据则必须调用ntohl和ntohs实现从网络字节序到主机字节序的转换。如果通信的一方是JAVA程序、一方是C/C++程序时， 则需要在C/C++一侧使用以上几个方法进行字节序的转换，而JAVA一侧，则不需要做任何处理，因为JAVA字节序与网络字节序都是BIG- ENDIAN，只要C/C++一侧能正确进行转换即可（发送前从主机序到网络序，接收时反变换）。如果通信的双方都是JAVA，则根本不用考虑字节序的问 题了。</p>
<p>4．如果网络上全部是PowerPC,SPARC和Motorola CPU的主机那么不会出现任何问题，但由于实际存在大量的IA架构的CPU，所以经常出现数据传输错误。</p>
<p>5．文章开头所提出的问题，就是因为程序运行在X86架构的PC SERVER上，发送数据的一端用C实现的，接收一端是用JAVA实现的，而发送端在发送数据前未进行从主机字节序到网络字节序的转换，这样接收端接收到 的是LITTLE-ENDIAN的数据，数据解释自然出错。<br />
具体数据如下，实际发送的数据为23578<br />
发送端发送数据： 1A 5C<br />
接收端接收到数据后，按BIG-ENDIAN进行解释具体数据是多少？你们自己去计算并比较吧！</p>
<p>=============================================================================================== <span style="color: #333333;"><span style="color: #333333;">Big Endian and Little Endian</p>
<p>谈到字节序的问题，必然牵涉到两大CPU派系。那就是Motorola的PowerPC系列CPU和Intel的x86系列CPU。PowerPC系列采 用big endian方式存储数据，而x86系列则采用little endian方式存储数据。那么究竟什么是big endian，什么又是little endian呢？</p>
<p>其实big endian是指低地址存放最高有效字节（MSB），而little endian则是低地址存放最低有效字节（LSB），即常说的低位在先，高位在后。<br />
用文字说明可能比较抽象，下面用图像加以说明。比如数字0&#215;12345678在两种不同字节序CPU中的存储顺序如下所示：</p>
<p>Big Endian</p>
<p>低地址                           高地址<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&gt;<br />
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />
|     12     |      34    |     56      |     78    |<br />
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</p>
<p>Little Endian</p>
<p>低地址                           高地址<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&gt;<br />
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />
|     78     |      56    |     34      |     12    |<br />
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</p>
<p>从上面两图可以看出，采用big endian方式存储数据是符合我们人类的思维习惯的。而little endian，!@#$%^&amp;*，见鬼去吧 -_-|||<br />
</span></span></p></blockquote>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li><li><a href="http://ixhan.com/2010/02/work-with-passion/" title="work with passion">work with passion</a></li><li><a href="http://ixhan.com/2009/11/things-ive-done-in-past-5-months/" title="Things I&#8217;ve done int past 5 months">Things I&#8217;ve done int past 5 months</a></li><li><a href="http://ixhan.com/2009/10/how-software-companies-die/" title=" [转]软件公司是怎么死掉的"> [转]软件公司是怎么死掉的</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/10/little-about-byte-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iPhone]播放midi文件</title>
		<link>http://ixhan.com/2009/10/how-to-let-iphone-play-midi-file/</link>
		<comments>http://ixhan.com/2009/10/how-to-let-iphone-play-midi-file/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 15:41:57 +0000</pubDate>
		<dc:creator>xhan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[midi]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=62</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>iPhone 默认不带播放MIDI的框架，所以播放MIDI还得寻求第3方的库帮忙。</p>
<p>这里使用的库就是大名鼎鼎的 <a href="http://www.fmod.org/">FMOD</a> ,许多火爆游戏使用的都是这个库。开发者可以免费下载使用。</p>
<p>首先下载安装 FMOD API FOR IPHONE：<br />
<a href="http://www.fmod.org/index.php/release/version/fmodapi42607iphone-installer.dmg" target="_blank">http://www.fmod.org/index.php/release/version/fmodapi42607iphone-installer.dmg</a></p>
<p>安装后可以在目录中看到不少示范代码，可惜没有MIDI。</p>
<p>自己写一个：）<br />
感谢强大的api，写起来异常轻松。</p>
<ul>
<li>新建一个基于view项目</li>
<li>修改项目属性，添加 Other Linker Flags 为 -lfmodexL_$PLATFORM_NAME</li>
<li>添加 Header Search Paths ：/Developer/FMOD\ Programmers\ API\ iPhone/api/inc  （默认是这个位置，修改成自己FMOD安装的目录）</li>
<li>添加 Library Search Paths ：/Developer/FMOD\ Programmers\ API\ iPhone/api/lib （同上）</li>
<li>把 appDelegate 修改成 .mm 的后缀</li>
<li>MIDI 播放需要一个 DLS 文件， 在osx 下没找到，这里使用了xp 自带的 gm.dls 文件（3M 有点大～）,拷贝到项目中。</li>
<li>修改ViewController 代码如下 ，随便在xib文件中链接两个按钮action上即可</li>
<li>运行（真机有效）</li>
</ul>
<p>主要源码：<span id="more-62"></span></p>
<p><script src="http://gist.github.com/202178.js"></script></p>
<p>项目打包下载（懒人专用包）<a href="http://ixhan.com/wp-content/uploads/2009/10/PlayMidiDemo.zip">PlayMidiDemo</a></p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a href="http://ixhan.com/2010/05/now-or-never/" title="now or never">now or never</a></li><li><a href="http://ixhan.com/2010/04/a-new-approach-to-my-career/" title="A new approach to my career">A new approach to my career</a></li><li><a href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/10/how-to-let-iphone-play-midi-file/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>命令行的伟大</title>
		<link>http://ixhan.com/2009/10/incredible-of-bash-code/</link>
		<comments>http://ixhan.com/2009/10/incredible-of-bash-code/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 14:47:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://ixhan.com/?p=30</guid>
		<description><![CDATA[曾经用Ruby 写了个脚本用来统计项目中文件行数，没事打发下时间顺便满足下小小的虚荣感。 发于cocoaChina论坛中（http://cocoachina.com/bbs/read.php?tid-8266.html）。 结果惨遭鄙视。 原来用 bash 一句话就可以搞定 ！（用Ruby还写了那么多代码～悲剧了～） find . -name '*.m' -exec cat {} \; &#124; wc -l find . -name '*.h' -exec cat {} \; &#124; wc -l find . -name &#34;*.m&#34;  &#124;xargs wc -l 掌握一些常用命令还是很能提高工作效率的。学习中。 Related Posts永远的扫雷英雄(开源) 登场OSX Terminal(终端) 使用快捷键2009年10月15日Downloads]]></description>
			<content:encoded><![CDATA[<p>曾经用Ruby 写了个脚本用来统计项目中文件行数，没事打发下时间顺便满足下小小的虚荣感。</p>
<p>发于cocoaChina论坛中（<a href="http://cocoachina.com/bbs/read.php?tid-8266.html">http://cocoachina.com/bbs/read.php?tid-8266.html</a>）。</p>
<p>结果惨遭鄙视。</p>
<p>原来用 bash 一句话就可以搞定 ！（用Ruby还写了那么多代码～悲剧了～）</p>
<pre class="brush: bash;">

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

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

find . -name &quot;*.m&quot;  |xargs wc -l
</pre>
<p>掌握一些常用命令还是很能提高工作效率的。学习中。</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a href="http://ixhan.com/2009/11/osx-terminal-keyshort/" title="OSX Terminal(终端) 使用快捷键">OSX Terminal(终端) 使用快捷键</a></li><li><a href="http://ixhan.com/2009/10/15th/" title="2009年10月15日">2009年10月15日</a></li><li><a href="http://ixhan.com/downloads/" title="Downloads">Downloads</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ixhan.com/2009/10/incredible-of-bash-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
