<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Alecs&apos; Blog</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/" />
    <link rel="self" type="application/atom+xml" href="http://linuxfire.com.cn:81/~alecs/mt4blog/atom.xml" />
    <id>tag:linuxfire.com.cn,2009-09-01:/~alecs/mt4blog//1</id>
    <updated>2009-06-30T07:48:34Z</updated>
    <subtitle>Did you ever go clear..</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.31-en</generator>

<entry>
    <title>Running Spaz on WebOS Emulator</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2009/06/running-spaz-on-webos-emulator.html" />
    <id>tag:linuxfire.com.cn,2009:/~alecs/mt4blog//1.74</id>

    <published>2009-06-30T07:18:17Z</published>
    <updated>2009-06-30T07:48:34Z</updated>

    <summary> You got root, you got everything. Yeah, Palm Pre is hot these days. Now with the webos emulator and ssh available, you can have more fun out of it. Once you ssh to the emulator, you can see there&apos;s...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Linux" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<blockquote>
  <p>You got root, you got everything.</p>
</blockquote>

<p>Yeah, Palm Pre is hot these days.  Now with the <a href="http://www.geektang.com/2009/06/linuxwebos.html">webos emulator</a> and <a href="http://www.geektang.com/2009/06/sshwebos.html">ssh</a> available, you can have more fun out of it.</p>

<p>Once you ssh to the emulator, you can see there's  <code>/usr/bin/ipkg</code>, by which you can list and install .ipk packages.</p>

<p>And all applications are in the <code>/usr/palm/applications</code> directory.  <a href="http://funkatron.com/spaz/">Spaz</a> is a twitter client for webos and whats more, it's open source!  Just grab <a href="http://github.com/funkatron/spaz-webos/tree/master">spaz-webos</a> and <a href="http://github.com/funkatron/spazcore/tree/master">spazcore</a>.  Put spaz-webos contents to <code>/usr/palm/applications/com.funkatron.app.spaz</code>  and spazcore contents to <code>/usr/palm/applications/com.funkatron.app.spaz/spazcore</code>.  </p>

<p><a href="http://linuxfire.com.cn/~alecs/pics/webos/">some screenshots</a></p>
]]>
        

    </content>
</entry>

<entry>
    <title>Haskell Platform</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2009/06/haskell-platform.html" />
    <id>tag:linuxfire.com.cn,2009:/~alecs/mt4blog//1.73</id>

    <published>2009-06-28T11:33:51Z</published>
    <updated>2009-06-28T11:42:56Z</updated>

    <summary> The Haskell Platform is a blessed library and tool suite for Haskell distilled from Hackage, along with installers for a wide variety of systems. IOW, It&apos;s Haskell with Batteries Included. ghc on jaunty is totally out of date. I...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Haskell" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<blockquote>
  <p>The Haskell Platform is a blessed library and tool suite for Haskell distilled from Hackage, along with installers for a wide variety of systems. </p>
</blockquote>

<p>IOW, It's Haskell with Batteries Included.</p>

<p>ghc on jaunty is totally out of date.  I recommend you grab the latest bin from the <a href="http://haskell.org/ghc">ghc official site</a>.  After that, just install <a href="http://hackage.haskell.org/platform/">Haskell Platform</a>. It contains a variety of selected commonly <a href="http://hackage.haskell.org/platform/contents.html">useful lib and tools</a>. You just dont need to install (and set up) 'em one by one.</p>

<p>Just a note for jaunty: install libedit-dev (not libeditline-dev) if you got a dep error for editline.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>When MT Meets iPhone/iPod Touch</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2009/05/when-mt-meets-iphoneipod-touch.html" />
    <id>tag:linuxfire.com.cn,2009:/~alecs/mt4blog//1.72</id>

    <published>2009-05-25T15:34:53Z</published>
    <updated>2009-05-25T16:06:05Z</updated>

    <summary>Just found iMT. It&apos;s the iphone / ipod touch interface for mt4. So now you can add/edit blog entries / comments on your favorite device using the familiar web ui. =) Just extract the tarball and no config at all....</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="MT" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="iPhone" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>Just found <a href="http://plugins.movabletype.org/imt/">iMT</a>. It's the iphone / ipod touch interface for mt4.  So now you can add/edit blog entries / comments on your favorite device using the familiar web ui. =)   Just extract the tarball and no config at all. Just type your original mt admin path in safari on iphone and you'll see the slick UI. Sreenshots: <a href="http://linuxfire.com.cn/~alecs/pics/touch/mt/entries.png">entries view</a> and <a href="http://linuxfire.com.cn/~alecs/pics/touch/mt/write.png">add a new entry</a>.</p>

