jianghong

Archive for the ‘Programming’ Category

Emacs smart split for programmers

In Programming on March 13, 2009 at 2:59 am
I spend most of my conscious hours in front of Emacs in a terminal window these days, and I share my configuration across all my computers. At work I have a huge monitor, so I split the emacs frame into 3 side-by-side 80-column windows. At home I have a smaller screen with room only enough for two windows. To share the same configuration file, I use the following snippet:

(defun smart-split ()
  "Split the frame into 80-column sub-windows, and make sure no window has
   fewer than 80 columns."
  (interactive)
  (defun smart-split-helper (w)
    "Helper function to split a given window into two, the first of which has 
     80 columns."
    (if (> (window-width w) (* 2 81))
    (let ((w2 (split-window w 82 t)))
      (smart-split-helper w2))))
  (smart-split-helper nil))

(smart-split)
The smart-split function split the emacs frame into a maximum number of 80-column windows. A very portable solution.

本文由脚本自动转载自http://blog.hjiang.net

JSON++: A JSON parser for C++

In Programming on March 9, 2009 at 5:10 am

LINQ++: An embeded DSL for C++

In Programming on October 20, 2008 at 6:44 am
LINQ have been the new hotness in Microsoft’s .Net platform. Well, you can have the same syntactic sugar in C++ without writing a new compiler. I wrote a small library (just a short header file right now) that can do some interesting things. (source available at github) The following snippets from the companion unit test shows a few:

// Count the number of people older than 30
cout << from(guests)
        .where(&_1 ->* &Person::age > 30)
        .count()

// combine the people older than 30 with the person with name
// "joe" into one table.
DataSet<vector<Person> > results =
        insert(
                from(guests)
                .where(&_1 ->* &Person::age > 30))
        .into(
                from(guests)
                .where(&_1 ->* &Person::name == "joe"));

// select the age column from the previous table.
shared_ptr<vector<int> > ages = results
                                .select<int>(&_1 ->* &Person::age)
                                .get();
It should work with all STL-compatible sequence containers and requires the boost library. You can chain the clauses to form complicated queries.

I wrote it up on the shuttle from work to home. Hopefully I can find some time to polish it up and make it actually useful.

本文由脚本自动转载自http://blog.hjiang.net

Follow

Get every new post delivered to your Inbox.