Farseerfc's Nest//farseerfc.me/en/2016-07-31T03:52:00+09:00PacVis: visualize pacman local database2016-07-31T03:52:00+09:002016-07-31T03:52:00+09:00farseerfctag:farseerfc.me,2016-07-31:/en/pacvis.html
<div class="panel panel-default">
<div class="panel-heading">
PacVis</div>
<div class="panel-body">
<img alt="Demo of PacVis" class="img-responsive" src="//farseerfc.me/en/images/pacvis-first.png"/>
</div>
</div>
<div class="section" id="motivation-for-pacvis">
<h2><a class="toc-backref" href="#id2">Motivation for PacVis</a></h2>
<p>I must admit that I love Arch Linux, largely because Arch Linux made me feel
like I really <strong>own</strong> the whole system. In my Arch Linux system, I know clearly
every package I have installed and why I installed it. I can find which
package brings …</p></div>
<div class="panel panel-default">
<div class="panel-heading">
PacVis</div>
<div class="panel-body">
<img alt="Demo of PacVis" class="img-responsive" src="//farseerfc.me/en/images/pacvis-first.png"/>
</div>
</div>
<div class="section" id="motivation-for-pacvis">
<h2><a class="toc-backref" href="#id2">Motivation for PacVis</a></h2>
<p>I must admit that I love Arch Linux, largely because Arch Linux made me feel
like I really <strong>own</strong> the whole system. In my Arch Linux system, I know clearly
every package I have installed and why I installed it. I can find which
package brings in a give file. A Debian/Fedora/openSUSE user with enough experience
may achieve this with their favorite package manager too, but they must overcome
a much higher complexity with their distro's fine-grinding packaging strategy.
Usually they have 3 to 10 times more packages than Arch Linux on a
similar setup. And with regard to packaging system, they must work with much more
details than Arch's simple PKGBUILD based packaging.</p>
<p>Every user who successfully installed Arch Linux should have learned that, after
the initial installation, you will only get a minimum setup. The most important
step in the installation guide on ArchWiki is a command
<code class="code">
pactrap /mnt base</code>
, which will use <code class="code">
/mnt</code>
as the filesystem root
and call <code class="code">
pacman -S base</code>
inside that root to install the whole base
group. And that's basically all you will get after the install. The initial
system has nearly nothing. Everything you need will be installed afterwards,
manually by using <code class="code">
pacman</code>
. It is nothing unnecessary, only for
<strong>your</strong> own need.</p>
<p>But after using the system for a long time, there are unavoidably some packages
inside the system which are installed and used for awhile and abandoned.
They are like the old furnitures inside your house, taking space and covered by
dusts. We have <code class="code">
pacman -Qtd</code>
to help you find all orphan packages, namely
those <strong>installed as dependency for other packages once but not needed for now</strong>
, but for manually installed packages, we have no good tool but manually
checking them one by one.</p>
<p>So I was looking for a tool to help me understand the relations in my system.
In particular, I want a tool to help me do these things:</p>
<ol class="arabic simple">
<li>Find packages that I installed manually but not needed now</li>
<li>Find those large and space-consuming packages</li>
<li>Understand the relationships between packages</li>
</ol>
<div class="figure">
<img alt="Android System Architecture" class="img-responsive" src="//farseerfc.me/en/images/Android-System-Architecture.jpg"/>
<p class="caption"><a class="reference external" href="https://en.wikipedia.org/wiki/Android_(operating_system)">Android System Architecture</a></p>
</div>
<p>About the last thing "relations between packages", I once saw the diagram of
<a class="reference external" href="https://en.wikipedia.org/wiki/Architecture_of_OS_X">macOS Architecture</a>
and Android System Architecture, and I was impressed by the layered hierarchy
in these diagrams. I was wondering since then, <em>is it possible to draw a
similar layered architecture diagram for modern Linux desktop</em> ?
Or <em>will a Linux desktop be much different</em>?
I can find out hierarchy diagrams for Linux kernel or
Xorg graphic stack on Wikipedia or other sites, but I don't know such diagrams
for the whole distribution. And further I thought, can I <em>draw such diagram from
the dependency relationships between packages automatically</em>?</p>
</div>
<div class="section" id="predecessors-of-pacvis">
<h2><a class="toc-backref" href="#id3">Predecessors of PacVis</a></h2>
<p>Before working on PacVis, I have tried several similar tools. Some of them meet
some of my needs, but they all lack certain features that I considered important.
These tools became the prototype of PacVis, as they enlightened me of how PacVis
should be.</p>
<div class="section" id="pactree">
<h3><a class="toc-backref" href="#id4">pactree</a></h3>
<p>pactree started as an <a class="reference external" href="https://bbs.archlinux.org/viewtopic.php?id=51795">individual project</a>
, but now it is <a class="reference external" href="https://www.archlinux.org/pacman/pactree.8.html">part of pacman</a>.
From its manpage we can see that the output of pactree is a dependency tree
starting from a given package. By appending <code class="code">
--graph</code>
parameter, pactree
can also output a diagram in <a class="reference external" href="http://www.graphviz.org/">dot</a> format,
then we can render this diagram using dot command:</p>
<div class="panel panel-default">
<div class="panel-heading">
<code class="code">
pactree pacvis-git -d3 --graph | dot -Tpng >pacvis-pactree.png</code>
</div>
<div class="panel-body">
<img alt="pactree --graph" class="img-responsive" src="//farseerfc.me/en/images/pacvis-pactree.png"/>
</div>
</div>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> pactree pacvis-git -d3</span>
<span class="code-line"><span class="go">pacvis-git</span></span>
<span class="code-line"><span class="go">├─python-tornado</span></span>
<span class="code-line"><span class="go">│ └─python</span></span>
<span class="code-line"><span class="go">│ ├─expat</span></span>
<span class="code-line"><span class="go">│ ├─bzip2</span></span>
<span class="code-line"><span class="go">│ ├─gdbm</span></span>
<span class="code-line"><span class="go">│ ├─openssl</span></span>
<span class="code-line"><span class="go">│ ├─libffi</span></span>
<span class="code-line"><span class="go">│ └─zlib</span></span>
<span class="code-line"><span class="go">├─pyalpm</span></span>
<span class="code-line"><span class="go">│ ├─python</span></span>
<span class="code-line"><span class="go">│ └─pacman</span></span>
<span class="code-line"><span class="go">│ ├─bash</span></span>
<span class="code-line"><span class="go">│ ├─glibc</span></span>
<span class="code-line"><span class="go">│ ├─libarchive</span></span>
<span class="code-line"><span class="go">│ ├─curl</span></span>
<span class="code-line"><span class="go">│ ├─gpgme</span></span>
<span class="code-line"><span class="go">│ ├─pacman-mirrorlist</span></span>
<span class="code-line"><span class="go">│ └─archlinux-keyring</span></span>
<span class="code-line"><span class="go">└─python-setuptools</span></span>
<span class="code-line"><span class="go"> └─python-packaging</span></span>
<span class="code-line"><span class="go"> ├─python-pyparsing</span></span>
<span class="code-line"><span class="go"> └─python-six</span></span>
<span class="code-line"><span class="gp"> $</span> pactree pacvis-git -d3 --graph <span class="p">|</span> dot -Tpng >pacvis-pactree.png</span>
</pre></div>
<p>From the rendered diagram we can see that, because some packages may share
common dependencies, the whole diagram is no longer a
<a class="reference external" href="https://en.wikipedia.org/wiki/Tree_structure">tree in graph theory</a> .
During the initial prototyping of PacVis, I tried to parse the output of pactree
and pacman using bash/python scripts, to draw a single diagram for the whole
system. However the rendered picture is so large that it takes hours for
dot to layout them, and the result is barely viewable in an image viewer or a
browser.</p>
<p>I need to say that there will be no PacVis if there is no pactree.
Even the pyalpm library that I used in PacVis is a python binding for alpm,
which is born during the rewrite of pactree in C language.</p>
</div>
<div class="section" id="pacgraph">
<h3><a class="toc-backref" href="#id5">pacgraph</a></h3>
<div class="panel panel-default">
<div class="panel-heading">
The output of pacgraph</div>
<div class="panel-body">
<img alt="pacgraph" class="img-responsive" src="//farseerfc.me/en/images/pacvis-pacgraph.png"/>
</div>
</div>
<p><a class="reference external" href="http://kmkeen.com/pacgraph/index.html">pacgraph</a> is developped by a
Arch Linux Trusted User <a class="reference external" href="http://kmkeen.com/">keenerd</a> . It is written
in Python, as is PacVis. Comparing with pactree, pacgraph is definitely more
suitable for my needs. It will draw a diagram for all the packages in the
system, using a clever layout algorithm that surpass the performance of
dot's layout.</p>
<p>The output of pacgraph is an artistic diagram with different font size of
package names showing their disk usage. By viewing pacgraph's output, we can
determine the overall system structure, e.g. whether the system is a desktop
system or a server. We can easily find large packages and consider remove them.</p>
<p>There's more. pacgraph provided an interactive GUI called pacgraph-tk, written
clearly in tk. You can zoom in to see details or zoom out to see the whole
graph in GUI, and you can highlight one package to see its relations to others.</p>
<p>And pacgraph support to render the dependencies of a selected group of packages,
not all, like pactree does.</p>
<p>But pacgraph does not meet all my needs. I want a diagram to show the
architecture of the system, but pacgraph don't differ
"the packages that this package depend on" and
"the packages that depends on this package". In other words, pacgraph draws a
<strong>undirected graph</strong>, but I want a <strong>directed graph</strong>, that reflects the
<strong>layered hierarchy of dependency relationship</strong>.</p>
</div>
</div>
<div class="section" id="so-here-is-pacvis">
<h2><a class="toc-backref" href="#id6">So here is PacVis</a></h2>
<div class="panel panel-default">
<div class="panel-heading">
PacVis on startup</div>
<div class="panel-body">
<img alt="PacVis on startup" class="img-responsive" src="//farseerfc.me/en/images/pacvis-second.png"/>
</div>
</div>
<p>With these predecessors, I started working on PacVis. The development takes
me 2 month, and largely break into 2 stages. In the first stage I wrote basic
logics and a prototype of the UI. In the second stage I applied the templates
from <a class="reference external" href="https://getmdl.io/">https://getmdl.io/</a> . Now finally it is usable for others.</p>
<p>So several days ago I made a PKGBUILD for pacvis on AUR:
<a class="reference external" href="https://aur.archlinux.org/packages/pacvis-git/">pacvis-git</a>.
Now it's fairly easy to run pacvis locally on a Arch Linux system.
You can use any aurhelper you familiar with, or build it directly from AUR:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="go">~$ git clone aur@aur.archlinux.org:pacvis-git.git</span></span>
<span class="code-line"><span class="go">~$ cd pacvis-git</span></span>
<span class="code-line"><span class="go">~/pacvis-git$ makepkg -si</span></span>
<span class="code-line"><span class="go">~/pacvis-git$ pacvis</span></span>
<span class="code-line"><span class="go">Start PacVis at http://localhost:8888/</span></span>
</pre></div>
<p>Following the instruction, open <a class="reference external" href="http://localhost:8888/">http://localhost:8888/</a> in a browser then you can
see PacVis's result of your own system. As a demonstration you can also visit
PacVis on my Arch Linux server :
<a class="reference external" href="https://pacvis.farseerfc.me/">https://pacvis.farseerfc.me/</a> . It is showing a minimal server setup, that might
load and layout faster than a normal desktop system.</p>
<div class="panel panel-default">
<div class="panel-heading">
PacVis on Windows msys2</div>
<div class="panel-body">
<img alt="PacVis on Windows msys2" class="img-responsive" src="//farseerfc.me/en/images/pacvis-msys2.png"/>
</div>
</div>
<p>As a side note, pacvis only depends on pyalpm and tornado, so there should be
no problem running it on other pacman-based systems, including
<a class="reference external" href="https://msys2.github.io/">msys2 on Windows</a> (altough building a msys2
python-tornado may take some non-trival effort).</p>
</div>
<div class="section" id="the-legend-and-usage-of-pacvis">
<h2><a class="toc-backref" href="#id7">The legend and usage of PacVis</a></h2>
<p>PacVis resembles the UI of a map app such as Google Maps. You can use
wheel of mouse to zoom and drag to move, or pinch gestures on a touch screen.
There is a side panel on the right top corner and you can hide it when you don't
need it. There are some zoom buttons on the right bottom corner.</p>
<div class="figure">
<img alt="PacVis showing pacvis-git" class="img-responsive" src="//farseerfc.me/en/images/pacvis-pacvis-git.png"/>
<p class="caption">The dependencies of pacvis-git package</p>
</div>
<p>The whole diagram is made up of small circles and arrows in between circles.
A circle represent a package, while an arrow represents a dependency
relationship. If you zoom into details, you can see text under the circles
showing their package names. Hover on packages will also give you infos
about the package. You can select a package, and in the side panel there will be
more detailed infomation about that package.</p>
<p>The above picture is showing the dependencies of pacvis-git package itself.
It dependes on pyalpm, python-tornado and python-setuptools, while pyalpm
is in-turn depend on pacman.
A package in <span class="label label-primary">purple</span> means it is
installed manually, while a package in
<span class="label label-warning">orange</span> means it is installed
as a dependency for other packages. The color of arrows usually follow their
origin package's color.</p>
<p>Note that most arrows in the diagram are pointing bottom-up, this is because
PacVis will do a topology sort based on the dependencies of packages.
From the topology sort, PacVis assigned a <em>topology level</em> to each package,
e.g. pacvis-git has a topo-level of 39, its dependency pyalpm has a topo-level
of 38, and pacman is sat on the topo-level 37.
Layering packages with their topo-level is the main difference of PacVis with
pacgraph.</p>
<p>Besides manually zoom-in to look around, you can also use PacVis's search box
to locate a particular package by its name. And when you select a package,
the related package names will be shown in the Dep and Req-By tabs in the
sidebar. These package names are made as buttons so you can click them to
browse the whole dependency graph.</p>
<p>Let me describe some arguments related to the implementation:</p>
<div class="label label-info">
Max Level</div>
<p>This will limit the max topo-level that PacVis renders.
When there are too many packages, the layout algorithm will take a lot of time.
Limiting this is very useful during debug of PacVis.</p>
<div class="label label-info">
Max Required-By</div>
<p>This will limit the max required-by-relationship that PacVis renders.
If you play around in PacVis, you will soon find that most packages in the
system directly depends on glibc or gcc-libs. Rendering these <em>well-known</em>
dependency may result in a lot of long arrows, that reduce the readability of
the whole diagram. You can limit this to a lower number so that PacVis will
not render these <em>well-known</em> dependencies.</p>
</div>
<div class="section" id="some-facts-you-can-learn-from-pacvis">
<h2><a class="toc-backref" href="#id8">Some facts you can learn from PacVis</a></h2>
<div class="panel panel-default">
<div class="panel-heading">
A normal KDE desktop <a class="reference external" href="//farseerfc.me/en/images/pacvis-16384.png">Full image(17M)</a></div>
<div class="panel-body">
<img alt="A normal KDE desktop in PacVis" class="img-responsive" src="//farseerfc.me/en/images/pacvis-4096-anno.png"/>
</div>
</div>
<p>You may find many facts by playing around in PacVis. An example will be the
aforementioned "most packages depends on glibc".
Besides that, I will give some more examples below.</p>
<div class="section" id="dependency-hierachy">
<h3><a class="toc-backref" href="#id9">Dependency hierachy</a></h3>
<p>The packages in the system is clearly divided into several layers:</p>
<ul class="simple">
<li>glibc, etc. C runtime</li>
<li>Bash/Perl/Python etc. script languages</li>
<li>coreutils/gcc/binutils etc. core binary utilities</li>
<li>pacman/systemd etc. large system utilities</li>
<li>gtk{2,3}/qt{4,5} etc. GUI toolkit</li>
<li>chromium etc. GUI Applications</li>
<li>Plasma/Gnome etc. Desktop environments</li>
</ul>
<p>This largely meet my overall understanding, but some details are interesting to
me. For example, zsh dependes on gdbm which in-turn depends on bash, which means
that you can not get rid of bash even if you only use zsh.
For another example, python package (which is python3 in Arch Linux) and
python2 and pypy sit roughly on the same topo-level in the diagram.</p>
<div class="figure">
<img alt="zsh indirectly depends on bash because of gdbm" class="img-responsive" src="//farseerfc.me/en/images/pacvis-zsh-bash.png" style="width: 45%;"/>
<p class="caption">zsh indirectly depends on bash because of gdbm</p>
</div>
<p>However there are some facts beyond common knowledge, e.g.
qt5-base < qt4 < gtk2 < gtk3 with regard to topo-level.
Qt5 was split into several packages therefore it is understandable that
qt5-base is lower than qt4. The fact that gtk is more high level than qt
may beyond most expectations (including mine).</p>
</div>
<div class="section" id="circular-dependencies">
<h3><a class="toc-backref" href="#id10">Circular dependencies</a></h3>
<p>There are some packages that have circular dependencies in between.
An example will be freetype2 and harfbuzz. freetype2 is a library for font
rendering, and harfbuzz is a library to deal with OpenType font shapes.
They depend on each other. Another example is kio and kinit of KDE.
kio provides VFS-like and FUSE-like resource abstraction for KDE applications,
while kinit is in charge of initializing KDE desktop environment.</p>
<div class="figure">
<img alt="freetype2 harfbuzz" class="img-responsive" src="//farseerfc.me/en/images/pacvis-freetype2-harfbuzz.png" style="width: 45%;"/>
<p class="caption">Circular dependency between freetype2 and harfbuzz</p>
</div>
<p>Because of these circular dependencies, PacVis cannot simply apply topology sort
directly. Before that, PacVis will firstly find all circles in the dependency
graph to break these circles. It renders the relationship that will cause a
circle as red arrows in the diagram.</p>
</div>
<div class="section" id="some-packages-don-t-have-dependency-relationship">
<h3><a class="toc-backref" href="#id11">Some packages don't have dependency relationship</a></h3>
<div class="figure">
<img alt="PacVis Level 0" class="img-responsive" src="//farseerfc.me/en/images/pacvis-level0.png" style="width: 45%;"/>
<p class="caption">man-pages and licenses don't have dependencies</p>
</div>
<p>There are some packages that don't depend on others, and don't depended
by others. They are isolated in the whole diagram, e.g. man-pages and licenses.
These packages sit on the most top level of the diagram, with a topo-level of 0.
PacVis will render them as <span class="label label-info">blue</span>
squares specially.</p>
</div>
<div class="section" id="linux-the-kernel-is-unimportant-if-we-only-look-at-dependencies">
<h3><a class="toc-backref" href="#id12">Linux (the kernel) is unimportant, if we only look at dependencies</a></h3>
<p>All userspace program depend on glibc, which calls the kernel using well-defined
syscalls. As a result, if we only look at userspace dependencies, glibc and
other GNU components are the center of the GNU/Linux distribution, while
Linux the kernel is just located in a random place deeply blew the dependency
graph. On my demo server the Linux package is even located on the most bottom
level because it depends on mkinitcpio which in-turn depend on many components
in the system.</p>
</div>
<div class="section" id="pacman-qtd-cannot-find-orphan-packages-with-circle-dependency">
<h3><a class="toc-backref" href="#id13">pacman -Qtd cannot find orphan packages with circle dependency</a></h3>
<div class="figure">
<img alt="pacman -Qtd cannot find packages with circle dependency" class="img-responsive" src="//farseerfc.me/en/images/pacvis-circledeps-Qtd.png" style="width: 45%;"/>
<p class="caption">msys2 packages with circle dependency</p>
</div>
<p>I saw an archipelago of packages from mingw repo when testing PacVis on msys2.
To my surprise, they don't connected to any manually installed packages,
something strange as I routinely run <code class="code">
pacman -Qtd</code>
and remove the results on
all my systems. After zoomed in I found that they contained a circle dependency
which indicated <code class="code">
pacman -Qtd</code>
cannot find these orphan packages,
not like a GC algorithm.</p>
</div>
</div>
<div class="section" id="the-future-of-pacvis">
<h2><a class="toc-backref" href="#id14">The future of PacVis</a></h2>
<p>Currently PacVis is what I planned to make, with some features added during
the development. Some of these added features are related to the poor
performance of the layout algorithm (e.g. limiting the max level).</p>
<p>In the future I planned to add more features:</p>
<ol class="arabic simple">
<li>More reasonable behavior for optdeps. Currently PacVis draw optdeps but do
not consider it during the topology sort.</li>
<li>More reasonable <strong>dependency resolution</strong>. Sometimes the dependency is not
written directly as package names, instead they appear in <code class="code">
provides</code>
array in the metadata. Currently PacVis resolve all dependencies using
alpm directly, which will lose these information.</li>
<li>Currently PacVis did not consider the repository (core/extra/community) and
package group that a package belongs to. In the future PacVis may consider
these infomation to render a clearer hierarchy.</li>
<li>Currently PacVis cannot show only part of the packages. In the future we may
provide the ability to draw only a part of all the installed packages like
pactree/pacgraph does.</li>
</ol>
<p>If you want some features in PacVis, please
<a class="reference external" href="https://github.com/farseerfc/pacvis/issues">leave me an issue</a> .</p>
</div>
Jumping KDE5 Plasma Activities Button2014-12-09T01:54:00+09:002014-12-09T01:54:00+09:00farseerfctag:farseerfc.me,2014-12-09:/en/jumping-kde5-plasma-activities-button.html<!-- PELICAN_BEGIN_SUMMARY -->
<p>I found this when using activities under KDE5 today.
One can drag the activities button out of the edge of the screen,
then it will jump back and forth at the edge.
Here is a video:</p>
<!-- PELICAN_END_SUMMARY -->
<div class="well" style="padding: 0">
<div class="tab-content" id="youtubeku">
<div class="tab-pane fade active in" id="youtube_SSbf97jGSpI">
<div align="left" class="youtube embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" src="https://www.youtube.com/embed/SSbf97jGSpI"></iframe> </div>
</div>
<div class="tab-pane fade" id="youku_XODQ0NjM2MzQ4">
<div align="left" class="youku embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" height="498" src="https://player.youku.com/embed/XODQ0NjM2MzQ4" width="510"></iframe> </div>
</div>
</div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#youtube_SSbf97jGSpI">Youtube</a></li>
<li><a data-toggle="tab" href="#youku_XODQ0NjM2MzQ4">Youku</a></li>
</ul>
</div>
<!-- PELICAN_BEGIN_SUMMARY -->
<p>Of course you can drag it back, so it is not a …</p><!-- PELICAN_BEGIN_SUMMARY -->
<p>I found this when using activities under KDE5 today.
One can drag the activities button out of the edge of the screen,
then it will jump back and forth at the edge.
Here is a video:</p>
<!-- PELICAN_END_SUMMARY -->
<div class="well" style="padding: 0">
<div class="tab-content" id="youtubeku">
<div class="tab-pane fade active in" id="youtube_SSbf97jGSpI">
<div align="left" class="youtube embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" src="https://www.youtube.com/embed/SSbf97jGSpI"></iframe> </div>
</div>
<div class="tab-pane fade" id="youku_XODQ0NjM2MzQ4">
<div align="left" class="youku embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" height="498" src="https://player.youku.com/embed/XODQ0NjM2MzQ4" width="510"></iframe> </div>
</div>
</div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#youtube_SSbf97jGSpI">Youtube</a></li>
<li><a data-toggle="tab" href="#youku_XODQ0NjM2MzQ4">Youku</a></li>
</ul>
</div>
<!-- PELICAN_BEGIN_SUMMARY -->
<p>Of course you can drag it back, so it is not a serious problem.
It is just so cute that I had to note this.</p>
<p>By comparison, the jumping window in Gnome3 is far worse than this:</p>
<!-- PELICAN_END_SUMMARY -->
<div class="well" style="padding: 0">
<div class="tab-content" id="youtubeku">
<div class="tab-pane fade active in" id="youtube_TRQJdRHYwrw">
<div align="left" class="youtube embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" src="https://www.youtube.com/embed/TRQJdRHYwrw"></iframe> </div>
</div>
<div class="tab-pane fade" id="youku_XNjc4MjQ5NjE2">
<div align="left" class="youku embed-responsive embed-responsive-16by9"> <iframe allow="fullscreen" class="embed-responsive-item" frameborder="0" height="498" src="https://player.youku.com/embed/XNjc4MjQ5NjE2" width="510"></iframe> </div>
</div>
</div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#youtube_TRQJdRHYwrw">Youtube</a></li>
<li><a data-toggle="tab" href="#youku_XNjc4MjQ5NjE2">Youku</a></li>
</ul>
</div>
<!-- PELICAN_BEGIN_SUMMARY -->
<p>BTW, I saw another cute translation error of mute screen in KDE5:</p>
<!-- PELICAN_END_SUMMARY -->
<blockquote class="twitter-tweet" lang="zh-tw"><p>KDE5のミュート画面の中国語翻訳、「静音」のはずだが「镜音」になっている。Vocaloidファンのネタだか、単なる入力ミスだか分からない。 <a href="http://t.co/ipyHjXMscR">pic.twitter.com/ipyHjXMscR</a></p>— Jiachen YANG (@farseerfc) <a href="https://twitter.com/farseerfc/status/541944351270518784">2014 12月 8日</a></blockquote>Will You Marry Me?2013-02-20T20:42:00+09:002013-02-20T20:42:00+09:00farseerfctag:farseerfc.me,2013-02-20:/en/marry-me.html<div class="panel panel-default">
<div class="panel-heading">
After rendering</div>
<div class="panel-body">
<blockquote>
<!-- PELICAN_BEGIN_SUMMARY -->
<img alt="will you marry me" class="img-responsive" src="/images/marry-me.png"/>
<!-- PELICAN_END_SUMMARY -->
</blockquote>
</div>
</div>
<p>Above is a image, the playable version is below:</p>
<script src="/static/three.min.js" type="text/javascript"></script>
<script src="/static/FirstPersonControls.js" type="text/javascript"></script>
<script src="/static/helvetiker_regular.typeface.js" type="text/javascript"></script>
<script src="/static/214game.js" type="text/javascript"></script>
<div id="game_area" style="width: 600px; height: 450px; margin-left: 10px;clear:both">
</div>
<p style="margin-left: 100px; margin-top: 10px; ">* Use WASD←→ to move,need WebGL support</p>MSR 2012 @ ICSE2012-06-02T10:42:00+09:002012-06-02T10:42:00+09:00farseerfctag:farseerfc.me,2012-06-02:/en/msr2012.html
<div class="section" id="mining-software-repository-2012-icse">
<h2><a class="toc-backref" href="#id1">Mining Software Repository 2012 @ ICSE</a></h2>
<p>I participated MSR of this year. We came to University of Zurich early
in the morning. The registration got something wrong when it seems that
Swisses cannot tell the difference among Asians so that name cards of
3 Chinese with family name of Yang are …</p></div>
<div class="section" id="mining-software-repository-2012-icse">
<h2><a class="toc-backref" href="#id1">Mining Software Repository 2012 @ ICSE</a></h2>
<p>I participated MSR of this year. We came to University of Zurich early
in the morning. The registration got something wrong when it seems that
Swisses cannot tell the difference among Asians so that name cards of
3 Chinese with family name of Yang are misplaced. And also the
organization field of Hotta was "Japan, Japan", as if he represented
the Japan.</p>
<div class="section" id="msr-microsoft-research-talk-msr-mining-software-repositories">
<h3><a class="toc-backref" href="#id2">MSR(MicroSoft Research) talk @ MSR(Mining Software Repositories)</a></h3>
<p>The first talk was the keynote given by Mrs Zhang from MSR(MicroSoft
Research @ Asia), so it turned out to be MSR gave keynote of MSR.
The talk was about Software Analysis and their clone detection tool
called XIAO. XIAO was a clone detector developed by MSRA which can be
used as a plugin for Microsoft Visual Studio. XIAO has two part, or
system state: the statics state analysis all the clones which didn't
consider the running time, while the dynamic state need real time response.
The thing I need to develop for Samsung is something like dynamic mode.
I wanted to know more about the internal details about XIAO but the talk
was finished there.</p>
</div>
<div class="section" id="towards-improving-bts-with-game-mechanisms">
<h3><a class="toc-backref" href="#id3">Towards Improving BTS with Game Mechanisms</a></h3>
<p>The contents of this talk is very much like this blog:</p>
<p><a class="reference external" href="http://www.joelonsoftware.com/items/2008/09/15.html">http://www.joelonsoftware.com/items/2008/09/15.html</a></p>
<p>The talk discussed whether the same game mechanism can be applied to
the things like issue tracking or similar. From my point of view, it
is useless to use game mechanism in this situation. The reason that
stackoverflow can success lies on that they just captured the use of
fade system in opensource community, as all hackers like to be approved
as great hacker, as what is happening in Wikipedia. Whether the same
theory can be applied in issue tracking systems inside a internal
company is questionable. Although MSDN has basic the same structure
as Wikipedia, the content of MSDN and Wikipedia have different
involvement of users. So I myself didn't approve this research.</p>
</div>
<div class="section" id="ghtorrent">
<h3><a class="toc-backref" href="#id4">GHTorrent</a></h3>
<p>They slide of this talk can be found from here:
<a class="reference external" href="http://www.slideshare.net/gousiosg/ghtorrent-githubs-data-from-a-firehose-13184524">http://www.slideshare.net/gousiosg/ghtorrent-githubs-data-from-a-firehose-13184524</a></p>
<p>Data exporter for github. Main part of data of Github, namely the hosted
code, are already exposed as git repos, and wiki of repos are stored in
git repo. So the aim of this project is to expose other data such as
issues, code comments, etc. The project access github api and fetch the
needed data as distributed system in order to overcome the limitations
of the github api. The project will provide download history as torrents.
The json data from github api is stored as bson in MongoDB and the parsed
data is stored in MySQL with schema.</p>
<p>From my point of view, it will be better if the format of data can be
uniformed and all data are stored in the git repo as wiki pages.
As the history stored in git repo is more nature, and using <pre><span class="code-line"></span>
<span class="code-line">git blame</span></pre>
to trace author of code comments should also be more useful. Of course
it is harder to read and write the raw data of git as we need more
understanding of the internal format of git. Maybe only people from
github can do this.</p>
</div>
<div class="section" id="topic-mining">
<h3><a class="toc-backref" href="#id5">Topic Mining</a></h3>
<p>I can not understand the two parameters, DE, AIC, used in this research,
study this later. The experiment target of this research are Firefox,
Mylyn and Eclipse. They are trying to analysis the identifiers and
comments from source codes in software repos and find the relationship
between topics and bugs, like what kind of topics are more likely to
contain buggy codes.</p>
<p>The result of this research is not so clear. Such as it said that the
core functions of Firefox have more bug reports, but it said no reason
about this. Maybe this only means that the core features are well
tested, rather than that the core features are more buggy.</p>
<p>But the slides showed by author are pretty and easy to understand.</p>
</div>
<div class="section" id="the-evolution-of-software">
<h3><a class="toc-backref" href="#id6">The evolution of software</a></h3>
<p>The keynote talk of the second day. It is about how should we combine
the social media with software development. Maybe this is the reason
why Github succeeded. In the talk she told about accessing tags,
uBlogs, blogs etc. directly from Integrated Development Environments,
or should we need cloud IDE such as Cloud9.</p>
</div>
<div class="section" id="do-faster-releases-improve-software-quality">
<h3><a class="toc-backref" href="#id7">Do Faster Releases Improve Software Quality?</a></h3>
<p>Used Firefox as example.</p>
<p>The conclusion is that faster releases will lead to more bugs and more
frequent crash, but bugs are get fixed more quickly and user will switch
to new released more quickly.</p>
</div>
<div class="section" id="security-vs-performance-bugs-in-firefox">
<h3><a class="toc-backref" href="#id8">Security vs Performance Bugs in Firefox</a></h3>
<p>Performance bugs are regression, blocks release.</p>
</div>
<hr class="docutils"/>
<div class="section" id="some-of-my-thoughts">
<h3><a class="toc-backref" href="#id9">Some of my thoughts</a></h3>
<div class="section" id="separation-of-commits-based-on-semantic-analysis">
<h4><a class="toc-backref" href="#id10">Separation of commits based on Semantic analysis</a></h4>
<p>The user of some tools (such as git) are not following the design
purposes of these tools which brings some difficulty to MSR. For example
git has a prefect branch system, so it is desired for users of git to
commit per topic. Commit per topic means that user send a commit for a
single implementation of a feature or a bug fix, etc. If it is difficult
to contain all modifications in a commit, then it should be in a
separate branch and merged into master branch. But actually
user tends to send very large commits, that contains many logical
features, and they can not predict to open a new branch until a few
commits.</p>
<p>Maybe this is not the fault of the user of tools, this is the tools
that are not smart enough. We should separate the commits according
to the semantic topics inside a commit.</p>
</div>
<div class="section" id="about-the-slide-systems-used-today">
<h4><a class="toc-backref" href="#id11">About the slide systems used today</a></h4>
<p>The study with title <pre><span class="code-line"></span>
<span class="code-line">Incorporating Version Histories in Information</span>
<span class="code-line">Retrieval Based Bug Localization</span></pre>
used the slides made by beamer. It
contains many equations, used many overlays are iterations, with few
figures, is a typical beamer slide. It also used mindmap very well.</p>
<p>There are at least 3 slides that are made by beamer today.</p>
<p>The study with title <pre><span class="code-line"></span>
<span class="code-line">Towards Improving Bug Tracking Systems with</span>
<span class="code-line">Game Mechanisms</span></pre>
presented with prezi. It have many pictures and many
transitions. But because of it is made by prezi, there are no headers
and footers so no page numbers and section titles etc. This is not
so convenient in such a official occasions because people need to
refer to the page number in question session.</p>
<p>There are at lease 6 presents used Apple Keynote. It is really
difficult to tell the difference between slides made by PowerPoint
and Keynote. 2 of them used the default theme of keynote.</p>
<p>The rest are using PowerPoint. Mrs Zhang from Microsoft used PowerPoint
but her slides looks like beamer very much such as the usage of footer
and header and overlays. If these are made by PowerPoint that will
involve many manually operations.</p>
<p>It is worth to mention that the slides of a study with title <pre><span class="code-line"></span>
<span class="code-line">Green</span>
<span class="code-line">Mining: A Methodology of Relating Software Change to Power Consumption</span></pre>
are all <pre><span class="code-line"></span>
<span class="code-line">badly</span></pre>
drawn hand paintings. The effect of these slide are
well received, they are green and clean and cute. You can refer to the
following animation for the effect but it is not exactly the same version
with what we saw :</p>
<p><a class="reference external" href="http://softwareprocess.es/a/greenmining-presentatation-at-queens-20120522.ogv">http://softwareprocess.es/a/greenmining-presentatation-at-queens-20120522.ogv</a></p>
</div>
<div class="section" id="microsoft-is-meaning">
<h4><a class="toc-backref" href="#id12">Microsoft is MEANING</a></h4>
<p>It is not a news. But Microsoft is the sponsor of Mining Challenge, and
the prize of this challenge will be Xbox and Kinect and the topic of
this year is:</p>
<pre class="literal-block">
Mining Android Bug
</pre>
<p>I see what you are doing there Microsoft ......</p>
</div>
</div>
</div>
PyRuby2012-03-02T23:09:00+09:002012-03-02T23:09:00+09:00farseerfctag:farseerfc.me,2012-03-02:/en/mix-ruby.html<p>Today I saw a package called <a class="reference external" href="https://github.com/danielfm/pyruby">PyRuby</a> in Github. The readme says:</p>
<pre class="literal-block">
PyRuby - Some Ruby for your Python!
PyRuby is a simple way to leverage the power of Ruby to make your Python code more readable and beautiful.
Usage
All you have to do is import the ruby module:
import …</pre><p>Today I saw a package called <a class="reference external" href="https://github.com/danielfm/pyruby">PyRuby</a> in Github. The readme says:</p>
<pre class="literal-block">
PyRuby - Some Ruby for your Python!
PyRuby is a simple way to leverage the power of Ruby to make your Python code more readable and beautiful.
Usage
All you have to do is import the ruby module:
import ruby
From now on you should be able to write Ruby code within a regular Python module. An example:
1.upto(10) { |n| puts n }
</pre>
<p>Even <a class="reference external" href="http://pypi.python.org/pypi/pyruby/1.0.0">PyPI</a> has listed this as a package.</p>
<p>In the beginning I thought this was again a Ruby implementation by PyPy project. Or at least it use some magic trick to write ruby code directly in Python.</p>
<div class="section" id="then-i-browse-into-the-source-code-of-it">
<h2>Then I browse into the source code of it.</h2>
<p>It contains only one file: ruby.py</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="c1"># -*- coding: utf-8 -*-</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="s2">"""</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="s2"> `.-:/+ossyhhddmmmmNNNNNNNmmmmmdddddhhhyyyyhhhyo:`</span></span>
<span class="code-line"><span class="s2"> .:+sydNNNmmdhhysso++/+++++++////::::::-.```......--/oymms.</span></span>
<span class="code-line"><span class="s2"> `:ohmdys+//::/::--::::////:-.```......`````.://:-` `/dNs.</span></span>
<span class="code-line"><span class="s2"> .+hNds:`-:-:///::------::///++///:--....--::///::-`.///. `oMm/</span></span>
<span class="code-line"><span class="s2"> /hNmo.` `` `....``````````` ...------:::-:/+/-.:/:` /NMs</span></span>
<span class="code-line"><span class="s2"> oMd/` `::::--.---://+` //` `````-:::::+/-`::.` :NM+</span></span>
<span class="code-line"><span class="s2"> yN` -+.` `/` o. ``::.-:. `` :NN:</span></span>
<span class="code-line"><span class="s2"> :Nm - ./ : `.-://///:-. `-` `` :NN-</span></span>
<span class="code-line"><span class="s2"> /NM/ .-:::-.` `/ `:sdmdhyMMMMMMNNmy/` :mNo`</span></span>
<span class="code-line"><span class="s2"> :hMd: /dmddddNNmdy+-. `smmy/-```hMMMMMMMhydm/ `-.`` `...:mMm+.</span></span>
<span class="code-line"><span class="s2"> -hNd/-/o/-..-::`.ydmmmmNMMMMMMNh:/+- dMN-`-+hmmmmdhhhhdddmMN-`-/o: .-::::/oydms-</span></span>
<span class="code-line"><span class="s2"> oNMo:+/::. ``...--:/+ohNMNhs- :hNmmdyo:..``yo-```.--. `-`-+shdddhs+-` `.//yms.</span></span>
<span class="code-line"><span class="s2"> .MMo:/`o:.:+sso+:-` sM+ ./-` /mNh+-....-/ymNNdo::--/shd+` -`:mm:</span></span>
<span class="code-line"><span class="s2"> /MM-o ./ ohhsooohNmy::sh. `yM/ `:oyyyyyyhys+:.` hy `/Nh` : -NN.</span></span>
<span class="code-line"><span class="s2"> -MM// -: `` y: odddhh+ -omNh- `--.` `` ```` .:ohMMs. +Ms / yMo</span></span>
<span class="code-line"><span class="s2"> hMoo .+. :Mh ```` `/hNd/.` ohdddy::...`..` `-/sdmdyo+NMNh+- :Mh / sMs</span></span>
<span class="code-line"><span class="s2"> .mmh:..:. :NMm `-/dMNM+ ./+++/:`.hM:`.````.` `-/shmNmh+-` /Mmooso.hM/ .: `mM/</span></span>
<span class="code-line"><span class="s2"> .mNs://: .NMNMs- -:-.`/+-sms. ` `shyyyhy`sNd` `.:+sdmmmdMM-. .oNM+ :m/ `s``yMh</span></span>
<span class="code-line"><span class="s2"> -mMo . sMNdMNNh+-. .ydyoyy` ``+o::+shdddhs+:-.:MM.`.-+hNMMh- `.`-/::dNs`</span></span>
<span class="code-line"><span class="s2"> -NM- mMMMh:MMdNmhs+:-..```-ohs-`...-:/+syhddmMMs:-.` `/mMMdmmddNMm+` ..-/hNh-</span></span>
<span class="code-line"><span class="s2"> sMy NMMM`:Mh`-/mMmmmdddddddddhhhdNNdhyo+:--.yMs `..:+ymMMMMd+--yNh. `+hNh:</span></span>
<span class="code-line"><span class="s2"> -Mm NMMM/yMh -NM-`..--:NMo:--.`+My :MNoydmNMMNmhdMh` -dNs` `yMd:</span></span>
<span class="code-line"><span class="s2"> `MN mMMMMMMMyshMN+:---.-MN-.....+My...-:/oyhdMMMMNmdy+-` +Mh:sNm/ yMy`</span></span>
<span class="code-line"><span class="s2"> MN yMMMMMMMMMMMMMMMMMNMMMMNNNNNMMMNNNMMMMMNmhMM/-. `yMMNs. /My</span></span>
<span class="code-line"><span class="s2"> `MN :MMmMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmmdy+:-``NM- ./hNNy- /Nd`</span></span>
<span class="code-line"><span class="s2"> -Mh dMydMmsNMNdNNMMmmmNMMMdddhys+yMo`` /Nm: `:yNNdo. .sNd.</span></span>
<span class="code-line"><span class="s2"> +Ms .mMsMN::NN:.:MN: `.+NM. +Mo +Mm+ymNdo- .omm+`</span></span>
<span class="code-line"><span class="s2"> yM: .hNMd+:sMN. oMm. oMo +Mh ```.:+shMNmy+-``.-:-..-//-`:yNmo`</span></span>
<span class="code-line"><span class="s2"> mM. :ohmNNMMdhyMMdo//+Mm//////sMNhyhhdmNNmhs/-``./+/:--+so/-:smNy/`</span></span>
<span class="code-line"><span class="s2"> .Mm `` .-:/+osyyhhddddddddddhhyysoo+/:-. `./+//--+oo/--+ymmy/.</span></span>
<span class="code-line"><span class="s2"> :Mh .: `+:` `.------------` ```-////:/++/:../ydNdo:`</span></span>
<span class="code-line"><span class="s2"> +Ms `/` :+o+:-``` ``..-::///++///:-.`-+ydNdo:`</span></span>
<span class="code-line"><span class="s2"> oMs :/:.`` `..---.``` ````````..-:/:::---.` `-ohmmh+:`</span></span>
<span class="code-line"><span class="s2"> /Mh .://///:::-----.-----.......` `-+hmmy+-</span></span>
<span class="code-line"><span class="s2"> sMy` ``````-+ydmy+-</span></span>
<span class="code-line"><span class="s2"> /mNs-` `./ohmNMNNNmy+-</span></span>
<span class="code-line"><span class="s2"> /yNmho/:.``````````.-:/+syhdNmdyso+/-.`</span></span>
<span class="code-line"><span class="s2"> `:+ydmNMNNNNNNNNNmdhys+/:.`</span></span>
<span class="code-line"><span class="s2"> ``.....`</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="s2"> LOL U MAD?</span></span>
<span class="code-line"><span class="s2">"""</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="kn">import</span> <span class="nn">sys</span></span>
<span class="code-line"><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></span>
</pre></div>
<p>Yes, indead. The idea of using Ruby in Python is totally mad.</p>
</div>
Discuss C++ Template Downcast2012-02-26T05:54:57+09:002012-02-26T05:54:57+09:00farseerfctag:farseerfc.me,2012-02-26:/en/discuss-cpp-template-downcast.html
<p>This is a discuss in C board in bbs.sjtu.edu.cn, about type down-cast in C++ template.</p>
<div class="section" id="original-discuss">
<h2><a class="toc-backref" href="#id1">Original Discuss</a></h2>
<p><a class="reference external" href="http://bbs.sjtu.edu.cn/bbstcon,board,C,reid,1330078933,file,M.1330078933.A.html">http://bbs.sjtu.edu.cn/bbstcon,board,C,reid,1330078933,file,M.1330078933.A.html</a></p>
</div>
<div class="section" id="the-problem">
<h2><a class="toc-backref" href="#id2">The problem</a></h2>
<p>Today I read a book about we can do cast-down in template, so …</p></div>
<p>This is a discuss in C board in bbs.sjtu.edu.cn, about type down-cast in C++ template.</p>
<div class="section" id="original-discuss">
<h2><a class="toc-backref" href="#id1">Original Discuss</a></h2>
<p><a class="reference external" href="http://bbs.sjtu.edu.cn/bbstcon,board,C,reid,1330078933,file,M.1330078933.A.html">http://bbs.sjtu.edu.cn/bbstcon,board,C,reid,1330078933,file,M.1330078933.A.html</a></p>
</div>
<div class="section" id="the-problem">
<h2><a class="toc-backref" href="#id2">The problem</a></h2>
<p>Today I read a book about we can do cast-down in template, so I write this to test:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="k">template</span> <span class="o"><</span><span class="kt">bool</span> <span class="n">_Test</span><span class="p">,</span> <span class="k">class</span> <span class="nc">_Type</span> <span class="o">=</span> <span class="kt">void</span><span class="o">></span></span>
<span class="code-line"><span class="k">struct</span> <span class="n">enable_if</span> <span class="p">{</span> <span class="p">};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span><span class="o"><</span><span class="k">class</span> <span class="nc">_Type</span><span class="o">></span></span>
<span class="code-line"><span class="k">struct</span> <span class="n">enable_if</span><span class="o"><</span><span class="nb">true</span><span class="p">,</span> <span class="n">_Type</span><span class="o">></span> <span class="p">{</span></span>
<span class="code-line"> <span class="k">typedef</span> <span class="n">_Type</span> <span class="n">type</span><span class="p">;</span></span>
<span class="code-line"><span class="p">};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">class</span> <span class="nc">A</span> <span class="p">{</span> <span class="p">};</span></span>
<span class="code-line"><span class="k">class</span> <span class="nc">B</span> <span class="o">:</span> <span class="n">A</span> <span class="p">{</span> <span class="p">};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span></span>
<span class="code-line"><span class="k">struct</span> <span class="n">traits</span> <span class="p">{</span> <span class="k">static</span> <span class="kt">int</span> <span class="k">const</span> <span class="n">value</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span> <span class="p">};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><></span></span>
<span class="code-line"><span class="k">struct</span> <span class="n">traits</span><span class="o"><</span><span class="n">A</span><span class="o">></span> <span class="p">{</span> <span class="k">static</span> <span class="kt">int</span> <span class="k">const</span> <span class="n">value</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span> <span class="p">};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span></span>
<span class="code-line"><span class="kt">void</span> <span class="n">f</span><span class="p">(</span><span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">enable_if</span><span class="o"><</span><span class="n">traits</span><span class="o"><</span><span class="n">T</span><span class="o">>::</span><span class="n">value</span><span class="o">>::</span><span class="n">type</span><span class="o">*</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><></span></span>
<span class="code-line"><span class="kt">void</span> <span class="n">f</span><span class="o"><</span><span class="n">A</span><span class="o">></span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">enable_if</span><span class="o"><</span><span class="n">traits</span><span class="o"><</span><span class="n">A</span><span class="o">>::</span><span class="n">value</span><span class="o">>::</span><span class="n">type</span><span class="o">*</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span></span>
<span class="code-line"></span>
<span class="code-line"></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span></span>
<span class="code-line"><span class="k">class</span> <span class="nc">BB</span> <span class="p">{};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span></span>
<span class="code-line"><span class="k">class</span> <span class="nc">DD</span> <span class="o">:</span> <span class="k">public</span> <span class="n">BB</span><span class="o"><</span><span class="n">T</span><span class="o">></span> <span class="p">{};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> <span class="kt">void</span> <span class="n">ff</span><span class="p">(</span><span class="n">BB</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="p">)</span> <span class="p">{};</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="n">argv</span><span class="p">[])</span></span>
<span class="code-line"><span class="p">{</span></span>
<span class="code-line"> <span class="n">A</span> <span class="n">a</span><span class="p">;</span> <span class="n">B</span> <span class="n">b</span><span class="p">;</span></span>
<span class="code-line"> <span class="n">DD</span><span class="o"><</span><span class="kt">long</span><span class="o">></span> <span class="n">dd</span><span class="p">;</span></span>
<span class="code-line"> <span class="c1">//f(b);</span></span>
<span class="code-line"> <span class="n">ff</span><span class="p">(</span><span class="n">dd</span><span class="p">);</span></span>
<span class="code-line"><span class="p">}</span></span>
</pre></div>
<p>It is strange when <code class="code">
f</code>
it don't allow my specified <code class="code">
f<A>`</code>
.</p>
<p>But in <code class="code">
ff</code>
it allowed <code class="code">
ff<BB<long>>`</code>
.</p>
<p>Tested under VC10 and GCC3.4</p>
</div>
<div class="section" id="my-answer-to-the-problem">
<h2><a class="toc-backref" href="#id3">My answer to the problem</a></h2>
<p>Let's think ourself as compiler to see what happened there.</p>
<p>Define mark <code class="code">
#</code>
: <code class="code">
A#B</code>
is the instantiated result when we put <code class="code">
B</code>
into the parameter <code class="code">
T</code>
of <code class="code">
A<T></code>
.</p>
<div class="section" id="first-we-discuss-ff">
<h3><a class="toc-backref" href="#id4">First we discuss ff</a></h3>
<div class="highlight"><pre><span class="code-line"><span></span><span class="n">DD</span><span class="o"><</span><span class="kt">long</span><span class="o">></span> <span class="n">dd</span><span class="p">;</span></span>
</pre></div>
<p>After this sentense, the compiler saw the instantiation of <code class="code">
DD<long></code>
, so it instantiate <code class="code">
DD#long</code>
, and also <code class="code">
BB#long</code>
.</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="n">ff</span><span class="p">(</span><span class="n">dd</span><span class="p">);</span></span>
</pre></div>
<p>This sentense required the compiler to calculate set of overloading functions.</p>
<p>Step 1 we need to infer <code class="code">
T</code>
of <code class="code">
ff<T></code>
from argument <code class="code">
DD#long -> BB<T></code>
. Based on the inference rule:</p>
<pre class="literal-block">
Argument with type :code:`class_template_name<T>` can be use to infer :code:`T``.
</pre>
<p>So compiler inferred <code class="code">
T</code>
as <code class="code">
long</code>
. Here if it is not <code class="code">
BB</code>
but <code class="code">
CC</code>
which is complete un-related, we can also infer, as long as <code class="code">
CC</code>
is a template like <code class="code">
CC<T></code>
.</p>
<p>Step 2 Template Specialization Resolution. There is only one template here so we matched <code class="code">
ff<T></code>
.</p>
<p>Step 3 Template Instantiation</p>
<p>After inferred <code class="code">
long -> T</code>
, compiler instantiated <code class="code">
ff#long</code>
.</p>
<p>Set of available overloading functions : <code class="code">
{ff#long}</code>
</p>
<p>Then overloading resolution found the only match <code class="code">
ff#long`</code>
, checked its real parameter <code class="code">
DD#long</code>
can be down-cast to formal parameter <code class="code">
BB#long</code>
.</p>
</div>
<div class="section" id="then-we-discuss-f">
<h3><a class="toc-backref" href="#id5">Then we discuss f</a></h3>
<div class="highlight"><pre><span class="code-line"><span></span><span class="n">f</span><span class="p">(</span><span class="n">b</span><span class="p">);</span></span>
</pre></div>
<p>Calculate set of overloading functions.</p>
<p>Step 1 infer all template parameters for template <code class="code">
f</code>
. According to inference rule:</p>
<pre class="literal-block">
Parameter with type T can be used to infer T 。
</pre>
<p>So <code class="code">
B -> T</code>
is inferred.</p>
<p>Step 2 Template Specialization Resolution.</p>
<p>Here <code class="code">
B</code>
is not <code class="code">
A</code>
so we can not apply specialization of <code class="code">
f<A></code>
, remaining <code class="code">
f<T></code>
as the only alternative.</p>
<p>Step 3 Template Instantiation.</p>
<p>When we put <code class="code">
B</code>
into <code class="code">
f<T></code>
to instantiate as <code class="code">
f#B</code>
, we need to instantiate <code class="code">
traits#B`</code>
.</p>
<p>There is no specialization for <code class="code">
B</code>
so we use template <code class="code">
traits<T></code>
, <code class="code">
traits#B::value=false</code>
, so <code class="code">
enable_if#false</code>
didn't contains a <code class="code">
type</code>
, an error occurred.</p>
<p>The only template is mismatch, available overloading functions is empty set. So we got an error.</p>
</div>
</div>
Give a try to Pelican2012-02-24T17:33:00+09:002012-02-24T17:33:00+09:00farseerfctag:farseerfc.me,2012-02-24:/en/try-pelican.html<p>It seems in one night
<a class="reference external" href="http://blog.yxwang.me/2011/11/migrated-to-octopress/">all</a>
<a class="reference external" href="http://xoyo.name/2012/02/migrate-to-octopress/">geeks</a>
have
<a class="reference external" href="http://blog.xdite.net/posts/2011/10/07/what-is-octopress/">their</a>
<a class="reference external" href="http://www.yangzhiping.com/tech/octopress.html">own</a>
<a class="reference external" href="http://pages.github.com/#user__organization_pages">Github User Page</a>
and <a class="reference external" href="http://octopress.org/">Octopress</a> Blog.
Like everyone posted in their blogs, Static Blog is indeed more convenient than traditional
Blog systems such as WordPress. I have been wanting my own <a class="reference external" href="http://octopress.org/">Octopress</a> since then.</p>
<div class="section" id="but-it-seems-that-octopress-isn-t-for-me">
<h2>But it seems that <a class="reference external" href="http://octopress.org/">Octopress</a> isn't …</h2></div><p>It seems in one night
<a class="reference external" href="http://blog.yxwang.me/2011/11/migrated-to-octopress/">all</a>
<a class="reference external" href="http://xoyo.name/2012/02/migrate-to-octopress/">geeks</a>
have
<a class="reference external" href="http://blog.xdite.net/posts/2011/10/07/what-is-octopress/">their</a>
<a class="reference external" href="http://www.yangzhiping.com/tech/octopress.html">own</a>
<a class="reference external" href="http://pages.github.com/#user__organization_pages">Github User Page</a>
and <a class="reference external" href="http://octopress.org/">Octopress</a> Blog.
Like everyone posted in their blogs, Static Blog is indeed more convenient than traditional
Blog systems such as WordPress. I have been wanting my own <a class="reference external" href="http://octopress.org/">Octopress</a> since then.</p>
<div class="section" id="but-it-seems-that-octopress-isn-t-for-me">
<h2>But it seems that <a class="reference external" href="http://octopress.org/">Octopress</a> isn't for me</h2>
<p>At first I was confused by <a class="reference external" href="http://octopress.org/docs/setup/">Setup Steps of Octopress</a> . What is this <a class="reference external" href="http://beginrescueend.com/">RVM</a> thing?
And what is that <a class="reference external" href="https://github.com/sstephenson/rbenv">rbenv</a> thing? It seems the high pace of Ruby community has beyond my imagination to a degree that
they need a version manager to ensure the compatibility of different versions of Ruby. Althrough the same compatibility
issue also troubles Python community <a class="footnote-reference" href="#id3" id="id1">[1]</a> , but at least Python don't need a version manager (yet) to control this mass <a class="footnote-reference" href="#id4" id="id2">[2]</a> .</p>
<p>Real problem for me is that I haven't yet a Linux box that I can play around freely. (I really want one ... ) Both <a class="reference external" href="http://beginrescueend.com/">RVM</a> and
<a class="reference external" href="https://github.com/sstephenson/rbenv">rbenv</a> needs to run on Unix/Linux/MacOSX. One can not be a geek if he use Windows ? (Maybe it's true...)</p>
<p>Remaining problem is the battle between Ruby and Python campaign. I haven't tried <a class="reference external" href="http://daringfireball.net/projects/markdown/">Markdown</a> , and I rather like <a class="reference external" href="http://docutils.sourceforge.net/rst.html">ReST</a> .
It seems that both sides depend on <a class="reference external" href="http://pygments.org/">Pygments</a> as code block highlighter so Rubyists need Python environment anyway.
I simply don't want to depend on any Ruby component. It is better when it is in pure Python, no C extensions so that I can
debug into it and make minor modifications.</p>
<p>So I started searching for Static Blog Engine in Python on Github. The author of the great framework <a class="reference external" href="http://flask.pocoo.org/">Flask</a> , <a class="reference external" href="https://github.com/mitsuhiko">mitsuhiko</a> ,
wrote a <a class="reference external" href="https://github.com/mitsuhiko/rstblog">rstblog</a> , but it's not well developed. <a class="reference external" href="http://ringce.com/hyde">Hyde</a> seems to be complete enough, but it use <a class="reference external" href="http://daringfireball.net/projects/markdown/">MarkDown</a> as its default markup
language, and the design of its homepage is too fashion to be used as blog. Finally I found <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a> .</p>
<table border="0" class="docutils table footnote" frame="void" id="id3" rules="none">
<colgroup><col class="label"/><col/></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Such as the difference between Python 2.x and 3.x , and also difference in C-API of implementations of <a class="reference external" href="http://pypy.org/">PyPy</a> , <a class="reference external" href="http://python.org/">CPython</a> , <a class="reference external" href="http://www.stackless.com/">Stackless</a> , <a class="reference external" href="http://cython.org/">Cython</a> .</td></tr>
</tbody>
</table>
<table border="0" class="docutils table footnote" frame="void" id="id4" rules="none">
<colgroup><col class="label"/><col/></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Yes, we have <a class="reference external" href="http://packages.python.org/distribute/easy_install.html">easy_install</a> and <a class="reference external" href="http://www.pip-installer.org/en/latest/index.html">pip</a> , but all these are package manager, running in a perticular Python implementation. Python implementation itself don't need a manager. Version issue of Python largely have been solved by lightweight converters such as <a class="reference external" href="http://docs.python.org/release/3.0.1/library/2to3.html">2to3.py</a> and <a class="reference external" href="http://www.startcodon.com/wordpress/?cat=8">3to2.py</a> , you don't need to store multiple implementations of Python in your disk for different packages. Yes you can use <a class="reference external" href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> if you need to preserve stablility but this is another story.</td></tr>
</tbody>
</table>
</div>
<div class="section" id="let-it-be-pelican">
<h2>Let it be <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a></h2>
<p>For my own use, <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a> offers me some advantages over <a class="reference external" href="http://octopress.org/">Octopress</a>:</p>
<blockquote>
<ol class="arabic simple">
<li>Implemented in <strong>pure Python</strong>. This means that I can use different implementation of Python other than CPython easily. I use <a class="reference external" href="http://pypy.org/">PyPy</a> myself.</li>
<li>Translation of multi-languages. The original author of <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a> is a France. This is unnecessory for most people, but I will post my blog mainly in three languages: English, Japanese and Chinese.</li>
<li><a class="reference external" href="http://docutils.sourceforge.net/rst.html">ReST</a> . So that I can use the @auto-rst feature of <a class="reference external" href="http://webpages.charter.net/edreamleo/front.html">Leo</a> . And also I don't need to switch between my blog and documentation of my projects.</li>
</ol>
</blockquote>
<p>But it seems that <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a> was less contributed than <a class="reference external" href="http://octopress.org/">Octopress</a> . Some minor issues remains in latest version:</p>
<blockquote>
<ol class="arabic simple">
<li>Support of pelican-import from WordPress for Chinese and Japanese articles are buggy.</li>
<li>Datetime format, timezone, and locale support for multi-language blogs are not so natural. <strong>I will work on this in these days</strong></li>
<li>There are not so many templates compared to <a class="reference external" href="http://octopress.org/">Octopress</a> .</li>
<li>And less plugins .</li>
</ol>
</blockquote>
<p>I hope more people from Python community can contribute to this excellent project, then all these issues will be fixed soon.</p>
</div>
<div class="section" id="my-settings">
<h2>My settings</h2>
<p>To install <a class="reference external" href="http://pelican.notmyidea.org/en/latest/">Pelican</a> is simple:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> pip install pelican</span>
</pre></div>
<p>Write posts in <a class="reference external" href="http://docutils.sourceforge.net/rst.html">ReST</a> , with <pre><span class="code-line"></span>
<span class="code-line">rst</span></pre>
extensions, and put them in <pre><span class="code-line"></span>
<span class="code-line">pages</span></pre>
folder. (Re)Build all pages is simply:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> pelican -s settings.py</span>
</pre></div>
<p>Push to Github:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> git commit -am <span class="s2">"Commit message"</span></span>
<span class="code-line"><span class="gp">$</span> git push</span>
</pre></div>
<p>And following is my <pre><span class="code-line"></span>
<span class="code-line">settings.py</span></pre>
:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="c1"># -*- coding: utf-8 -*-</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">TIMEZONE</span> <span class="o">=</span> <span class="s1">'Asia/Tokyo'</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">DATE_FORMATS</span> <span class="o">=</span> <span class="p">{</span></span>
<span class="code-line"> <span class="s1">'en'</span><span class="p">:(</span><span class="s1">'usa'</span><span class="p">,</span><span class="s1">'</span><span class="si">%a</span><span class="s1">, </span><span class="si">%d</span><span class="s1"> %b %Y'</span><span class="p">),</span></span>
<span class="code-line"> <span class="s1">'zh'</span><span class="p">:(</span><span class="s1">'chs'</span><span class="p">,</span><span class="s1">'%Y-%m-</span><span class="si">%d</span><span class="s1">, </span><span class="si">%a</span><span class="s1">'</span><span class="p">),</span></span>
<span class="code-line"> <span class="s1">'jp'</span><span class="p">:(</span><span class="s1">'jpn'</span><span class="p">,</span><span class="s1">'%Y/%m/</span><span class="si">%d</span><span class="s1"> (</span><span class="si">%a</span><span class="s1">)'</span><span class="p">),</span></span>
<span class="code-line"><span class="p">}</span></span>
<span class="code-line"><span class="c1"># windows locale: http://msdn.microsoft.com/en-us/library/cdax410z%28VS.71%29.aspx</span></span>
<span class="code-line"><span class="n">LOCALE</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'usa'</span><span class="p">,</span> <span class="s1">'chs'</span><span class="p">,</span> <span class="s1">'jpn'</span><span class="p">,</span> <span class="c1"># windows</span></span>
<span class="code-line"> <span class="s1">'en_US'</span><span class="p">,</span> <span class="s1">'zh_CN'</span><span class="p">,</span> <span class="s1">'ja_JP'</span><span class="p">]</span> <span class="c1"># Unix/Linux</span></span>
<span class="code-line"><span class="n">DEFAULT_LANG</span> <span class="o">=</span> <span class="s1">'zh'</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">SITENAME</span> <span class="o">=</span> <span class="s1">'Farseerfc Blog'</span></span>
<span class="code-line"><span class="n">AUTHOR</span> <span class="o">=</span> <span class="s1">'Jiachen Yang'</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">DISQUS_SITENAME</span> <span class="o">=</span> <span class="s1">'farseerfcgithub'</span></span>
<span class="code-line"><span class="n">GITHUB_URL</span> <span class="o">=</span> <span class="s1">'https://github.com/farseerfc'</span></span>
<span class="code-line"><span class="n">SITEURL</span> <span class="o">=</span> <span class="s1">'http://farseerfc.github.com'</span></span>
<span class="code-line"><span class="n">TAG_FEED</span> <span class="o">=</span> <span class="s1">'feeds/</span><span class="si">%s</span><span class="s1">.atom.xml'</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">SOCIAL</span> <span class="o">=</span> <span class="p">((</span><span class="s1">'twitter'</span><span class="p">,</span> <span class="s1">'http://twitter.com/farseerfc'</span><span class="p">),</span></span>
<span class="code-line"> <span class="p">(</span><span class="s1">'github'</span><span class="p">,</span> <span class="s1">'https://github.com/farseerfc'</span><span class="p">),</span></span>
<span class="code-line"> <span class="p">(</span><span class="s1">'facebook'</span><span class="p">,</span> <span class="s1">'http://www.facebook.com/farseerfc'</span><span class="p">),</span></span>
<span class="code-line"> <span class="p">(</span><span class="s1">'weibo'</span><span class="p">,</span> <span class="s1">'http://weibo.com/farseerfc'</span><span class="p">),</span></span>
<span class="code-line"> <span class="p">(</span><span class="s1">'renren'</span><span class="p">,</span> <span class="s1">'http://www.renren.com/farseer'</span><span class="p">),</span></span>
<span class="code-line"> <span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">TWITTER_USERNAME</span> <span class="o">=</span> <span class="s1">'farseerfc'</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">THEME</span><span class="o">=</span><span class="s1">'notmyidea'</span></span>
<span class="code-line"><span class="n">CSS_FILE</span> <span class="o">=</span> <span class="s2">"wide.css"</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">DEFAULT_CATEGORY</span> <span class="o">=</span><span class="s1">'Others'</span></span>
<span class="code-line"><span class="n">OUTPUT_PATH</span> <span class="o">=</span> <span class="s1">'.'</span></span>
<span class="code-line"><span class="n">PATH</span> <span class="o">=</span> <span class="s1">'posts'</span></span>
</pre></div>
</div>
“…if we do this work … ” --Bill Gates2011-03-14T20:34:00+09:002011-03-14T20:34:00+09:00farseerfctag:farseerfc.me,2011-03-14:/en/if-we-do-this-work.html<p>Imported from
<a class="reference external" href="http://blog.renren.com/blog/230263946/716517729">renren</a></p>
<div class="section" id="if-we-do-this-work-and-the-result-is-that-linux-works-great-bill-gates">
<h2>“…if we do this work … and the result is that Linux works great …” --Bill Gates</h2>
<p>From: Bill Gates</p>
<p>’-- Sent: Sunday, January 24, 1999 8:41 AM</p>
<p>Jeff Westorinon; Ben Fathi ;</p>
<p>TO: Carl Stork (Exchange); Nathan Myhrvofd; Eric Rudder</p>
<p>Subject: ACPI extensions</p>
<p>One thing I find myself wondering …</p></div><p>Imported from
<a class="reference external" href="http://blog.renren.com/blog/230263946/716517729">renren</a></p>
<div class="section" id="if-we-do-this-work-and-the-result-is-that-linux-works-great-bill-gates">
<h2>“…if we do this work … and the result is that Linux works great …” --Bill Gates</h2>
<p>From: Bill Gates</p>
<p>’-- Sent: Sunday, January 24, 1999 8:41 AM</p>
<p>Jeff Westorinon; Ben Fathi ;</p>
<p>TO: Carl Stork (Exchange); Nathan Myhrvofd; Eric Rudder</p>
<p>Subject: ACPI extensions</p>
<p>One thing I find myself wondering about is whether we shouldn’t try and
make the "ACPI" extensions somehow Windows specific.</p>
<p>It seems unfortunate if we do this work and get our partners to do the
work and the result is that <strong>Linux works great without having to do the work</strong>.</p>
<p><strong>Maybe there is no way to avoid this problem but it does bother me.</strong></p>
<p>Maybe we could define the APIs so that they work well with NT and not
the others even if they are open.</p>
<p>Or maybe we could patent something relaled to this.</p>
<p>From:</p>
<p><a class="reference external" href="http://antitrust.slated.org/www.iowaconsumercase.org/011607/3000/PX03020.pdf">http://antitrust.slated.org/www.iowaconsumercase.org/011607/3000/PX03020.pdf</a></p>
<p>If this is the reason that Xen 4.0 is still not fully support ACPI 3.0, then f*ck
you Bill Gates!</p>
</div>
Write a program to keep CPU usage as sin funcion2008-06-02T23:27:00+09:002008-06-02T23:27:00+09:00farseerfctag:farseerfc.me,2008-06-02:/en/sine-cpu.html<p>Imported from:
<a class="reference external" href="http://blog.renren.com/blog/230263946/298871889">renren</a>.</p>
<p>It is said that this is a problem from interview of Microsoft. Write a program, which makes the CPU usage curve in Windows Task Manager shows a Sin function.</p>
<img alt="Sine function 1" class="img-responsive align-center" src="http://fm531.img.xiaonei.com/pic001/20080602/23/14/large_10019p67.jpg"/>
<img alt="Sine function 2" class="img-responsive align-center" src="http://fm541.img.xiaonei.com/pic001/20080602/23/14/large_9935o67.jpg"/>
<p>The program below is written in java:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">sincpu</span> <span class="p">{</span></span>
<span class="code-line"> <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">cycle</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span><span class="n">tick</span> <span class="o">=</span> <span class="mi">256 …</span></span></pre></div><p>Imported from:
<a class="reference external" href="http://blog.renren.com/blog/230263946/298871889">renren</a>.</p>
<p>It is said that this is a problem from interview of Microsoft. Write a program, which makes the CPU usage curve in Windows Task Manager shows a Sin function.</p>
<img alt="Sine function 1" class="img-responsive align-center" src="http://fm531.img.xiaonei.com/pic001/20080602/23/14/large_10019p67.jpg"/>
<img alt="Sine function 2" class="img-responsive align-center" src="http://fm541.img.xiaonei.com/pic001/20080602/23/14/large_9935o67.jpg"/>
<p>The program below is written in java:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">sincpu</span> <span class="p">{</span></span>
<span class="code-line"> <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">cycle</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span><span class="n">tick</span> <span class="o">=</span> <span class="mi">256</span><span class="p">;</span></span>
<span class="code-line"> <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span> <span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="kd">throws</span> <span class="n">InterruptedException</span> <span class="p">{</span></span>
<span class="code-line"> <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span></span>
<span class="code-line"> <span class="n">work</span><span class="p">(</span><span class="n">calcNextSleep</span><span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="n">cycle</span><span class="p">));</span></span>
<span class="code-line"> <span class="n">sleep</span><span class="p">(</span><span class="n">tick</span> <span class="o">-</span> <span class="n">calcNextSleep</span><span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="n">cycle</span><span class="p">));</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="kd">private</span> <span class="kd">static</span> <span class="kt">long</span> <span class="nf">calcNextSleep</span><span class="p">(</span><span class="kt">long</span> <span class="n">i</span><span class="p">){</span></span>
<span class="code-line"> <span class="k">return</span> <span class="p">(</span><span class="kt">int</span><span class="p">)(</span><span class="n">Math</span><span class="p">.</span><span class="na">sin</span><span class="p">((</span><span class="kt">double</span><span class="p">)</span><span class="n">i</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">Math</span><span class="p">.</span><span class="na">PI</span> <span class="o">/</span> <span class="n">cycle</span><span class="p">)</span> <span class="o">*</span> <span class="n">tick</span> <span class="o">+</span> <span class="n">tick</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="kd">private</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">sleep</span> <span class="p">(</span><span class="kt">long</span> <span class="n">sleepTime</span><span class="p">)</span> <span class="kd">throws</span> <span class="n">InterruptedException</span></span>
<span class="code-line"> <span class="p">{</span></span>
<span class="code-line"> <span class="k">if</span><span class="p">(</span><span class="n">sleepTime</span> <span class="o"><</span> <span class="mi">2</span><span class="p">)</span></span>
<span class="code-line"> <span class="n">Thread</span><span class="p">.</span><span class="na">yield</span><span class="p">();</span></span>
<span class="code-line"> <span class="k">else</span></span>
<span class="code-line"> <span class="n">Thread</span><span class="p">.</span><span class="na">sleep</span><span class="p">(</span><span class="n">sleepTime</span><span class="p">);</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="kd">private</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">work</span> <span class="p">(</span><span class="kt">long</span> <span class="n">period</span><span class="p">)</span> <span class="p">{</span></span>
<span class="code-line"> <span class="kt">long</span> <span class="n">start</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">currentTimeMillis</span><span class="p">();</span></span>
<span class="code-line"> <span class="k">for</span><span class="p">(;;){</span></span>
<span class="code-line"> <span class="n">Math</span><span class="p">.</span><span class="na">sin</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span></span>
<span class="code-line"> <span class="k">if</span><span class="p">(</span><span class="n">System</span><span class="p">.</span><span class="na">currentTimeMillis</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> <span class="o">>=</span> <span class="n">period</span><span class="p">)</span></span>
<span class="code-line"> <span class="k">break</span><span class="p">;</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"> <span class="p">}</span></span>
<span class="code-line"><span class="p">}</span></span>
</pre></div>
<p>Be careful you need to turn off other cores if you have multi-core CPU.</p>
<img alt="multi-core CPU" class="img-responsive align-center" src="http://fm411.img.xiaonei.com/pic001/20080602/23/14/large_9946k67.jpg"/>
EVA-Komm,susser Tod2008-04-10T03:28:00+09:002008-04-10T03:28:00+09:00farseerfctag:farseerfc.me,2008-04-10:/en/EVA-Komm-susser-Tod.html<p>Imported from
<a class="reference external" href="http://blog.renren.com/blog/230263946/282668291">renren</a></p>
<p>I know, I know I''ve let you down</p>
<p>I''ve been a fool to myself</p>
<p>I thought that I could live for no one else</p>
<p>But now through all the hurt and pain</p>
<p>It''s time for me to respect</p>
<p>The ones you love mean more than anything</p>
<hr class="docutils"/>
<p>So …</p><p>Imported from
<a class="reference external" href="http://blog.renren.com/blog/230263946/282668291">renren</a></p>
<p>I know, I know I''ve let you down</p>
<p>I''ve been a fool to myself</p>
<p>I thought that I could live for no one else</p>
<p>But now through all the hurt and pain</p>
<p>It''s time for me to respect</p>
<p>The ones you love mean more than anything</p>
<hr class="docutils"/>
<p>So with sadness in my heart</p>
<p>Feel the best thing I could do</p>
<p>It''s end it all</p>
<p>And leave forever</p>
<p>What''s done is done it feel so bad</p>
<p>What once was happy now is sad</p>
<p>I''ll never love again</p>
<p>My world is ending</p>
<hr class="docutils"/>
<p>I wish that I could turn back time</p>
<p>Cause now the guilt is all mine</p>
<p>Can''t live without the trust from those you love</p>
<p>I know we can''t forget the past</p>
<p>You can''t forget love and pride</p>
<p>Because that it''s killing me inside</p>
<hr class="docutils"/>
<p>It all returns to nothing</p>
<p>It all comes tumbling down tumbling down tumbling down</p>
<p>It all returns to nothing</p>
<p>I just keep letting me down letting me down letting me down</p>
<hr class="docutils"/>
<p>In my heart of hearts</p>
<p>I know I could never love again</p>
<p>I''ve lost everything everything</p>
<p>Everything that matters to me matters in this world</p>
<hr class="docutils"/>
<p>I wish that I could turn back time</p>
<p>Cause now the guilt is all mine</p>
<p>Can''t live without the trust from those you love</p>
<p>I know we can''t forget the past</p>
<p>You can''t forget love and pride</p>
<p>Because that it''s killing me inside</p>
<hr class="docutils"/>
<p>It all returns to nothing</p>
<p>It just keeps tumbling down tumbling down tumbling down</p>
<p>It all returns to nothing</p>
<p>I just keep letting me down letting me down letting me down</p>
<hr class="docutils"/>
<p>Up up up up up</p>
<p>Tumbling down tumbling down tumbling down</p>
<p>Up up up up up</p>
<p>Letting me down letting me down letting me down</p>
<p>Up up up up up</p>
<p>Tumbling down tumbling down tumbling down</p>
<p>Up up up up up</p>
<p>Letting me down letting me down letting me down</p>