<p>And also <a href="http://plugins.movabletype.org/iphone-template-set/">iPhone Template Set</a>.  By adopting it you can publish iphone-friendly pages. After extrating it, you can see here <a href="http://www.movabletype.org/documentation/designer/template-sets.html">how to use a template set</a>. Now if you are using iphone / ipod touch to view <a href="http://linuxfire.com.cn:81/~alecs/mt4blog/">my blog</a>, you should be auto directed to the <a href="http://linuxfire.com.cn:81/~alecs/mt4blog/m/">mobile version</a>. Check out <a href="http://linuxfire.com.cn:81/~alecs/mt4blog/2009/05/all-project-euler-problems-solved.html">this entry</a> in your iphone. Should get auto directed to the <a href="http://linuxfire.com.cn:81/~alecs/mt4blog/m/2009/05/all-project-euler-problems-solved.html">mobile page</a>. Screenshots: <a href="http://linuxfire.com.cn/~alecs/pics/touch/mt/main.png">main page</a> and <a href="http://linuxfire.com.cn/~alecs/pics/touch/mt/one.png">a specific entry</a>.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>All Project Euler Problems Solved</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2009/05/all-project-euler-problems-solved.html" />
    <id>tag:linuxfire.com.cn,2009:/~alecs/mt4blog//1.71</id>

    <published>2009-05-20T01:26:50Z</published>
    <updated>2009-05-20T03:21:27Z</updated>

    <summary>Project Euler continues to be fun. First reached 100% when there were 240 problems. And have successfully guarded that honor since =). (As of this writing, there are now 245 problems). Well, not that easy. Recent problems tend to be...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Algorithm" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Math" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p><a href="http://projecteuler.net">Project Euler</a> continues to be fun.  First reached 100% when there were 240 problems.  And have successfully guarded that honor since =).  (As of this writing, there are now 245 problems).  Well, not that easy.  Recent problems tend to be more difficult IMNSHO. In the process, you learn new stuff, refresh your old knowledge and gradually become a better problem-solver.</p>

<p>In the no-spoiler tradition of Project Euler (oh, they say "If you cant solve it, you cant solve it. Dont ask."), i would not disclose any direct answer or code. Instead, I'd love to share some of my experience and give some general advice for newcomers:</p>

<ol>
<li><p>Learn maths.  You dont have to be a mathematician to solve Project Euler problems but the more math knowledge you have, the easier it would be. And in fact, the math required is not that 'deep' since Project Euler is not a pure math puzzle. It's more like a programming challenge based on some math background. So other than depth, try broadening the breadth of your math knowledge. Get interested in more math topics and learn to appreciate the beauty of the diverse math world. <a href="http://www.amazon.com/Mathematics-Elementary-Approach-Ideas-Methods/dp/0195105192">What Is Mathematics</a> is a very good book to read. And btw, seems Project Euler devs more like these 3 fields than others: Number Theory, Combinatorics and Probability.</p></li>
<li><p>Learn algorithms.  If judged only by the algorithms required, Project Euler problems are not as difficult as ACM/ICPC problems.  Dynamic Programming might be Project Euler's favorite algorithm. Graph algorithms like bfs, dfs or shortest path are also good to know. And whats more important,  learn algorithm runtime-and-space analysis. IOW, have a good estimate on how long your code will run and how much memory it will consume. </p></li>
<li><p>Know your tools/langs and sharpen your coding skills. Some problems can be easier solved by using a particular lib or programming language than other. Some heavy brute force might need you to cut the cost as much as possible.  Better some knowledge of a few different langs (procedure, object, functional, script, etc.) with 1 or 2 very-good-at.</p></li>
<li><p>Dont fear the problems. "Only Thing We Have to Fear Is Fear Itself". There's no fun if the problems are not difficult. And different ppl have different knowledge backgrounds and expertise. So a problem easy for others might look very difficult to you.  Learn the new math on-the-road. Often than not, there's a mention of the needed math background in the problem description. You can search and study it. And sometimes, there is no such magic or elegant solution at all. Please dont be a perfectionist and never be shy to get your hands dirty to try on small cases.  You'll find some patterns that'd enlighten you very much.</p></li>
<li><p><a href="http://en.wikipedia.org/wiki/Thinking_outside_the_box">Think outside the box</a>. If you get stuck, try thinking of another different approach, sometimes totally different. Try to view the problem in other perspective. Be open-minded and learn to be 'creative' and 'smart'.  Hints: some geometry problems in fact turn out not to be geometric at all. Cut all tedious lines, circles, sine and cosine; think of abstract combinatoric items.</p></li>
</ol>

<p>Project Euler problem is a mixture of math, algo and coding. Solving them is a mixture of joy and pain, trail and fail, fun and frustration, love and hate.</p>

<p>Here are all <a href="http://eulerfun.appspot.com">my solutions</a> to Project Euler.  Of course, I wont spoil the real fun and you have to solve the problem yourself thus know the answer to see my code, not vice versa.  The site is on top of Google app engine and currently very primitive (poor ui but please dont say 'ugly'). I'm not into web dev very much.  You can see <a href="http://github.com/int/eulerfun/tree/master">the code on github</a>.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Million Digits of E, Sqrt(2), Pi</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/11/a-million-digits-of-e-sqrt2-pi.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.70</id>

    <published>2008-11-24T09:12:25Z</published>
    <updated>2008-11-24T10:42:48Z</updated>

    <summary> More puzzles, more fun. Besides acm oj and projecteuler, i also like to solve the puzzles on spoj. The ACM/ICPC rules are rather limited -- you have to submit the src code (only one file) in java or c/c++....</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Algorithm" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Math" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<blockquote>
  <p>More puzzles, more fun.</p>
