顯示具有 Linux/Ubuntu 標籤的文章。 顯示所有文章
顯示具有 Linux/Ubuntu 標籤的文章。 顯示所有文章

2011-12-27

Emacs server per workspace (GNU Screen)

I am a heavy user of GNU screen and Emacs at work and home. In the past, I created different GNU Screen instances for different projects and only one instance of Emacs server in one machine. For instance, you are aked to fix bugs in threee code branches and some fixes can't go into certain branches, I need to be very careful when I edit and switch buffers because only once emacs server out there.



What I really need to have setup like this,



Now, whenever you edit or switch files in a GNU screen by emacsclient, you can sit back and relax for a while. But, the problem is how do I make this a bit automatic? If you need to execute 'emacs --daemon=serverN' for every created GNU Screen, that will be very troublesome.
Here is what I have done to make this happen,



Now, when you instantiate GNU Screen by 'ws_XXX' aliases, an Emacs server identified by 'XXX' is created for you. And then you can use 'et' to edit a file in the proper Emacs server.

The only thing I don't like is that I am compelled to use another alias 'kill-emacs' to kill Emacs server. I often 'pkill' to kill process, but this will kill all Emacs servers in the same machine which is absolutely not the behavior I want.

The last thing to do is to patch the source code of emacsclient. In my experiment, emacsclient in the latest stable release (23.3b) doesn't pass correct argument for Emacs to start its daemon mode. So, I made minor changes to make it right.



After recompile and install, you can start using these two power tools in this way as I do.

2011-05-27

Load machine-dependent bash setting

I own several computers and each is running different OS on it. We all know that maintaining different settings for different OS is very cumbersome. A simple solution for this is to separate common settings and machine-dependent settings into different files like this,
MNAME=`uname -s`
MBASHRC=$HOME/Settings/bashrc.${MNAME,,}
if [ -f $MBASHRC ]; then
    echo "==> loading $MBASHRC"
    . $MBASHRC
fi
In this way, all you need to do is to write your machine-dependent settings in the bashrc.darwin or bashrc.linux.

MacOSX-like open command in Ubuntu and Windows/Cygwin.

I always find 'open' command in MacOSX is very useful for people always hanging around in the Terminal. To get the similar behavior in Ubuntu or other Linux system, we can create an alias such as,

2011-02-10

Two X11 bitmap fonts for Mac

I came across these two X11 bitmap fonts, peep and neep-alt. I love what they looks in Linux, but their original sites don't provide MacOS counterparts. I used FontForge to generate their Mac dfont versions.

NeepAltBold
NeepAltMedium
NeepBold
NeepMedium
peepMedium

2009-07-01

Enlarge a VirtualBox image file

VirtualBox is a great free software that helps you get different OS in the same machine without messing up your main working environment. If you haven't tried it, a new version 3.0.0 is just released. My working environment isn't special, Ubuntu 9.04 as my main system and VirtualBox installed to satisfy the Windows-must situations. So, a 10GB media was created in my VirtualBox to install WindowsXP and some applications. It was enough until I started to begin developing S60/Qt programs. The S60 and Qt for S60 SDK takes roughly 2-3GB space. I figured Windows XP is kinda hungry monster that eats my space rapidly. I have to enlarge this device. Currently, VirtuanlBox doesn't have this feature implemented and don't know when it will support this. After hours of searching answers, I figured using TrueImage's cloning disk looks like a pretty simple solution and it works like a charm.
  1. Create a brand new and bigger media (10GB++++ at this time, of course) at VirtualBox.
  2. Attach this bigger media to the WindowsXP device so that this device has two medias, an old 10GB media and a new 10GB-more media.
  3. Start WindowsXP device and install Acronis TrueImage. Trial version should be enough.
  4. In TrueImage, clone old 10GB disk to new 10GB-more disk. After cloning, TrueImage should ask you to restart system. Do as what it suggests.

2009-04-30

開啟PCF字型的使用

在Ubuntu的預設值中,fontconfig是不會將PCF字型納入。但是有時候,在小字型時,PCF字型實在是比較清晰。如果,需要Fontconfig將PCF字型加入,就必須 sudo dpkg-reconfigure fontconfig-config # choose Autohinter, Automatic and Yes sudo dpkg-reconfigure fontconfig

2008-10-01

GNOME開發文件

在寫Maemo程式時,一直苦於GNOME環境沒有像Qt的assistant一樣方便的程式庫文件程式。今天,無意間發現居然有devhelp這玩意。顧名思義,這東西是寫GNOME平台程式的Help程式。他的功用和assistant一樣,將程式庫的說明文件整理好,包在一個程式中,方便使用者查詢。

2008-09-30

Integrating applications into Maemo Application Framework

