Solving Newton’s Law of Cooling Using Maxima

May 2, 2012

In my previous post, I introduced setting up Maxima, a powerful symbolic computation system, to work with Emacs. This post provides a real example of using Maxima.

I was motivated by this interesting post, introducing the use of Newton’s Law of Cooling in the ranking algorithm of Reddit.  This post (in Chinese) explains more about the derivation of Newton’s Law. I believe the author is good at calculus.  But how if you forgot calculus?  In this case, Maxima would save you!  The following figure illustrates how I use Maxima to derive the Law:


My Common Lisp Programming Environment

October 7, 2011

Just for fun, I want to try Common Lisp. (I’ve been using Scheme when I was a student.)

As an ancient language, CL has many implementations. Following Wikipedia, I chose SBCL, a descendent of CMUCL.

It it just like Eclipse for Java, Emacs + SLIME is powerful for Common Lisp (or Scheme). Auto-complete and other stuff are so well supported.

dpans2texi enables us to get help about the word under cursor by simply typing ‘C-h S’.


Hanoi in Emacs Lisp

September 25, 2011

Just for fun.

(defun hanoi (ndisks source dest)
  (cond ((= ndisks 1)
	 (format "%d -> %d, " source dest))
	(t
	 (let ((rest-pole (rest-pole source dest))
	       (top-disks (- ndisks 1)))
	   (concat (hanoi top-disks source rest-pole)
		   (format "%d -> %d, " source dest)
		   (hanoi top-disks rest-pole dest))))))

(defun rest-pole (source dest)
  (- 6 source dest))

(hanoi 5 1 3)

安装 Emacs 24 咯!

September 14, 2011

Emacs 24 已经可以开始使用了。它的 Mac OS X 版本支持 fullscreen mode。在 Mac OS X 下可以通过 Homebrew 来安装。方法如下:

brew update
brew install emacs --cocoa --use-git-head --HEAD
mv /usr/local/Cellar/emacs/HEAD/Emacs.app /Applications/Emacs24.app

如果要全屏,可以M-x ns-toggle-fullscreen。其中ns表示 NextSTEP,也就是 Apple Cocoa 的前身。

如果要配置半透明效果(Emacs 23也可以),可以采用 EmacsWiki 上建议的这段代码

 (eval-when-compile (require 'cl))
 (defun toggle-transparency ()
   (interactive)
   (if (/=
        (cadr (frame-parameter nil 'alpha))
        100)
       (set-frame-parameter nil 'alpha '(100 100))
     (set-frame-parameter nil 'alpha '(95 50))))
 (global-set-key (kbd "C-c t") 'toggle-transparency)

如果想用 Emacs 看 Google Maps,可以用 Julien Danjou 写的 google-maps-mode。下载方式如下:

cd ~/.emacs.d
git clone git://git.naquadah.org/google-maps.git

然后配置如下:

(add-to-list 'load-path "~/.emacs.d/google-maps")
(require 'google-maps)

下面附上我的 Mac OS X Lion 上,Emacs 24 在窗口为当前窗口和不是当前窗口时,不同的半透明效果图:


Using GNU Emacs on MacBook (Pro)

August 3, 2011

You can download pre-compiled GNU Emacs for Mac OS X from http://emacsformacosx.com.

In order to use the Command key as Emacs’s meta key, and Option key as Emacs’ control key, add following two lines to your ~/.emacs file:

(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'control)

Emacs Viewing and Editing Chinese

August 3, 2010

I have two versions of Emacs on my iMac (SnowLeopard): Aquamacs and Emacs for Mac OS X. When I open a Chinese text file, Aquamacs can display it, but Emacs for Mac OS X cannot. Fortunately, Google brought me to an old post about editing and viewing Chinese in Emacs/Cygwin, and the method does work for Emacs for Mac OS X.

The code snippet that should be inserted into your .emacs file.

(if (not (member '("-*-courier new-normal-r-*-*-13-*-*-*-c-*-fontset-chinese"
   . "fontset-chinese") fontset-alias-alist))
    (progn
      (create-fontset-from-fontset-spec
       "-*-courier new-normal-r-*-*-13-*-*-*-c-*-fontset-chinese,
      chinese-gb2312:-*-MS Song-normal-r-*-*-16-*-*-*-c-*-gb2312*-*,
      chinese-big5-1:-*-MingLiU-normal-r-*-*-16-*-*-*-c-*-big5*-*,
      chinese-big5-2:-*-MingLiU-normal-r-*-*-16-*-*-*-c-*-big5*-*" t)

      (setq default-frame-alist
            (append
             '((font . "fontset-chinese"))
             default-frame-alist))
      )
  )

Above method is not enough to GNU Emacs for Windows.  I added the following encoding settings (copied from this post):

(set-language-environment 'Chinese-GB)
(set-keyboard-coding-system 'euc-cn)
(set-clipboard-coding-system 'euc-cn)
(set-terminal-coding-system 'euc-cn)
(set-buffer-file-coding-system 'euc-cn)
(set-selection-coding-system 'euc-cn)
(modify-coding-system-alist 'process "*" 'euc-cn)
(setq default-process-coding-system
            '(euc-cn . euc-cn))
(setq-default pathname-coding-system 'euc-cn)

Follow

Get every new post delivered to your Inbox.

Join 31 other followers