</blockquote>

<p>Besides <a href="http://acm.tju.edu.cn/toj/ranklist.html">acm oj</a> and <a href="http://projecteuler.net">projecteuler</a>, i also like to solve the puzzles on <a href="http://spoj.pl">spoj</a>. The ACM/ICPC rules are rather limited -- you have to submit the src code (only one file) in java or c/c++.  ProjectEuler is much more free: it just accepts the final answer -- you are free to use any tools/langs as you like.  Spoj stands kinda in between: it still accepts a one-file-src but you can use a lot of languages (just to name a few: bash, perl, lua, lisp,  python, haskell, c, asm, etc.). In other words, it's hard to not to find your favorite language there.  But you cannot use any external src or libs (only standard feature or lib of the langauge is allowed).</p>

<p>Among many interesteting puzzles, spoj has some <a href="http://www.spoj.pl/problems/challenge/">challenge problems</a>.  These problems are not simply checked right-or-wrong. Instead it makes the rank based on its problem-specific scoring: usually precision, sometimes code-length.  Take the following three for example:</p>

<ul>
<li><a href="http://www.spoj.pl/problems/EVAL/">Digits of e</a></li>
<li><a href="http://www.spoj.pl/problems/SQRT2/">Digits of sqrt(2)</a></li>
<li><a href="http://www.spoj.pl/problems/PIVAL/">Digits of pi</a></li>
</ul>

<p>The rules are same: given limited time and code-length, calculate the value in as many decimal digits as possible.</p>

<p>All three problems involve arbitrary-precision computations -- you either implement your own FFT or use those languages that have bignum built in (like java, python or haskell). </p>

<ul>
<li>Digits of e -- just use the Taylor expansion with Binary-Splitting.</li>
<li>Digits of sqrt(2) -- Newton iteration (note that each iteration doubles the precision).</li>
<li>Digits of pi -- use Chudnovsky series with Binary-Splitting.</li>
</ul>

<p>For the underlying magic algorithms, see the those wonderful <a href="
http://numbers.computation.free.fr/Constants/constants.html">papers/docs</a>.  Here's a reference implementation for <a href="http://gmplib.org/pi-with-gmp.html">pi digits using gmp</a> -- claims to be the world's fastest -- for as many as billion digits.  Also, <a href="http://code.google.com/p/mpmath">mpmath</a> has some interesting implementations as well.</p>

<p>I myself dont bother to implement a FFT in c/c++ (and i doubt i could write a fast enough version in 4K code). Python is really slow for this (sorry, sad, but true) . Haskell's Integer is using the fast(est) <a href="http://gmplib.org">gmp</a>.  Not only it's fast, it's very convenient and leads to (much) shorter and cleaner code. You can <a href="http://www.spoj.pl/ranks/EVAL/">see</a> <a href="http://www.spoj.pl/ranks/SQRT2/">the</a> <a href="http://www.spoj.pl/ranks/PIVAL/">ranks</a>.  Also specific ranks in your <a href="http://www.spoj.pl/ranks/EVAL/lang=PYTH">favorite</a> <a href="http://www.spoj.pl/ranks/PIVAL/lang=HASK">languages</a>.</p>

<p>Other interesting ones might be:</p>

<ul>
<li><a href="http://www.spoj.pl/problems/SIZECON">Make the src as short as possible</a>. Perl is the ruler for this. But you can try to be the top 1 on a specific language ranking.</li>
<li><a href="http://www.spoj.pl/problems/MAGIC2/">Compress and uncompress in one file</a>. The hard part is how to dump the compressed data in src file.</li>
<li><a href="https://www.spoj.pl/problems/MAR/">Magic Markov</a>. Write code to generate code, with special craft.</li>
</ul>
]]>
        

    </content>
</entry>

