﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Onway</title><link>http://www.cppblog.com/Onway/</link><description>我是一只菜菜菜菜鸟...</description><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 14:45:21 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 14:45:21 GMT</pubDate><ttl>60</ttl><item><title>认识matplotlib</title><link>http://www.cppblog.com/Onway/archive/2017/02/11/214675.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Sat, 11 Feb 2017 07:12:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2017/02/11/214675.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/214675.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2017/02/11/214675.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/214675.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/214675.html</trackback:ping><description><![CDATA[<strong style="color: #454545; font-family: Helvetica; font-size: 12px;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">一，</span><span style="font-size: 14pt;">matplotlib</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">是什么</span></strong><br />
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">在</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">python</span><span style="font-size: 14pt;">中用于数据库可视化的</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">2D</span><span style="font-size: 14pt;">绘图库。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>二，安装</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="font-size: 14pt;"><a href="http://matplotlib.org/users/installing.html">http://matplotlib.org/users/installing.html</a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>三，交互模式与非交互模式</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">1</span><span style="font-size: 14pt;">，非交互模式</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">在</span><span style="font-size: 14pt;">python shell</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">里面执行</span></p>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff; font-size: 12pt;">import</span><span style="font-size: 12pt;">&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt</span><br />
<span style="font-size: 12pt;">plt.plot([</span><span style="font-size: 12pt;">1</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">])</span><br />
<span style="font-size: 12pt;">plt.show()</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">执行</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">show</span><span style="font-size: 14pt;">之后会打开一个</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">GUI</span><span style="font-size: 14pt;">窗口显示，同时交互命令会阻塞。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><img src="http://www.cppblog.com/images/cppblog_com/onway/show_cmd.png" width="400" height="314" alt="" /><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">2</span><span style="font-size: 14pt;">，交互模式</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">matplotlib.is_interactive()可以查看当前是否在交互模式；</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">matplotlib.pyplot.ion()用于打开交互模式；</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">matplotlib.pyplot.ioff()用于关闭交互模式；</span></p>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff; font-size: 12pt;">import</span><span style="font-size: 12pt;">&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt</span><br />
<span style="font-size: 12pt;">plt.ion()</span><br />
<span style="font-size: 12pt;">plt.plot([</span><span style="font-size: 12pt;">1</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">2])</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">执行</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">plot</span><span style="font-size: 14pt;">之后打开了一个</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">GUI</span><span style="font-size: 14pt;">窗口，交互命令没有阻塞，继续执行：</span></p>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="font-size: 12pt;">plt.plot([2</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">3])</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">可以看到在窗口里面再画了一条线。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">也就是在非交互模式，需要一次画好再调用</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">show</span><span style="font-size: 14pt;">显示；而交互模式在每次绘制后都能实时看到效果。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545; min-height: 17px;"><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><strong><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">3，ipython的</span><span style="font-size: 14pt;">magic command</span>&nbsp;</strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">在ipython的%matplotlib也可以打开交互模式。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">在交互模式中如果某些修改没有自动刷新，可以调用matplotlib.pyplot.draw()刷新。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545; min-height: 17px;"><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>四，在jupyter notebook中使用matplotlib</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>1，%matplotlib</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">以交互模式打开独立的GUI窗口，对同一个figure的绘制都自动刷新到对应的GUI窗口。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong><br />
</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>2，％matplotlib notebook</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">同%matplotlib，只是会将GUI窗口嵌入到cell的输出。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><img src="http://www.cppblog.com/images/cppblog_com/onway/matplotlib_notebook.png" width="400" height="302" alt="" /><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong><br />
</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>3，%matplotlib inline</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">将绘制的图转换为静态图片嵌入到cell的输出。在不同的cell进行绘制效果不会叠加。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><img src="http://www.cppblog.com/images/cppblog_com/onway/matplotlib_inline.png" width="400" height="269" alt="" /><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545; min-height: 14px;"><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="font-size: 14pt;">五，</span><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">figure</span><span style="font-size: 14pt;">的各个组成部分</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="font-size: 14pt;"><a href="http://matplotlib.org/faq/usage_faq.html#parts-of-a-figure">http://matplotlib.org/faq/usage_faq.html#parts-of-a-figure</a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><strong><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">六，</span><span style="font-size: 14pt;">matplotlib</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">的两种绘图接口</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><strong><span style="font-size: 14pt;">1</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">，</span><span style="font-size: 14pt;">matlab</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">风格接口</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">所有的</span><span style="font-size: 14pt;">plt</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">命令都会应用到自动创建的</span><span style="font-size: 14pt;">&#8220;</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">当前</span><span style="font-size: 14pt;">&#8221;</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">的</span><span style="font-size: 14pt;">figure</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">和</span><span style="font-size: 14pt;">axes</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">对象。使用</span><span style="font-size: 14pt;">plt.gcf</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">和</span><span style="font-size: 14pt;">plt.gca</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">获取</span><span style="font-size: 14pt;">&#8220;</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">当前</span><span style="font-size: 14pt;">&#8221;</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">的</span><span style="font-size: 14pt;">figure</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">和</span><span style="font-size: 14pt;">axes</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">调用</span><span style="font-size: 14pt;">plt.plot([1, 2])</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">即绘制到自动创建的</span><span style="font-size: 14pt;">figure</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">和</span><span style="font-size: 14pt;">axes</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">。</span></p>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="font-size: 12pt;">plt.plot([1</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">])</span><br />
<span style="font-size: 12pt;">plt.plot([</span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">1])</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;"><br />
</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">2</span><span style="font-size: 14pt;">，面向对象接口</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">显式获得绘制对象，在特定对象执行相应操作。</span></p>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="font-size: 12pt;">fig,&nbsp;ax&nbsp;=</span><span style="font-size: 12pt;">&nbsp;plt.subplots()</span><br />
<span style="font-size: 12pt;">ax.plot([</span><span style="font-size: 12pt;">1</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">])</span><br />
<span style="font-size: 12pt;">ax.plot([</span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">,&nbsp;</span><span style="font-size: 12pt;">1])</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;"><br />
</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><strong><span style="line-height: normal; font-family: Helvetica; font-size: 14pt;">3</span><span style="font-size: 14pt;">，差别</span></strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">对于简单绘制两种接口的差别不大，复杂情况面向对象接口会更合适。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545;"><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">另外</span><span style="font-size: 14pt;">plt</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">的很多函数都可以直接转为</span><span style="font-size: 14pt;">ax</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">的函数，例如</span><span style="font-size: 14pt;">plt.plot() -&gt; ax.plot()</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">，但某些会有差别，例如</span><span style="font-size: 14pt;">plt.xlabel() -&gt; ax.set_xlabel()</span><span style="line-height: normal; font-family: 'PingFang SC'; font-size: 14pt;">。</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545; min-height: 14px;"><strong style="font-size: 14pt; font-family: 'PingFang SC';"><br />
</strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545; min-height: 14px;"><strong style="font-size: 14pt; font-family: 'PingFang SC';">七，各类图形demo</strong></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #e4af09;"><span style="font-size: 14pt;"><a href="http://matplotlib.org/gallery.html">http://matplotlib.org/gallery.html</a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><br />
</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><strong>八，API</strong></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;"><a href="http://matplotlib.org/api/index.html">http://matplotlib.org/api/index.html</a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545; min-height: 14px;"><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #454545; min-height: 14px;"><br />
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;"><span style="font-size: 14pt;">参考：</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="color: #454545; font-size: 14pt;">1</span><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;">，<a href="http://matplotlib.org/index.html#"><span style="line-height: normal; font-family: Helvetica; color: #e4af09; font-size: 14pt;">http://matplotlib.org/index.html#</span></a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="color: #454545; font-size: 14pt;">2</span><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;">，<a href="http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode"><span style="line-height: normal; font-family: Helvetica; color: #e4af09; font-size: 14pt;">http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode</span></a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="color: #454545; font-size: 14pt;">3</span><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;">，<a href="http://jupyter.org"><span style="line-height: normal; font-family: Helvetica; color: #e4af09; font-size: 14pt;">http://jupyter.org</span></a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="color: #454545; font-size: 14pt;">4</span><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;">，<a href="http://www.labri.fr/perso/nrougier/teaching/matplotlib/#introduction"><span style="line-height: normal; font-family: Helvetica; color: #e4af09; font-size: 14pt;">http://www.labri.fr/perso/nrougier/teaching/matplotlib/#introduction</span></a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'PingFang SC'; color: #454545;">
</p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="color: #454545; font-size: 14pt;">5</span><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;">，<a href="http://nbviewer.jupyter.org/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/04.00-Introduction-To-Matplotlib.ipynb#Two-Interfaces-for-the-Price-of-One"><span style="line-height: normal; font-family: Helvetica; color: #e4af09; font-size: 14pt;">http://nbviewer.jupyter.org/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/04.00-Introduction-To-Matplotlib.ipynb#Two-Interfaces-for-the-Price-of-One</span></a></span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; color: #e4af09;"><span style="line-height: normal; font-family: 'PingFang SC'; color: #454545; font-size: 14pt;"></span></p><img src ="http://www.cppblog.com/Onway/aggbug/214675.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2017-02-11 15:12 <a href="http://www.cppblog.com/Onway/archive/2017/02/11/214675.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>goldendict的有道词典扩展程序：eyoudao-1.4</title><link>http://www.cppblog.com/Onway/archive/2016/02/15/212820.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Mon, 15 Feb 2016 11:57:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2016/02/15/212820.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/212820.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2016/02/15/212820.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/212820.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/212820.html</trackback:ping><description><![CDATA[<div><span style="font-family: 'Times New Roman'; font-size: 14pt;">一晃N年过去了。<br /><br /></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">windows的有道词典都不知道升级到哪个版本了。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">linux的有道词典官方版本也出来了。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">goldendict已经1.5版本了。<br /><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">博客上几个月前居然还有一条关于这个东西的评论。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">将代码找回来试了一下居然还能跑，有道的api和xml格式还是真是稳定啊。<br /><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">简单修改了一下install脚本，重写了README，收到github了：</span></div><div><a href="https://github.com/Onway/eyoudao"><span style="font-family: 'Times New Roman'; font-size: 14pt;">https://github.com/Onway/eyoudao</span></a></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">原1.3版本：</span></div><div><a href="http://www.cppblog.com/Onway/archive/2012/10/22/193668.html"><span style="font-family: 'Times New Roman'; font-size: 14pt;">http://www.cppblog.com/Onway/archive/2012/10/22/193668.html</span></a></div><img src ="http://www.cppblog.com/Onway/aggbug/212820.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2016-02-15 19:57 <a href="http://www.cppblog.com/Onway/archive/2016/02/15/212820.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简单的socks5代理程序：ThisSocks</title><link>http://www.cppblog.com/Onway/archive/2016/02/12/212809.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Fri, 12 Feb 2016 09:50:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2016/02/12/212809.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/212809.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2016/02/12/212809.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/212809.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/212809.html</trackback:ping><description><![CDATA[<div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>背景</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">前段时间在digitalocean租了vps搭建shadowsocks，简单看了一下socks5协议，决定自己也造一个小轮子玩玩。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">春节在家整理了一下代码，大神轻拍。</span></div><div><a href="https://github.com/Onway/ThisSocks">https://github.com/Onway/ThisSocks<br /><br /></a></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>功能</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">代码是c++，在linux基于perfork+select实现的，目前的功能有：</span></div><div><ul><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">TCP代理</span></li><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">远程DNS</span></li><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">用户验证</span></li><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">数据加密</span></li></ul></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;"><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>过程</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">开发调试的过程发现两点比较有意思：</span></div><div><ol><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">偶尔会收到RST的数据包，查看代码日志，用tcpdump在两端抓包并无发现异常</span></li><li><span style="font-family: 'Times New Roman'; font-size: 14pt;">访问某些网站总是会收到RST数据包造成无法访问</span></li></ol></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">对上述第二点加入了非常简单的数据加密后就解决了哈，shadowsocks的加密应该就是这么用的吧。<br /><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>缺陷</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">功能上没有支持UDP，ie和chrome浏览器似乎都不支持socks5，只能先用着firefox了。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">在windows也用c#做了一个客户端，但无暇顾及已经好久没更新了。<br /><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>其他</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">可能跟所用宽带有关，访问digitalocean的时延超过300ms，网站只能打开首页，登录页面都加载不全，慎用。</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">前些天收到邮件说是vps出现流量异常被关闭了，还无法登录管理页面，用lantern也一直连不上。(T_T)</span></div><img src ="http://www.cppblog.com/Onway/aggbug/212809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2016-02-12 17:50 <a href="http://www.cppblog.com/Onway/archive/2016/02/12/212809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>APUE第二章 UNIX标准化及实现</title><link>http://www.cppblog.com/Onway/archive/2015/12/08/212438.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Tue, 08 Dec 2015 14:35:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/12/08/212438.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/212438.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/12/08/212438.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/212438.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/212438.html</trackback:ping><description><![CDATA[<span style="font-size: 14pt;"> </span><div><strong><span style="font-size: 14pt;">1, 三个标准</span></strong><br /><span style="font-size: 14pt;">1.1, ISO C标准由ISO/IEC维护开发</span><br /><span style="font-size: 14pt;">最新版本是C11，共有29个标准头文件。</span><br /><br /><span style="font-size: 14pt;">1.2, POSIX是一系列由IEEE制定的标准</span><br /><span style="font-size: 14pt;">POSIX包括ISO C标准库函数。</span><br /><span style="font-size: 14pt;">POSIX标准的1988版本是IEEE 1003.1-1988，经过修改后作为IEEE Std.1003.1-1990提交ISO，成为国际标准ISO/IEC 9945-1:1990,该标准通常称为POSIX.1。</span><br /><span style="font-size: 14pt;">当前最新版本是POSIX.1-2008，由IEEE和Open Group共同开发。</span><br /><br /><span style="font-size: 14pt;">1.3, SUS是POSIX的超集，其系统接口全集称为XSI</span><br /><span style="font-size: 14pt;">The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group.</span><br /><span style="font-size: 14pt;">只有遵循XSI的实现才能称为UNIX系统。</span><br /><span style="font-size: 14pt;">当前的最新版本是SUSv4。</span><br /><br /><span style="font-size: 14pt;">1.4, 找到一些网址</span><br /><span style="font-size: 14pt;">C11</span><br /><a href="http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853">http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853</a><br /><br /><span style="font-size: 14pt;">POSIX.1-2008</span><br /><a href="http://pubs.opengroup.org/onlinepubs/9699919799/">http://pubs.opengroup.org/onlinepubs/9699919799/</a><br /><a href="https://standards.ieee.org/findstds/standard/1003.1-2008.html">https://standards.ieee.org/findstds/standard/1003.1-2008.html</a><br /><br /><span style="font-size: 14pt;">SUSv4</span><br /><a href="https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=12310">https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=12310</a><br /><a href="https://en.wikipedia.org/wiki/Single_UNIX_Specification#cite_note-11">https://en.wikipedia.org/wiki/Single_UNIX_Specification#cite_note-11</a><br /><br /><strong><span style="font-size: 14pt;">2, 限制</span></strong><br /><span style="font-size: 14pt;">2.1 两种限制</span><br /><span style="font-size: 14pt;">编译时限制和运行时限制。</span><br /><span style="font-size: 14pt;">编译时限制通过头文件获取；</span><br /><span style="font-size: 14pt;">不与文件或目录相关的运行时限制通过sysconf函数获取；</span><br /><span style="font-size: 14pt;">与文件或目录相关的运行时限制通过pathconf和fpathconf函数获取。</span><br /><br /><span style="font-size: 14pt;">2.2 ISO C限制</span><br /><span style="font-size: 14pt;">都是编译时限制，主要定义在&lt;limits.h&gt;里面。</span><br /><a href="http://en.cppreference.com/w/c/types/limits">http://en.cppreference.com/w/c/types/limits</a><br /><br /><span style="font-size: 14pt;">2.3 POSIX限制和XSI限制</span><br /><span style="font-size: 14pt;">书中列出的都是实现中必须支持的各种最小值，特定系统实际支持的限制值需要通过头文件或者三个函数函数获取。</span><br /><span style="font-size: 14pt;">三个函数的name参数是限制名前面加_SC_或者_PC_前缀得到。</span><br /><a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html">http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html</a><br /><br /><span style="font-size: 14pt;">2.4 书中代码</span><br /><span style="font-size: 14pt;"></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">/*</span><span style="color: #008000; "><br />&nbsp;*&nbsp;If&nbsp;&nbsp;name&nbsp;&nbsp;is&nbsp;&nbsp;invalid,&nbsp;-1&nbsp;is&nbsp;returned,&nbsp;and&nbsp;errno&nbsp;is&nbsp;set&nbsp;to&nbsp;EINVAL.<br />&nbsp;*&nbsp;Otherwise,&nbsp;the&nbsp;value&nbsp;returned&nbsp;is&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;system&nbsp;resource&nbsp;and&nbsp;errno&nbsp;is&nbsp;not&nbsp;changed.<br />&nbsp;*&nbsp;In&nbsp;the&nbsp;case&nbsp;of&nbsp;options,&nbsp;a&nbsp;positive&nbsp;value&nbsp;is&nbsp;returned&nbsp;if&nbsp;a&nbsp;queried&nbsp;option&nbsp;is&nbsp;available,&nbsp;and&nbsp;-1&nbsp;if&nbsp;it&nbsp;is&nbsp;not.<br />&nbsp;*&nbsp;In&nbsp;the&nbsp;case&nbsp;of&nbsp;limits,&nbsp;-1&nbsp;means&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;definite&nbsp;limit.<br /></span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br /><br />#include&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">apue.h</span><span style="color: #000000; ">"</span><span style="color: #000000; "><br />#include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">errno.h</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">limits.h</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br /><br />#ifdef&nbsp;OPEN_MAX<br /></span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;openmax&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;OPEN_MAX;<br /></span><span style="color: #0000FF; ">#else</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;openmax&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br /></span><span style="color: #0000FF; ">#endif</span><span style="color: #000000; "><br /><br /></span><span style="color: #008000; ">/*</span><span style="color: #008000; "><br />&nbsp;*&nbsp;If&nbsp;OPEN_MAX&nbsp;is&nbsp;indeterminate,&nbsp;we're&nbsp;not<br />&nbsp;*&nbsp;guaranteed&nbsp;that&nbsp;this&nbsp;is&nbsp;adequate<br />&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">#define</span><span style="color: #000000; ">&nbsp;OPEN_MAX_GUESS&nbsp;256</span><span style="color: #000000; "><br /><br /></span><span style="color: #0000FF; ">long</span><span style="color: #000000; "><br />open_max(</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(openmax&nbsp;</span><span style="color: #000000; ">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)&nbsp;{&nbsp;</span><span style="color: #008000; ">/*</span><span style="color: #008000; ">&nbsp;first&nbsp;time&nbsp;through&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errno&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;((openmax&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;sysconf(_SC_OPEN_MAX))&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(errno&nbsp;</span><span style="color: #000000; ">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;openmax&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;OPEN_MAX_GUESS;&nbsp;</span><span style="color: #008000; ">/*</span><span style="color: #008000; ">&nbsp;it's&nbsp;indeterminate&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;err_sys(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">sysconf&nbsp;error&nbsp;for&nbsp;_SC_OPEN_MAX</span><span style="color: #000000; ">"</span><span style="color: #000000; ">;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">(openmax);<br />}</span></div><br /><strong><span style="font-size: 14pt;">3, 选项</span></strong><br /><span style="font-size: 14pt;">3.1, 选项确定方式</span><br /><span style="font-size: 14pt;">编译时选项定义在&lt;unistd.h&gt;中；</span><br /><span style="font-size: 14pt;">与文件或目录无关的选项用sysconf确定；</span><br /><span style="font-size: 14pt;">与文件或目录有关的选项用pathconf或者fpathconf确定；</span><br /><a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html">http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html</a><br /><br /><span style="font-size: 14pt;">3.2, 选项确定流程</span><br /><span style="font-size: 14pt;">如果符号常量未定义，</span><br /><span style="font-size: 14pt;">对_POSIX前缀的选项，将_POSIX前缀替换为_SC或_PC前缀，</span><br /><span style="font-size: 14pt;">对_XOPEN前缀的选项，在_XOPEN前面加上_SC或_PC前缀，</span><br /><span style="font-size: 14pt;">然后调用sysconf, pathconf或fpathconf函数。</span><br /><span style="font-size: 14pt;">如果符号常量已经定义，则有三种可能：</span><br /><span style="font-size: 14pt;">值为-1，不支持相应的选项；</span><br /><span style="font-size: 14pt;">值大于0，支持相应的选项；</span><br /><span style="font-size: 14pt;">值为0，需调用函数确定选项是否支持。</span><br /><span style="font-size: 14pt;">注：某些系统可能出现定义了符号常量，但没有定义值的情况。</span><br /><br /><span style="font-size: 14pt;">3.4, 代码示例</span><br /><span style="font-size: 14pt;">先占坑。</span><br /><br /><strong><span style="font-size: 14pt;">4, 功能测试宏</span></strong><br /><span style="font-size: 14pt;">Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.</span><br /><span style="font-size: 14pt;">NOTE:&nbsp; In&nbsp; order&nbsp; to be effective, a feature test macro must be defined before including any header files.&nbsp; This can be done either in the compilation command (cc -DMACRO=value) or by defining the macro within the source code before including any headers.</span><br /><span style="font-size: 14pt;">see man page feature_test_macros(7).</span></div><img src ="http://www.cppblog.com/Onway/aggbug/212438.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-12-08 22:35 <a href="http://www.cppblog.com/Onway/archive/2015/12/08/212438.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shadowsocks</title><link>http://www.cppblog.com/Onway/archive/2015/12/06/212428.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Sun, 06 Dec 2015 09:18:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/12/06/212428.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/212428.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/12/06/212428.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/212428.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/212428.html</trackback:ping><description><![CDATA[<div><strong style="font-size: 14pt;">1, shadowsocks home page</strong><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://shadowsocks.org/en/index.html">https://shadowsocks.org/en/index.html</a><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">2, install shadowsocks server</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo apt-get install python-pip</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo pip install shadowsocks</span><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://shadowsocks.org/en/download/servers.html">https://shadowsocks.org/en/download/servers.html</a><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">3, shadowsocks server config file</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ vi /etc/shadowsocks.json</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">{</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "server":"my_server_ip",</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "server_port":8388,</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "local_port":1080,</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "password":"barfoo!",</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "timeout":600,</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; "method":"table"</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">}</span><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://shadowsocks.org/en/config/quick-guide.html">https://shadowsocks.org/en/config/quick-guide.html</a><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">4, shadowsocks server command</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ ssserver -h // help message</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ ssserver -c /etc/shadowsocks.json -d start // start in daemon mode</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ ssserver -d stop // stop the server</span><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">5, shadowsocks-qt5 client for ubuntu 14.04</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo add-apt-repository ppa:hzwhuang/ss-qt5</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo apt-get update</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo apt-get install shadowsocks-qt5</span><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://github.com/shadowsocks/shadowsocks-qt5/wiki/Installation">https://github.com/shadowsocks/shadowsocks-qt5/wiki/Installation</a><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">6, install genpac to generate PAC file from gfwlist</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ sudo pip install genpac // install</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ genpac --init // generate config.ini and user-rules.txt</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">-- modify config.ini</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ vi config.ini</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">[config]</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">proxy = SOCKS5 127.0.0.1:1080</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">gfwlist-url = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">user-rule-from = /path/to/user-rules.txt</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">output = /path/to/proxy.pac</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">$ genpac -c config.ini // generate pac file</span><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://github.com/JinnLynn/genpac">https://github.com/JinnLynn/genpac</a><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://github.com/gfwlist/gfwlist">https://github.com/gfwlist/gfwlist</a><br style="font-size: 14pt;" /><br style="font-size: 14pt;" /><strong style="font-size: 14pt;">7, using a PAC file in Firefox</strong><br style="font-size: 14pt;" /><span style="font-size: 14pt;">about:preferences#advanced -&gt; Network -&gt; Settings</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">check 'Automatic proxy configuration URL:'</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">file:///path/to/proxy.pac</span><br style="font-size: 14pt;" /><span style="font-size: 14pt;">enable 'Remote DNS'</span><br style="font-size: 14pt;" /><a style="font-size: 14pt;" href="https://www.youtube.com/watch?v=nKB4FoPw15k">https://www.youtube.com/watch?v=nKB4FoPw15k</a></div><img src ="http://www.cppblog.com/Onway/aggbug/212428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-12-06 17:18 <a href="http://www.cppblog.com/Onway/archive/2015/12/06/212428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>可枚举对象与枚举器</title><link>http://www.cppblog.com/Onway/archive/2015/08/01/211446.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Sat, 01 Aug 2015 06:00:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/08/01/211446.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/211446.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/08/01/211446.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/211446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/211446.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1，最先学会的是，继承了IEnumerable接口的类都可以使用foreach遍历，但一直没有多想。2，IEnumerable和IEnumerable&lt;out T&gt;的定义：Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->&nbsp; &nb...&nbsp;&nbsp;<a href='http://www.cppblog.com/Onway/archive/2015/08/01/211446.html'>阅读全文</a><img src ="http://www.cppblog.com/Onway/aggbug/211446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-08-01 14:00 <a href="http://www.cppblog.com/Onway/archive/2015/08/01/211446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Dispose模式</title><link>http://www.cppblog.com/Onway/archive/2015/07/29/211424.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Wed, 29 Jul 2015 14:50:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/07/29/211424.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/211424.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/07/29/211424.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/211424.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/211424.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">1，两个链接里面已经解析完Dispose模式了，其他的只是自己的一些理解。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">
<div><a href="https://msdn.microsoft.com/en-us/library/vstudio/b1yfkh5e(v=vs.100).aspx" style="background-color: inherit; cursor: pointer;"><span style="font-size: 14pt;">https://msdn.microsoft.com/en-us/library/vstudio/b1yfkh5e(v=vs.100).aspx</span></a></div>
<div><a href="http://www.cnblogs.com/luminji/archive/2011/03/29/1997812.html" style="background-color: inherit; cursor: pointer;"><span style="font-size: 14pt;">http://www.cnblogs.com/luminji/archive/2011/03/29/1997812.html</span></a></div>
</div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">2，如果自定义类型封装了非托管资源，或者引用了一个封装了非托管资源的对象时（比如引用了SqlConnection对象），应该实现Dispose模式。</span></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">3，如果自定义类型继承的基类需要Dispose，但该对象本身并没有需要Dispose的资源时（比如只是附加了一些简单类型），无需考虑Dispose模式。</span></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">4，如果基类实现了Dispose，则其派生类只需重写protected级别的Dispose方法，释放本类型的使用到的资源。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">public级别的Dispose和Finalize方法都来自继承。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">重写的Dispose方法，记得最后调用基类带参的Dispose。</span></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">5，附加的Close方法都是直接调用public无参的Dispose方法。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;"><br />6，类型的析构函数会被编译器改为Finalize方法，不要重载这个方法。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">基类的Finalize方法总是会被自动调用的。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">Finalize方法都不应该引用任何对象。</span></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="line-height: 1.5; font-size: 14pt; background-color: inherit;">7，不懂这段话，既然基类没有需要释放的资源，为何要实现Dispose模式，而为了性能考虑，又不写析构函数？</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">那我的派生类，还要先看一下基类，再决定要不要写析构函数？</span></div>
<span style="font-family: 微软雅黑; widows: auto; font-size: 14pt; background-color: #ffffff;">Implement the dispose design pattern on a base type that commonly has derived types that hold onto resources, even if the base type does not. If the base type has a Close method, often this indicates the need to implement Dispose. In such cases, do not implement a Finalize method on the base type. Finalize should be implemented in any derived types that introduce resources that require cleanup</span><span style="font-size: 14pt; font-family: 微软雅黑; widows: auto; background-color: #ffffff;">.</span><span style="font-family: 微软雅黑; widows: auto; font-size: 14pt; background-color: #ffffff;"><br /></span>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">8，对象在调用Dispose之后，除了Dispose以外，都应该抛出ObjectDisposedException异常。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">9，实现了Finalize的对象，在第一次垃圾回收的时候，不会释放对象，而只是调用其Finalize方法，第二次回收才会真正释放对象。</span></div><img src ="http://www.cppblog.com/Onway/aggbug/211424.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-07-29 22:50 <a href="http://www.cppblog.com/Onway/archive/2015/07/29/211424.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>变体泛型</title><link>http://www.cppblog.com/Onway/archive/2015/07/29/211412.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Wed, 29 Jul 2015 12:23:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/07/29/211412.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/211412.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/07/29/211412.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/211412.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/211412.html</trackback:ping><description><![CDATA[<span style="font-size: 14pt;">因为某些原因，一直用的都是.NET2，但渣也总得有些追求是不，说不定哪天就用上了呢？</span><br />
<br />
<div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff;">using</span>&nbsp;System;<br />
<span style="color: #0000FF; ">using</span>&nbsp;System.Collections.Generic;<br />
<span style="color: #0000FF; ">using</span>&nbsp;System.Text;<br />
<br />
<span style="color: #0000FF; ">namespace</span>&nbsp;ConsoleApplicationTest<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">/*</span><span style="color: #008000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;变体泛型<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;.NET4，在泛型接口类型或者泛型委托类型里面，<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;被关键字in声明的泛型参数，其类型可以从父类向子类逆变，只能用作输入参数<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;被关键字out声明的泛型参数，其类型可以从子类向父类协变，只能用于返回值<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;整个泛型类型是不限于用作输入参数还是作为返回值<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;interface&nbsp;IType_IN_OUT&lt;in&nbsp;T1,&nbsp;out&nbsp;T2&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;IType_IN_OUT&lt;Farmer,&nbsp;Person&gt;&nbsp;farmerPersonType&nbsp;=&nbsp;null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;IType_IN_OUT&lt;Person,&nbsp;Farmer&gt;&nbsp;personfarmerType&nbsp;=&nbsp;null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;farmerPersonFinder&nbsp;=&nbsp;personFarmerFinder;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;为什么不支持&#8220;变体&#8221;class呢？跟字段有关系么？<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">*/</span><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Program<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Main(<span style="color: #0000FF; ">string</span>[]&nbsp;args)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_IN&lt;Person&gt;&nbsp;person_in&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_IN&lt;Farmer&gt;&nbsp;farmer_in&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;farmer_in&nbsp;=&nbsp;person_in;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Greeting(person_in);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(GetTypeIn()&nbsp;==&nbsp;<span style="color: #0000FF; ">null</span>);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_OUT&lt;Person&gt;&nbsp;person_out&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_OUT&lt;Farmer&gt;&nbsp;farmer_out&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;person_out&nbsp;=&nbsp;farmer_out;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Greeting(farmer_out);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(GetTypeOut()&nbsp;==&nbsp;<span style="color: #0000FF; ">null</span>);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_IN&lt;Person&gt;&nbsp;personFinderIn&nbsp;=&nbsp;p&nbsp;=&gt;&nbsp;Console.WriteLine(p.GetType());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_IN&lt;Farmer&gt;&nbsp;farmerFinderIn&nbsp;=&nbsp;f&nbsp;=&gt;&nbsp;Console.WriteLine(f.GetType());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;farmerFinderIn&nbsp;=&nbsp;personFinderIn;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Greeting(personFinderIn);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(GetFarmerFinder().GetType());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_OUT&lt;Person&gt;&nbsp;personFinderOut&nbsp;=&nbsp;()&nbsp;=&gt;&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Person();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_OUT&lt;Farmer&gt;&nbsp;farmerFinderOut&nbsp;=&nbsp;()&nbsp;=&gt;&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Farmer();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;personFinderOut&nbsp;=&nbsp;farmerFinderOut;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Greeting(personFinderOut);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(GetPersonFinder().GetType());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_IN_OUT&lt;Farmer,&nbsp;Person&gt;&nbsp;farmerPersonFinder&nbsp;=&nbsp;f&nbsp;=&gt;&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Person();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_IN_OUT&lt;Person,&nbsp;Farmer&gt;&nbsp;personFarmerFinder&nbsp;=&nbsp;p&nbsp;=&gt;&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Farmer();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;farmerPersonFinder&nbsp;=&nbsp;personFarmerFinder;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;interface&nbsp;IType_IN_OUT&lt;in&nbsp;T1,&nbsp;out&nbsp;T2&gt;</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_IN_OUT&lt;Farmer,&nbsp;Person&gt;&nbsp;farmerPersonType&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_IN_OUT&lt;Person,&nbsp;Farmer&gt;&nbsp;personfarmerType&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;farmerPersonType&nbsp;=&nbsp;personfarmerType;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.ReadKey();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Greeting(IType_OUT&lt;Person&gt;&nbsp;person)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(person&nbsp;==&nbsp;<span style="color: #0000FF; ">null</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Greeting(IType_IN&lt;Farmer&gt;&nbsp;farmer)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(farmer&nbsp;==&nbsp;<span style="color: #0000FF; ">null</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;IType_OUT&lt;Person&gt;&nbsp;GetTypeOut()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_OUT&lt;Farmer&gt;&nbsp;farmer&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;farmer;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;IType_IN&lt;Farmer&gt;&nbsp;GetTypeIn()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IType_IN&lt;Person&gt;&nbsp;person_IN&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;person_IN;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Greeting(Finder_OUT&lt;Person&gt;&nbsp;personFinder)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(personFinder().GetType());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Greeting(Finder_IN&lt;Farmer&gt;&nbsp;farmerFinder)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(farmerFinder.GetType());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;Finder_OUT&lt;Person&gt;&nbsp;GetPersonFinder()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_OUT&lt;Farmer&gt;&nbsp;farmerFinder&nbsp;=&nbsp;()&nbsp;=&gt;&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Farmer();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;farmerFinder;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;Finder_IN&lt;Farmer&gt;&nbsp;GetFarmerFinder()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finder_IN&lt;Person&gt;&nbsp;person&nbsp;=&nbsp;p&nbsp;=&gt;&nbsp;Console.WriteLine(p.GetType());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;person;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;IType_OUT&lt;<span style="color: #0000FF; ">out</span>&nbsp;T&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;IType_IN&lt;<span style="color: #0000FF; ">in</span>&nbsp;T&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;IType_IN_OUT&lt;<span style="color: #0000FF; ">in</span>&nbsp;T1,&nbsp;<span style="color: #0000FF; ">out</span>&nbsp;T2&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">delegate</span>&nbsp;T&nbsp;Finder_OUT&lt;<span style="color: #0000FF; ">out</span>&nbsp;T&gt;();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">delegate</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;Finder_IN&lt;<span style="color: #0000FF; ">in</span>&nbsp;T&gt;(T&nbsp;t);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">delegate</span>&nbsp;T2&nbsp;Finder_IN_OUT&lt;<span style="color: #0000FF; ">in</span>&nbsp;T1,&nbsp;<span style="color: #0000FF; ">out</span>&nbsp;T2&gt;(T1&nbsp;t1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Person<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Farmer&nbsp;:&nbsp;Person<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</div><img src ="http://www.cppblog.com/Onway/aggbug/211412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-07-29 20:23 <a href="http://www.cppblog.com/Onway/archive/2015/07/29/211412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>栅格化道路渲染</title><link>http://www.cppblog.com/Onway/archive/2015/07/19/211304.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Sun, 19 Jul 2015 05:31:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/07/19/211304.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/211304.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/07/19/211304.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/211304.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/211304.html</trackback:ping><description><![CDATA[<span style="font-family: 微软雅黑; widows: auto; font-size: 14pt; background-color: #ffffff;">需求：</span>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">地图上Grid对象表示一个40*40的栅格，除了经纬度以外，还有一个指标值如信号强度，以及一个根据指标值确定的渲染颜色。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">Road对象是一条矢量道路，由多个经纬度点组成。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">如果道路穿过某个栅格，则将穿过栅格的那一小段道路按栅格的颜色值画出来，没有穿过栅格的其他道路部分，用黑色渲染。</span></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">第一次做法：</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">对道路进行预处理，将道路上的各个点归类到其所属的栅格内。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">然后将栅格内的点用线连起来。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">完成后一看地图，掉坑里面了。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">1，一条道路穿过某个栅格，栅格内可能只有一个点，连不成线；</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">2，一条直线道路，只记录了开头和结尾，中间穿过的栅格就没点了</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">后来想到用补点的方式，两个点超过20米就补一个</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">简单试了一下，效果不好就开始用第二种方法</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">第二次做法：</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">先将道路在空白bitmap上画出来，颜色用黑色；</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">再将栅格在另一空白的bitmap上画出来，颜色用原本的栅格颜色；</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">对比两张bitmap，像素同时不为0的就是相交像素，用栅格的像素颜色复制到道路的像素里面；</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">效果杠杠的。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">其他方法：</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">在讨论组里面说了以后，发现另一种是预处理做法</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 14pt;">判断两点之间跟栅格的相交，将相交点记录到所在栅格里面，这比较适合后台。</span></div>
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div>
<br />
<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="font-size: 18pt;">以后还是默默写博客吧！</span></div><img src ="http://www.cppblog.com/Onway/aggbug/211304.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-07-19 13:31 <a href="http://www.cppblog.com/Onway/archive/2015/07/19/211304.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual Studio扩展开发：AutoProjectFiles</title><link>http://www.cppblog.com/Onway/archive/2015/07/11/211228.html</link><dc:creator>Onway</dc:creator><author>Onway</author><pubDate>Sat, 11 Jul 2015 11:39:00 GMT</pubDate><guid>http://www.cppblog.com/Onway/archive/2015/07/11/211228.html</guid><wfw:comment>http://www.cppblog.com/Onway/comments/211228.html</wfw:comment><comments>http://www.cppblog.com/Onway/archive/2015/07/11/211228.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Onway/comments/commentRss/211228.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Onway/services/trackbacks/211228.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><div></div></div><div><span style="font-size: 18pt; font-family: 'Times New Roman';"></span></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>说明</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">用于多人开发的项目且在不提交项目文件的情况下，自动将新增的源码文件加入到项目中或者将删除的文件从项目中移除。<br /><a href="https://github.com/Onway/AutoProjectFiles">https://github.com/Onway/AutoProjectFiles<br /></a><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>使用</strong></span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">安装后在资源管理器中右键项目名称节点，会看到&#8220;自动更新项目&#8221;和&#8220;创建快照...&#8221;两个选项。 &nbsp;</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">&#8220;创建快照&#8221;是对项目中指定的源码目录建立一份已有文件列表，以便后续知道新增或者删除的文件。 &nbsp;</span></div><div><span style="font-family: 'Times New Roman'; font-size: 14pt;">&#8220;自动更新项目&#8221;之后，将会对新增或删除文件更新至项目，同时刷新文件快照列表。<br /><br /></span></div><div></div><div><span style="font-family: 'Times New Roman'; font-size: 18pt;"><strong>效果图<br /><img src="http://www.cppblog.com/images/cppblog_com/onway/solution.png" width="541" height="542" alt="" /><br /><img src="http://www.cppblog.com/images/cppblog_com/onway/snapshot_form.png" width="414" height="289" alt="" /><br /></strong></span></div><div><span style="font-family: 'Times New Roman';"></span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><a href="https://github.com/Onway/AutoProjectFiles" style="background-color: inherit; cursor: pointer;"></a></div><img src ="http://www.cppblog.com/Onway/aggbug/211228.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Onway/" target="_blank">Onway</a> 2015-07-11 19:39 <a href="http://www.cppblog.com/Onway/archive/2015/07/11/211228.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>