Maemo .desktop file
  1. To make an application visible in maemo Task navigator, a desktop file is needed for the application.
  2. /usr/share/applications/hildon/[application].desktop
  3. Use af-sb-init.sh restart to restart GUI again in order for the new entry to be seen in the task navigator.
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=Example libOSSO <=== the name of the application Exec=/usr/bin/example_libosso ;; <== binary to launch X-Osso-Service=org.maemo.example_libosso ;; <=== D-BUS service name Icon=qgn_list_gene_default_app MimeType=application/x-example;
D-Bus Service File
  • Only one instance of a D-BUS service can be run simultaneously, guaranteeing that each application is running only once.
  • /usr/share/dbus-1/services/[application].service
  • use af-sb-init.sh restart before D-BUS daemon recognizes it.

[D-BUS Service]
Name=org.maemo.example_libosso # D-Bus service name (has to be unique)
Exec=/usr/bin/example_libosso # binary to launch

LibOSSO Library

Maemo initialization

All maemo applications need to be initialized correctly, or they will not work as expected.

Initializing application is performed with osso_initialize() function.
  1. Connects to D-Bus session bus and system bus.
  2. Should only be called once in the application.
  3. The structure of type osso_context_t type that is returned should be stored for later use.


osso_context_t* /* shoud be stored for later use */
osso_initialize(const gchar *application,/* D-BUS name */
const gchar* version, /* application version */
gboolean activation, /* TURE: application binary has been launched by the D-Bus
GMainContext *context /* GLib main-loop context to connect to */
)

osso_deinitialize() should be called to close the message bus connection and free all the memory allocated by the library.
void osso_deinitialize(osso_context_t* osso);

Remote Process Messages

System wide messages in maemo platform are handled with D-BUS system messaging, which is a Remote Process Communication (RPC) method.

osso_rpc_set_cb_f(...);
gint dbus_message_handler(const gchar* interface,
const gchar* method,
GArray* arguments,
gpointer data,
sso_rpc_t* retval);
osso_rpc_run(osso_context,
const gchar* service,
const gchar* object,
const gchar* interface,
const gchar* message,
...);

The receiving application does not even need to be started: D-BUS can automatically start the application based on its service file, and then pass the message to it!.
Hardware State Messages

Maemo applications can connect to listen the system D-BUS messages, like "battery low" and "shutdown".When these messages are received, the application may want to ask the user to save files that are open, or react however wanted.

void hw_event_handler(osso_hw_state_t* state, gpointer data);
state->memory_low_ind
state->system_inactivity_ind
osso_hw_set_event_cb( appdata->osso_context, NULL, hw_event_handler, (gpointer)appdata );

These hardware events are not sent to the SDK, testing them is only possible in maemo device.
System Exit Message


void exit_event_handler(gboolean die_now, goiinter data);
osso_application_set_exit_cb(appdata->osso_context,
exit_event_handler,
(gpointer)appdata);

whenever the system needs to close an application for any reason, exit_event_handler will be performed gracefully.

Information on how to implement state saving can be found in LibOSSO API document.

2008-09-29

Install Maemo Dialo Development Platform 4.1.1

The installation of the Maemo Development Platform contains: Scratchbox,Maemo SDK and Nokia binaries. These three steps can be automated by the script written by Nokia or the community.

Install Scratchbox
Use,
$ wget http://repository.maemo.org/stable/diablo/maemo-scratchbox-install_4.1.1.sh
$ chmod a+x ./maemo-scratchbox-install_4.1.1.sh
$ sudo ./maemo-scratchbox-install_4.1.1.sh
If the script comlains something about vdso_enabled or min_addr, insert the following settings into your /etc/sysctl.conf. Like,
vm.vdso_enabled = 0
vm.mmap_min_addr = 4096
net.ipv4.ip_local_port_range = 1024 65535

Then, execute,
sudo sysctl -p

Install Maemo SDK
Use,

$ wget http://repository.maemo.org/stable/diablo/maemo-sdk-install_4.1.1.sh
$ chmod u+x maemo-sdk-install_4.1.1.sh
$ sudo ./maemo-sdk-install_4.1.1.sh

Install Nokia Binaries
Use,
$ wget http://repository.maemo.org/stable/diablo/maemo-sdk-nokia-binaries_4.1.1.sh
$ chmod +x maemo-sdk-nokia-binaries_4.1.1.sh
$ sh maemo-sdk-nokia-binaries_4.1.1.sh
Then, log into Scratchbox system, execute,
$ /scratchbox/login
[sbox-DIABLO_ARMEL: ~] > fakeroot apt-get install maemo-explicit

Install Virtual X11 server (XEPHYR)
Before we can run applications from SDK, the Xephyr X11 Server has to be installed first.
$ sudo apt-get install xserver-xephyr

2008-09-28

Emacsclient in Scratchbox