<entry>
    <title>Saga of Python and Math</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/11/saga-of-python-and-math.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.69</id>

    <published>2008-11-17T06:29:29Z</published>
    <updated>2008-11-17T08:25:50Z</updated>

    <summary><![CDATA[I've listed some math tools and libraries before. A lot of math tools have their own DSL (domain-specific language) for quick &amp; easy access to their various math functions with some primitive control flows. DSL is better in the sense...]]></summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Math" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Python" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Tools" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>I've listed some <a href="http://linuxfire.com.cn/~alecs/blog/2008/06/project-euler.html">math tools and libraries</a> before. A lot of math tools have their own DSL (domain-specific language) for quick &amp; easy access to their various math functions with some primitive control flows.  DSL is better in the sense that it's relatively convenient and it gets hooked more tightly to the underlying base (i.e. shorter code, more inner-involving). A general programming language has its own strength: it's powerful, elegant, much more mature and more easy to access the 'outer' world.  DSL for the math tools (like the 3 big Ms) sometimes looks kinda awkward from a 'programming' point of view.  Besides, people tend to like doing work in their own favorite languages.</p>

<p>Python is rather popular nowadays. It's been used in various fields -- sys admin, net utility, web, prototyping, unit testing, etc.  -- and of course, in mathematics, science, and engineering. One of the well-known tool chains is: <a href="http://www.scipy.org/">scipy</a> + <a href="http://www.scipy.org/NumPy">numpy</a> + <a href="http://matplotlib.sourceforge.net/">matplotlib</a> + <a href="http://ipython.scipy.org/moin/">ipython</a> aka the <a href="http://www.scipy.org/PyLab">PyLab</a>.   scipy/numpy is tremendously good for numeric computation and matplotlib can generate high-quality <a href="http://matplotlib.sourceforge.net/gallery.html">2D plots</a> -- in your <a href="http://matplotlib.sourceforge.net/examples/index.html">favorite language</a>.</p>

<p>Another tool chain i'd like to share is for symbolic manipulation: <a href="http://code.google.com/p/gmpy/">gmpy</a>  + <a href="http://code.google.com/p/mpmath/">mpmath</a> + <a href="http://code.google.com/p/sympy/">sympy</a>.  gmpy provides the python binding for <a href="http://gmplib.org/">gmp</a>, mpmath provides some high-level arbitrary-precision computing functions while sympy is really good at symbolic processing with great 2D/3D plotting support and a convenient interactive 'isympy'.  Your distro may have these pkgs but please check if they are outdated.  I recommend you use the latest version built from their <a href="http://code.google.com/p/gmpy/source/checkout">own</a> <a href="http://git.sympy.org/?p=sympy.git">repos</a>.  (sympy has included mpmath, btw). Newer versions are way faster -- Try calculating 1M digits of Pi.</p>

<p>And here's a big all-in-one math tool called <a href="http://www.sagemath.org/">sage</a>, which is using python as the primary programming language and can be regarded as a free alternative to the 3 big Ms.</p>

<p>Also, two tools not specifically for math: <a href="http://psyco.sourceforge.net/">psyco</a> and <a href="http://www.parallelpython.com/">parallel python</a> (via <a href="http://li2z.cn/2008/11/09/parallel_python/">bones</a>).  psyco is kind of a python JIT. If you do a lot of cpu-bound instructions in python, it is your lovely friend.  pp is for parallel computing (multi-core or even network cluster). It can split computation <a href="http://www.parallelpython.com/content/view/17/31/">at the function level</a>.</p>

<p>Finally, for speed-lovers, there's a language called <a href="http://mathias-kettner.de/wirbel.html">wirbel</a>. It has very similar syntax to python (almost equal). The key difference is that it can compile src to native bin, thus it's very fast. But limited: not all python code can be easily changed and compiled by it of course, at least not now.  Still an interesting alternative anyway.  You might want to have a look.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Install, Boot, Run</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/11/install-boot-run.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.68</id>

    <published>2008-11-14T07:49:05Z</published>
    <updated>2008-11-14T12:54:19Z</updated>

    <summary>Installing linux is much more easier these days. LiveCD is now becoming a de facto standard. Some distro even provides a LiveUSB. If not, here&apos;s a great tool that can help you make a liveusb from a livecd image, automatically:...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Linux" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Tools" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>Installing linux is much more easier these days.  LiveCD is now becoming a de facto standard.  Some distro even provides a LiveUSB.  If not, here's a great tool that can help you make a liveusb from a livecd image, automatically: <a href="http://unetbootin.sourceforge.net/">unetbootin</a>.</p>

<p>Besides the usblive feature, it also supports install-from-net, install-from-windoze, install-from-disk, etc.  If you like to try installing different distros and dont have a CD drive (or dont like to burn CDs), unetbootin is your friend. </p>

<p>Big distros nowadays are all trying hard to make the booting fast: kernel-mode-setting, init-ng, readahead, parallel loading, etc.  Here's a great tool that can monitor and visualize the booting process:  <a href="http://www.bootchart.org/">bootchart</a>.  I upgraded to <a href="http://www.ubuntu.com/products/whatisubuntu/810features/">Intrepid</a> weeks ago.  And here's a <a href="http://linuxfire.com.cn/~alecs/pics/intrepid-20081113-1.png">bootchart shot</a>.</p>

<p>35 seconds: a cold start, from boot to xorg/gdm running with all common services and wireless network up.  I'm very pleased with this, considering its a ubuntu default kernel, default initrd with default settings.  If you customize your kernel building all needed drivers in with <a href="http://linuxfire.com.cn/~alecs/blog/2007/05/kernel-with-no-initird-or-module.html">no module or initrd</a>, and use a slimmed down DE/WM without many startup services, it may reduce about 10 seconds i guess.</p>

<p>And speaking of wireless network, i've been using <a href="http://projects.gnome.org/NetworkManager/">network-manager</a> for a long time (since edgy?) It works fine (well, though not as half good as AirPort). But not for me in intrepid.   Authentication goes well but it fails requesting an ip address. I dunno why. Maybe the kernel, the iwl driver, the wireless router or the nm itself. Dont bother to figure it out or use the cmd line (iwconfig,  wpa_supplicant, etc.).  Bad me, I am a typical desktop linux user now. Here's a replacement:  <a href="http://wicd.sf.net">wicd</a>.  It works well. No bloat. Kool.</p>

<p>And finally, here's a tool called <a href="http://smolt.fedoraproject.org/">smolt</a> which can gather your hardware information and submit it to its central database.  You can see <a href="http://smolt.fedoraproject.org/static/stats/stats.html">some stats</a> and <a href="http://smolt.fedoraproject.org/static/stats/devices.html">devices information</a>.  Maybe not directly good for you but it helps the community in the long run.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Cabal and Cabal-install</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/11/cabal-and-cabal-install.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.67</id>

    <published>2008-11-13T08:26:57Z</published>
    <updated>2008-12-01T04:53:58Z</updated>

    <summary>Cabal is a system for building and packaging Haskell libraries and programs. Put it another way: its Setup.lhs is like Makefile.pl for perl or setup.py for python. Well, you&apos;ve got the idea. See the user guide for details. And cabal-install...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Haskell" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Tools" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p><a href="http://www.haskell.org/cabal/">Cabal</a> is a system for building and packaging Haskell libraries and programs.  Put it another way: its Setup.lhs is like Makefile.pl for perl or setup.py for python.  Well, you've got the idea.  See the <a href="http://www.haskell.org/cabal/release/latest/doc/users-guide/">user guide</a> for details.</p>

<p>And <a href="http://hackage.haskell.org/trac/hackage/wiki/CabalInstall">cabal-install</a> is like perl's cpan (the command) which can automatically download/install/update haskell package off from <a href="http://hackage.haskell.org/">Hackages</a>.  It's still a work in process.  Occasionally it cant resolve the dep right or miss out one or two packages. You might have to manually install them.  So be warned.</p>

<p>BTW, I dont think many ppl are still using the 'cpan' cmd to install perl modules these days.  At least not for most linux distros.  CPAN perl modules are very mature and most distro vendors have made their own pkg/ports already for you.  But not for haskell, because far few ppl are using/developing haskell pkg.  Either there are no pkg built or if there is, the pkg is usually outdated.  So if you need to install cutting-edge haskell pkg, i recommend cabal-install.  I used it to install <a href="http://www.haskell.org/haskellwiki/Lambdabot">lambdabot</a>.  Almost went fine except a dead dep loop. Manually fixed it anyway.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>200 PE solved and more love of haskell</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/10/200-pe-solved-and-more-love-of-haskell.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.66</id>

    <published>2008-10-21T14:15:47Z</published>
    <updated>2008-11-17T08:34:35Z</updated>

    <summary>Solving project euler problems continued to be fun. Now i have solved 200 out of 213 problems. There have been some relatively easier ones recently added as well as some hard-and-fun ones. Just to name a few: laser beam reflecting...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Algorithm" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Haskell" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Math" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>Solving <a href="http://linuxfire.com.cn/~alecs/blog/2008/06/project-euler.html">project euler</a> problems continued to be fun.  Now i have solved <a href="http://projecteuler.net/index.php?section=scores&amp;level=5">200 out of 213 problems</a>.  There have been some relatively easier ones recently added as well as some hard-and-fun ones.  Just to name a few:</p>

<ul>
<li><a href="http://projecteuler.net/index.php?section=problems&amp;id=202">laser beam reflecting on mirrors</a></li>
<li><a href="http://projecteuler.net/index.php?section=problems&amp;id=213">paranoid flea jumping on a chess board</a></li>
<li><a href="http://projecteuler.net/index.php?section=problems&amp;id=198">secret ambiguous numbers</a></li>
</ul>

<p>And as always, i like to use <a href="http://haskell.org">haskell</a> to solve them if possible.  And the more you use haskell the more you love it.  Here are some (new) haskell resources:</p>

<ul>
<li><a href="http://learnyouahaskell.com/">Learn You a Haskell</a>, great tutorial, very enjoyable.</li>
<li><a href="http://realworldhaskell.org/">Real World Haskell</a>, soon to be published by O'Reilly.</li>
</ul>

<p>Two search engines for haskell (API, library, types, etc.):</p>

<ul>
<li><a href="http://www.haskell.org/hoogle/">Hoogle</a>, Haskell's Google</li>
<li><a href="http://holumbus.fh-wedel.de/hayoo/hayoo.html">Hayoo!</a>, Haskell's Yahoo! 2.0</li>
</ul>
]]>
        

    </content>
</entry>

<entry>
    <title>Cairo Dock and ibus</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/10/cairo-dock-and-ibus.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.65</id>

    <published>2008-10-21T14:00:50Z</published>
    <updated>2008-10-21T14:52:35Z</updated>

    <summary>I&apos;ve been using awn for quite a while. It&apos;s normally ok but sometimes it just has one glitch or another: not very stable. Also the feel is not quite like Mac&apos;s Dock. Now here&apos;s a new one: Cairo Dock. It...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Desktop" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>I've been using <a href="http://linuxfire.com.cn/~alecs/blog/2007/04/avant-and-screenlets.html">awn</a> for quite a while.  It's normally ok but sometimes it just has one glitch or another: not very stable.  Also the feel is not quite like Mac's Dock.  Now here's a new one: <a href="http://www.cairo-dock.org/">Cairo Dock</a>.  It looks great and feels snappy. The icon magnification is just neat.</p>

<p>And for the input method, i got fed up with scim and its crappy dict.  Now i start using <a href="http://code.google.com/p/ibus">ibus</a>. It's written by the same author of <a href="http://code.google.com/p/scim-python">scim-python</a>.  It looks very promising (Dbus based, native theme, etc.) and hopefully has a bright future (i guess).  You can give it a try. </p>
]]>
        

    </content>