I am using Emacs to program both at work and home. When I found I can't use Emacsclient inside ScratchBox, although, it is claimed OK in the documentation, I felt a bit surprised. The error reads,
[sbox-DIABLO_ARMEL: /tmp] > emacsclient emacsclient-1.c
Can't stat /tmp/esrv1000-yenliang-laptop
[sbox-DIABLO_ARMEL: /tmp] > ls /tmp/esrv1000-yenliang-laptop
ls: /tmp/esrv1000-yenliang-laptop: No such file or directory


Obviously, the socket file /tmp/esrv1000-yenliang-laptop is not created by Emacs server. I looked into the source code of Emacsclient shipped from Emacs and found that the socket file it is looking for is /tmp/emacs1000/server as indicated by the code below.

sprintf(socket_name, "/tmp/emacs%d/%s",
(int)geteuid(), server_name);


But, the code in ScratchBox version is,

sprintf(server.sun_path, "/tmp/eserv%d-%s",
(int)geteuid(), system_name);

I think if I change the socket file path above to match the one used by Emacs server and compiled a new emacsclient, it should work. And it does work.



The screenshot above says it works like a charm, though, the Emacs started the server is version 22.2, not CVS version. The emacsclient fails to connet to the server created by CVS version. My guess is that the CVS version returns the different ID as the client initializes the connection.

Another way you can try is to create a symbolic link at the home directory of the host pointing to the home directory in the ScratchBox system.
ln -s /scratchbox/users/$USER/home/$USER sbox

2008-09-24

HelloWorld example in Hildon Desktop

After a long installation of ScratchBox and Hildon SDK, everyone would like to see how Hildon Desktop looks like. The first thing we should do is to start a virtual X server with a display number different than the host, here we use :2.
[yenlaingl@yenliangl-laptop:~] Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -extension Composite
The second thing to do is to redirect the DISPLAY of all X clients in sbox to the :2
export DISPLAY=:2

The third thing we should do is to start up the Hildon Application Framework.
[sbox-DIABLO_ARMEL: ~/workspace]: af-sb-init.sh start

You should see the Hildon Desktop shown inside the window of the Xephyr, such as,



And now, time to invoke the HelloWorld example.
[sbox-DIABLO_ARMEL: ~/workspace]: run-standalone.sh ./hello



Cool! In fact, I've had a dilemma choosing OpenMoko or Nokia Internet Tablet to be my off-work hobby. I did try to install OpenMoko SDK, but honestly, it's not quite intuitive and hard to make it work. Inversely, Diablo is very easy to install and get started.

2008-09-22

This mind map briefly describes the important widgets that can be used to create applications in Nokia internet tablet. It is drawn by FreeMind by the way.

2008-09-16

Record your moves on the screen

Use wink to record your moves on the screen

http://debugmode.com/wink/

Linux version is available, but not up-to-date.

Use enscript to generate pretty HTML and PostScript output

Create HTML output with TOC(Table of content) and syntax highlighting of Java files.

enscript -E --color -Whtml --toc -pNotepad.html *.java
Generate PoscScript output with TOC and syntax highlighting of Java files.
enscript -E --color -WPostScript --toc -pNotePad.ps *.java

If you want to get these files printed out from printer, you'd better remove the --color from above.

BusyBox: The Swiss Army Knife of Embedded Linux

BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides replacements for most of the utilities you
usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox
generally have fewer options than their full-featured GNU cousins; however,
the options that are included provide the expected functionality and behave
very much like their GNU counterparts. BusyBox provides a fairly complete
environment for any small or embedded system.

BusyBox

Use stat to view inode information

user@system:~$ stat /etc/passwd
File: `/etc/passwd'
Size: 1347 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 209619 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2007-11-23 06:30:49.199768116 +0200
Modify: 2007-11-17 21:27:02.271803959 +0200
Change: 2007-11-17 21:27:02.771832454 +0200

2006-09-08

My desktop snapshot



This is the screen shot of my Linux machine. The window manager I use is Ion3 which is very fantastic.

Query the installed patches

PlatformCommand and Description
Linux platform (Assuming the IT had used RPM installation process)Installed Packages and version
rpmquery -a
Kernerl version
uname -a
CPU/MEM information
cat /proc/cpuinfo
cat /proc/meminfo
SUN platformInstalled Packages and version
showrev -a
Kernel version
uname -a
CPU/MEM information
/usr/platform/sun4u/sbin/prtdiag -v
HP platformInstalled Packages and version
/usr/sbin/swlist
Kernel version
uname -a
CPU/MEM information
CPU: uname -r
MEM: ?????
AIX platformInstalled Packages and version
/bin/lslpp -L all
Kernel version
/bin/oslevel
CPU/MEM information
/usr/sbin/prtconf