</entry>

<entry>
    <title>MT still rocks your world</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/10/mt-still-rocks-your-world.html" />
    <id>tag:linuxfire.com.cn,2008:/~alecs/mt4blog//1.64</id>

    <published>2008-10-10T04:58:57Z</published>
    <updated>2008-10-10T05:15:04Z</updated>

    <summary> Call me old school. I like apache + plain cgi. Export old entries from mt3, install brand new MT4, and import back. Sweet. Smooth. Slick. MT4 has markdown builtin by default so all my entries are rendered with no...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="MT" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<blockquote>
  <p>Call me old school.  I like apache + plain cgi.</p>
</blockquote>

<p>Export old entries from mt3, install brand new <a href="http://movabletype.org/">MT4</a>, and import back.  Sweet. Smooth. Slick. </p>

<p>MT4 has markdown builtin by default so all my entries are rendered with no problem at all.  The new interface is modern and user-friendly, yet still quick and powerful.  Time to dig out more and hopefully to write more.</p>

<blockquote>
  <p>It just works.</p>
</blockquote>
]]>
        

    </content>
</entry>

<entry>
    <title>AideRSS to Aide Your A^HRSS</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/08/aiderss-to-aide-your-ahrss.html" />
    <id>tag:linuxfire.com.cn,2008:/mt4blog//1.63</id>

    <published>2008-08-05T03:56:38Z</published>
    <updated>2008-11-17T09:29:37Z</updated>

    <summary> I dont digg, i reddit. Information-exploding century. Tens of feeds. Hundreds of entries. You might have wasted too much time on reading blog/rss/feeds. Normally, the more feeds you subscribe to, the less percentage of useful entries. I read proggit...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Tools" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<blockquote>
  <p>I dont digg, i reddit.</p>
</blockquote>

<p>Information-exploding century.  Tens of feeds.  Hundreds of entries.  You might have wasted too much time on reading blog/rss/feeds.</p>

<p>Normally, the more feeds you subscribe to, the less percentage of useful entries.   I read <a href="http://www.reddit.com/r/programming/">proggit</a> and <a href="http://news.ycombinator.com/">YC</a> everyday. There are hundreds of updates everyday but only very few is interesting to me. The truth is, what remains interesting is really nice.  So i dont want to miss those interesting ones while i dont want to waste my time doing the manual filtering either.</p>

<p>So here comes a great tool called <a href="http://www.aiderss.com/">aiderss</a> to help you easily locate those 'good' ones without wasting your (precious) time.  It adopts a technique called <a href="http://postrank.com/">PostRank</a> to score/rank a post. Take proggit for example, you can see <a href="http://www.aiderss.com/all/www.reddit.com/r/programming/">all</a>, <a href="http://www.aiderss.com/good/reddit.com/r/programming">good</a>, <a href="http://www.aiderss.com/great/reddit.com/r/programming">great</a> and <a href="http://www.aiderss.com/best/reddit.com/r/programming">best</a> ones all filtered for you.  There are respective rss feeds made for you too. And if you use firefox + google reader, there's also an <a href="http://gr.aiderss.com/">addon</a>.</p>

<p>Oh, lets see <a href="http://www.postrank.com/feed/fae6f2b9247196fe3b828ae0ef823f6d">Alecs' Blog in the postranked mode</a>.</p>

<blockquote>
  <p>Less is more <br />
Less is more than more</p>
</blockquote>
]]>
        

    </content>
</entry>

<entry>
    <title>Cracking RSA for Fun and Profit</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/07/cracking-rsa-for-fun-and-profit.html" />
    <id>tag:linuxfire.com.cn,2008:/mt4blog//1.62</id>

    <published>2008-07-25T09:18:51Z</published>
    <updated>2008-10-10T03:54:36Z</updated>

    <summary>You may use RSA (or other public key crypt method) every day without even noticing it or actually bothering &apos;whats under the hood&apos;. But for one day, you might ask, &quot;what&apos;s actually under the hood anyway?&quot; Recently I&apos;ve been reading...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Algorithm" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>You may use RSA (or other public key crypt method) every day without even noticing it or actually bothering 'whats under the hood'.  But for one day, you might ask, "what's actually under the hood anyway?"</p>

<p>Recently I've been reading a new book about algorithms -- <a href="http://www.cs.berkeley.edu/~vazirani/algorithms.html">Algorithms</a>.  In the Chap 1 <a href="http://www.cs.berkeley.edu/~vazirani/algorithms/chap1.pdf">Algorithms with numbers</a>, the authors give a very good view of the underlying theory and smoothly outline the <a href="http://en.wikipedia.org/wiki/RSA">elegant algorithm</a>.  You never truly understand an algorithm until you get your feet^Whands wet and actually code a working implementation.</p>

<p>So here's a small <a href="http://linuxfire.com.cn/~alecs/code/rsa.hs">RSA skeleton</a> implemented in haskell, which contains all bits including: Fermat's testing, getting random large primes, calculating mod inverse (extended-Euclid),  the cipher functions and a simple test.</p>
]]>
        <![CDATA[<p>Cracking RSA is actually very easy: just factorizing a very large number n = p * q (p, q are primes).   No, i'm kidding. It's very hard, as factorizing large numbers has no efficient algorithm (so far).  And it's actually what RSA's security comes from: you just cant easily (quickly) factorize a large number.</p>

<p>But what if the number is not so large?  There's an algorithm called <a href="http://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm">Pollard's rho heuristic</a>.  It's a <a href="http://en.wikipedia.org/wiki/Las_Vegas_algorithm">Las Vegas algorithm</a>, which means the algorithm may never terminate (what??) but if it does, it's 100% correct.  In practice, the rho algorithm normally  runs in O(n^0.25) for a composite n.  Here's my <a href="http://linuxfire.com.cn/~alecs/code/rho.hs">toy rho</a> implementation.</p>

<p>Just for fun, you can try cracking a <a href="http://acm.pku.edu.cn/JudgeOnline/problem?id=2447">small-scale RSA</a> or testing your code against <a href="http://acm.pku.edu.cn/JudgeOnline/problem?id=1811">this one</a>.  The online judge has no haskell or python support, i instead used java for its <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html">BigInteger class</a>.  To avoid rho running into an infinite loop, you might do some extra work (primality test, steps limit, random iterate function, etc.). Java BigInteger has provided the isProbablePrime function.  To implement one, you can use the <a href="http://en.wikipedia.org/wiki/Miller-Rabin_primality_test">Rabin-Miller algorithm</a>. It's a <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo algorithm</a>, which means it may not be 100% correct but the more time you run it, the more correct it is.</p>

<p>To have more fun, I encrypted the src code for the above two problems: <a href="http://linuxfire.com.cn/~alecs/code/2447poj.secret.txt">crack rsa</a> and <a href="http://linuxfire.com.cn/~alecs/code/1811poj.secret.txt">prime test</a>.  Though the keys in the original problem are less than 2^64, to make it a little harder for you, i used a slightly larger key (2^91 ~ 2^92).  Try deciphering the secret code, given the public key as (5, 3136682460441793638416097209). :^)</p>

<p>PS, for algorithms, please never forget to refer to the book <a href="http://en.wikipedia.org/wiki/Introduction_to_Algorithms">CLRS</a>. Just FYI, the R in CLRS is also the R in RSA. =)  Chap 31 has wonderful materials about various number theory algorithms.</p>
]]>
    </content>
</entry>

<entry>
    <title>Bug or Feature?</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/07/bug-or-feature.html" />
    <id>tag:linuxfire.com.cn,2008:/mt4blog//1.61</id>

    <published>2008-07-16T02:38:55Z</published>
    <updated>2008-10-10T03:54:36Z</updated>

    <summary>For years, as my fans may^Wshould know, i&apos;ve been using the fetchmail (POP3) + procmail (filter) + mutt (sucks less) + msmtp (eSMTP) tool chain for emailing. And yes, i use gmail. All is very convenient. For the SMTP part,...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Tools" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>For years, as my fans may^Wshould know, i've been using the <a href="http://fetchmail.berlios.de/">fetchmail</a> (POP3) + <a href="http://www.procmail.org/">procmail</a> (filter) + <a href="http://www.mutt.org/">mutt</a> (sucks less) + <a href="http://msmtp.sourceforge.net/">msmtp</a> (eSMTP) tool chain for emailing.  And yes, i use gmail.  All is very convenient. For the SMTP part, gmail automatically stores any mail you sent in the 'Sent' folder. As for POP3,  it can archive any mail you fetched (you can safely specify 'delete' on the client side). All these are very user-friendly and sweet.</p>

<p>But recently i just found that you cant get (via pop3) mails sent by yourself. This is really annoying for mailing lists (yes, i want to see my mails in the lists).  And it turns out that <a href="http://mail.google.com/support/bin/answer.py?answer=76163">it's a feature, not a bug</a>. Gmail smartly thinks it's a duplicate (ie. same message-id) and ignores it. One workaround is to enable <a href="http://mail.google.com/support/bin/answer.py?hl=en-uk&amp;answer=13291">'recent mode'</a> but that's really awkward. Another option is to use IMAP.</p>
]]>
        <![CDATA[<p>Because gmail's POP3 worked so well for me, especially its 'archive' feature is good for backup, i really wouldnt need IMAP, if not for this 'smart' dup-checking problem of pop3.  So i just changed my fetchmailrc to use IMAP (very easy, just some s/pop/imap/, s/995/993/) to fetch my mails. I can actually get the mails sent by myself then but there's another new problem: gmail's IMAP mistakenly encoded From:/To: address.  <a href="http://dev.mutt.org/trac/ticket/2997">It's a bug, not a feature</a>. Not fetchmail's, not mutt's, it's just gmail's bug.</p>

<p>And the bug is triggered by fetching with <a href="http://osdir.com/ml/mail.imap.general/2007-12/msg00014.html">advanced parameters</a> (ie. BODY.PEEK).  fetchmail detects server imap version on-the-fly and if server's advanced (ie.  IMAP4rev1), it will <a href="http://src.opensolaris.org/source/xref/sfw/usr/src/cmd/fetchmail/fetchmail-6.3.8/imap.c">issue BODY.PEEK</a> (around line 1094). And i dunno of any exposed options/interfaces for users to change it. We may patch fetchmail or mutt to cope with this problem. But we should not, as it's not a bug of fetchmail's or mutt's <em>at all</em>, it's totally fault of gmail's buggy imap implementation.</p>

<p>The workaround is to use a 'simple' (not so advanced) imap fetcher to avoid gmail triggering this bug.  <a href="http://pyropus.ca/software/getmail/">getmail</a> fits well.  It's simple. It 'works' well <a href="http://pyropus.ca/software/getmail/faq.html#faq-integrating-procmail">with procmail</a>. It can be used as a drop-in replacement of fetchmail. And the configuration is also <a href="http://pyropus.ca/software/getmail/configuration.html">cleaner</a>.</p>

<p>As an amusement, i think we can remove all the words written so far and just write one sentence:</p>

<blockquote>
  <p>Dont bother, use gmail webly.</p>
</blockquote>
]]>
    </content>
</entry>

<entry>
    <title>Project Euler</title>
    <link rel="alternate" type="text/html" href="http://linuxfire.com.cn:81/~alecs/mt4blog/2008/06/project-euler.html" />
    <id>tag:linuxfire.com.cn,2008:/mt4blog//1.60</id>

    <published>2008-06-12T16:42:12Z</published>
    <updated>2008-11-17T08:34:23Z</updated>

    <summary>I came across Projuect Euler last year when i wanted to find some exercise to learn Haskell. And it&apos;s fun. There&apos;s about one new problem in one week. The puzzles are math-based but you still have to program. The problems...</summary>
    <author>
        <name>Alecs</name>
        <uri>http://linuxfire.com.cn/~alecs/</uri>
    </author>
    
        <category term="Algorithm" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Haskell" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Math" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://linuxfire.com.cn:81/~alecs/mt4blog/">
        <![CDATA[<p>I came across <a href="http://projecteuler.net">Projuect Euler</a> last year when i wanted to find some exercise to learn <a href="http://haskell.org">Haskell</a>.  And it's fun.</p>

<p>There's about one new problem in one week.  The puzzles are math-based but you still have to program.  <a href="http://projecteuler.net/index.php?section=problems">The problems</a> are in lots of branches of maths: number theory, combinatorics, graph theory, game theory,  geometry, probability, statistics, etc. and in a broad range of difficulties: easy, hard, tricky and tedious ones all over.</p>
]]>
        <![CDATA[<p>Trying to attack these interesting problems help you learn some new maths,  broaden your mind and sharpen your coding skills.  My current <a href="http://projecteuler.net/index.php?section=scores">rating</a> is "94% genius, having solved 185 out of 197 problems."  I mainly use haskell (pure functional), occasionally python (memo decorator),  sometimes C/C++ (brute force) and perl/lua/shell (in the mood for scripting). Besides, here are some tools and languages that might be useful as well (not only for project euler):</p>

<ol>
<li><p>Heavy math tools: three big M: <a href="http://www.mathworks.com/">Matlab</a>, <a href="http://www.wolfram.com/">Mathematica</a>, <a href="http://www.maplesoft.com/">Maple</a>.</p></li>
<li><p>Alternative (specific) tools: <a href="http://pari.math.u-bordeaux.fr/">PARI-GP</a> for number theory, <a href="http://www.gnu.org/software/glpk/">GLPK</a> for linear programming / integer constraint programming, <a href="http://maxima.sourceforge.net/">Maxima</a> for symbolic processing, <a href="http://www.gap-system.org/">GAP</a> for group theory.</p></li>
<li><p>Good-at-math langs: <a href="http://aplteam2.com/aplwiki/moin.cgi/FrontPage">APL</a>, <a href="http://www.jsoftware.com/">J</a>, <a href="http://www.kx.com/">K</a>.</p></li>
<li><p>Library: <a href="http://gmplib.org/">gmp</a> for large arbitrary-precision integer calculations (for languages that dont have 'bignum' builtin)</p></li>
</ol>

<p>Once you has solved a problem correctly, you can view the corresponding forum thread, where you can see how others attacked the problem and share your own smartness.  Just dont miss it.</p>

<p>Enjoy and have fun.</p>
]]>
    </content>
</entry>

</feed>
