Hacking by Walkingice

2011/09/14

tmux split window in current directory

I use tmux to instead of gnu-screen due to tmux supports vertical window splitting.

There are many common question such as 'How to create a new window in the current directory'. Here are some simple how-to, inspired by tmux FAQ.



1. Preparing - set environment variable by PS1 in shell
add this line to your .bashrc
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '


How it works?


$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)
The previous half part makes the magic, #I indicates the index of each displays. In display 1, it saves current directory ($PWD) into environment variable $TMUXPWD_1, corresponding to $TMUXPWD_2, $TMUXPWD_3 ...etc.

Just type 'printenv |grep TMUXPWD' and you will know everything.


${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Well, this is my own prompt (such as walkingice@my_laptop$ ), you can keep your own settings by 'cat ~/.bashrc |grep PS1'


2. Create new window in current directory
Follow the common FAQ, add this line to your .tmux.conf
bind-key c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
3. Split window in current directory
Since we did the magic to PS1, why don't we keep using it? Add these two lines to your .tmux.conf
bind-key h run-shell 'tmux splitw -v "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
bind-key v run-shell 'tmux splitw -h "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
Caution: I prefer Ctrl-a h to split horizontal window(splitw -v). In other words, when I click Ctrl-a h, I am saying "Hey, give me a horizontal line". I think it make more sense than tmux original key binding.

2011/06/03

To change default window manager

This is a quick note for myself to avoid bother [Kanru] again and again.

Why

I use compiz in my Debian a lot. The default window manager in Gnome2 is metacity. I would not like to type this command once I reboot.
$ compiz ccp --indirect-rendering --replace

How

Tell gnome to use compiz as default windowmanager
  • open gconf-editor, navigate to /desktop/gnome/session/required_components
  • change value of windowmanager to compiz
  • logout and login, here you go
If you want to specify some runtime parameters to compiz like me ( assign ccp --indirect-rendering), just to
  • edit /usr/share/applications/compiz.desktop
  • change the value of Exec to Exec=compiz ccp --indirect-rendering

I have tried edit ~/.gnomerc but it does not work.

    2010/10/06

    Ubuntu wifi connection randomly disconnect

    I am using Ubuntu Linux 10.04 but had this annoying problem since Ubuntu 9.04. When I am at some place and use particular Access Point, the Wifi connection on my laptop randomly disconnect. Although I reboot laptop, reconnect to wifi, it still disconnect in less than one minute.

    Image that, you open browser and enter gmail, click first unread mail then you lose connection. That repeat 100 times in one hour. Gosh !

    Jserv told me the Wifi driver mode N is not so stable as my imagination. Follow his suggestion I turned off the N mode and it does not annoy me anymore. (at least now)

    Here is the workaround
    # unload iwlagn
    $ sudo rmmod iwlagn
    # load again with disable options
    $ sudo modprobe iwlagn 11n_disable50=1 11n_disable=1
    
    

    If it works, you can add it to /etc/modprobe.d. Once system modprobe this module, these options will be used.
    $ echo "options iwlagn 11n_disable50=1 11n_disable=1" > /etc/modprobe.d/iwlagn.conf
    

    There is another problem. If I suspend my laptop and put it into my backpack. Sometimes the hardware wifi switch will be turned off. If I resume the laptop while the wifi switch turned off, I can not turn it on anymore.

    You can try this command, it works for me.
    $ sudo rfkill block all
    $ sudo rfkill unblock all
    

    2010/09/04

    NotifyOSD Dispute

    You might googled this article with the same reason I had. Days ago I updated my Ubuntu9.04 to Ubuntu10.04 and really enjoy it. There are sort of things annoy me - the notification at the corner displays TOO LONG.

    To put the question simply: You  cannot change the displaying period of notification.

    I use Rhythmbox to listen music, the new version of Rhythmbox at Ubuntu10.04 is sweet because it displays a notification once it finish playing a song and starting next one. This feature is very like Amarok just did, I like it excepts the displaying period is too long.

    Most of guys like to coding and listening music at the same time. When the notification coming, you say "Ok, I got it" and back to your original work. 10 seconds passed then the notification disappears, and grab your attention AGAIN : "Hey, I am leaving, bye bye"

    Gosh!

    It is very like SMS and Phone Call. When you get a SMS message, your mobile just beep for one second. But phone calling keeps shouting until 30 seconds pass or pick up your phone.

    Oh, you cannot even close the notification by clicking it.

    According to my experience of using Amarok, a user can tweak the period to fit his own requirement. But I cannot find any option in Rhythmbox. I guess the main developers of Rhythmbox are too busy to do that, send a patch to them might be a good idea.

    Building Rhythmbox is pretty easy, just checkout the source code then type
      ./autogen.sh --enable-libnotify --prefix=/tmp/mybuild # I want to install to /tmp/mybuild
      make
      make install
    Actually, the notification mechanism was implemented by plug-in. See rhythmbox/plugins/status-icon/rb-status-icon-plugin.c

      static void do_notify (RBStatusIconPlugin *plugin,
                 guint timeout,
                 const char *primary,
                 const char *secondary,
                 GdkPixbuf *pixbuf,
                 gboolean show_action) 
      {
                .....
                notify_notification_set_timeout (plugin->priv->notification, timeout);
               ....... 
      }
    The function makes the notification and it also set timeout. But, whatever I did to the variables timeout, the notification always displays 10 seconds.

    I doubt there is a bug at libnotify so I checkout the source. the function notify_notification_show at libnotify/notification.c did send an notification with expect timeout to dbus. The command notify-send did as well. Actually, even if you write a small script to send notification request with expect timeout to dbus, you still got 10 seconds notification.

      #!/usr/bin/env python
      import dbus
      item = ('org.freedesktop.Notifications')
      path = ('/org/freedesktop/Notifications')
      interface = ('org.freedesktop.Notifications')
      time = 2000 # 2second
      bus = dbus.SessionBus()
      notif = bus.get_object(item, path)
      notify = dbus.Interface(notif, interface)
      notify.Notify('blah', 0, '', 'Ouch', '2 seconds,please', '', '', time)

    Rhythmbox is ok, libnotify is ok. What thing is go wrong? Take a look of the source code of NotifyOSD. See notify-osd-0.9.29/src/default.c

      /* these values are interpreted as milliseconds-measurements and do comply to  * the visual guide for jaunty-notifications */ 
      #define DEFAULT_FADE_IN_TIMEOUT      250 
      #define DEFAULT_FADE_OUT_TIMEOUT     1000 
      #define DEFAULT_ON_SCREEN_TIMEOUT    10000 
       
      ...... 
              property_on_screen_timeout = g_param_spec_int (
                                      "on-screen-timeout",
                                      "on-screen-timeout",
                                      "Timeout for bubble on screen in milliseconds",
                                      0,
                                      10000,
                                      DEFAULT_ON_SCREEN_TIMEOUT,
                                      G_PARAM_CONSTRUCT |
                                      G_PARAM_READWRITE |
                                      G_PARAM_STATIC_STRINGS);
              g_object_class_install_property (gobject_class,
                                               PROP_ON_SCREEN_TIMEOUT,
                                               property_on_screen_timeout);
       

    And then see function stack_notify_handler at stack.c

            if (bubble_get_id (bubble) == FORCED_SHUTDOWN_THRESHOLD)
                    g_timeout_add (defaults_get_on_screen_timeout (self->defaults),
                                   _arm_forced_quit,
                                   (gpointer) self);


    As you see, NotifyOSD defines a default on-screen-time to 10 seconds and use it at handling notification. But Why? take a look of this [design specification for Notify OSD]. It said "All other hints, and all other parameters (including expire_timeout) should be ignored."

    Well, there is a huge discussion at [Launchpad Bug Tracker (#390508)]. I read the whole thread. Ouch, thats pretty tough for me, a non-native English speaker. (But I still did, now you know how much I care about this issue.) Matthew Paul Thomas [said]

          the timeout parameter is for application developers, not end users. We think we can set more consistent and reliable durations for users automatically than diverse application developers ever could manually.

    That really pissed off many developers :-P.

    First, why 10 seconds? Why not 9.5 second, 10.5 second or 3.14159265358 seconds? Does they really did a research and find THE BEST NUMBER?(I do believe it should be 42) We don't know, we just got the answer: 10.

    Ok, 10 is fine. Displays a notification in 10 seconds by default is fine. But why can't an end user change 10 seconds to another number? Is that a bad idea? That is not for developer, that is for end user.

    Those developers went to there and complained because they really care about what they are using. Many end users don't complain because they don't know how to complain but not they think the design is good. Every developer who ever designed a UI agrees that making a good interface is so hard therefore making mistake is just so easy.
    Providing a good default settings and a option to customize is always a better way.

    Unfortunately, Ubuntu has its right to set period to any seconds it want because that is Open Source. I agree but disappointed. John Lee mentioned [How to use notification-daemon to instead of notify osd], I will replace it and say bye bye to NotifyOSD. Moreover, you can use [patched NotifyOSD]

    2010/06/10

    MotionEvent on HTC Hero

    I have both of HTC Hero and Nexus One. Thanks God and HTC, finally Hero users got the Android Eclair update via OTA.

    Recently I found a weird behavior on HTC Hero and differs from my Nexus One.

    Here is the testing code

    public boolean onTouchEvent(MotionEvent event) {
    long now = android.os.SystemClock.uptimeMillis();
    android.util.Log.i("Ouch", "keep pressing:" + (now - event.getDownTime()));
    return false;
    }

    I just keep pressing the screen and see the log output which tells the pressing time in millisecond.

    Nexus One (Eclair)
    (just press and do not drag)
    I/Ouch (11979): keep pressing:2
    I/Ouch (11979): keep pressing:14
    I/Ouch (11979): keep pressing:43
    I/Ouch (11979): keep pressing:71
    I/Ouch (11979): keep pressing:98
    I/Ouch (11979): keep pressing:127
    I/Ouch (11979): keep pressing:154
    I/Ouch (11979): keep pressing:189
    I/Ouch (11979): keep pressing:214
    I/Ouch (11979): keep pressing:238
    I/Ouch (11979): keep pressing:265
    I/Ouch (11979): keep pressing:294
    I/Ouch (11979): keep pressing:324
    I/Ouch (11979): keep pressing:351
    I/Ouch (11979): keep pressing:380
    I/Ouch (11979): keep pressing:405
    I got 16 events in 0.4 seconds, that is well known event "Touch Event Flood".

    HTC Hero (Eclair)
    (just press, I do not drag)
    W/Rosie ( 152): mAddHtcWidgetByOtherActivity = false, mIsOpenSlideWhenLeaveLaunch = true
    I/Ouch ( 2149): keep pressing:4
    I/Ouch ( 2149): keep pressing:17
    I/Ouch ( 2149): keep pressing:26
    I/Ouch ( 2149): keep pressing:62
    I/Ouch ( 2149): keep pressing:245
    I/Ouch ( 2149): keep pressing:421
    I/Ouch ( 2149): keep pressing:817
    I/Ouch ( 2149): keep pressing:1671
    D/dalvikvm( 528): GC freed 1174 objects / 73000 bytes in 139ms
    (8 seconds left, I start moving my finger)
    I/Ouch ( 2149): keep pressing:8372
    I/Ouch ( 2149): keep pressing:8697
    I/Ouch ( 2149): keep pressing:8743
    I/Ouch ( 2149): keep pressing:8752
    D/dalvikvm( 135): GC freed 211 objects / 10464 bytes in 241ms

    In the first 1.6 seconds, I got 8 events. I still kept pressing the screen untle 8 seconds left. I started dragging and then got touch event as I expects.

    I guess Sense-UI of HTC Hero did some change to deal with touch event flood. It should be good thing but I guess that kicks someone's ass.

    2010/03/30

    Javadoc at Android

    * This article also post to 0xlab planet *
    I have a tiny, useless brain with slow frequency, 128 bytes L1 cache and 256K Ram. Therefore, I cannot remember everything while I am doing Java programming.

    Although you are not a nut like me, you might still need Java API documentation. Well, we could read the [online version], thats cool.

    But what if you are a poor guy cannot pay for network. You still have to work on the Bus, at Starbucks coffee, at toilet or on the bed.

    Luckily, you could generate offline documentation by command

    $make docs

    But I do not like droiddoc. I cannot explain why I dislike it.

    I like the original javadoc style, it is like although I had PS but I still love FF3 on FC. (bad example I know)

    I read article of [androidjavadoc] and prepared this [patch], you could generate your own old style offline java documentation.

    From bfe51b44ee6f6c1a989d34c96f9b0ea457731d80 Mon Sep 17 00:00:00 2001
    From: Julian Chu

    Date: Wed, 26 Aug 2009 12:19:36 +0800
    Subject: [PATCH] Create original javadoc

    Apply this patch and type in
    $make docs
    ---
    core/droiddoc.mk | 12 ++++--------
    1 files changed, 4 insertions(+), 8 deletions(-)

    diff --git a/core/droiddoc.mk b/core/droiddoc.mk
    index 30bd918..af4121e 100644
    --- a/core/droiddoc.mk
    +++ b/core/droiddoc.mk
    @@ -159,17 +159,13 @@ $(full_target): $(full_src_files) $(droiddoc_templates) $(droiddoc) $(html_dir_f
    -J-Xmx768m \
    -J-Djava.library.path=$(HOST_OUT_SHARED_LIBRARIES) \
    $(PRIVATE_PROFILING_OPTIONS) \
    - -quiet \
    - -doclet DroidDoc \
    - -docletpath $(PRIVATE_DOCLETPATH) \
    - -templatedir $(PRIVATE_CUSTOM_TEMPLATE_DIR) \
    - -templatedir $(PRIVATE_TEMPLATE_DIR) \
    - $(PRIVATE_DROIDDOC_HTML_DIR) \
    + -overview $(TOP)/frameworks/base/core/java/overview.html \
    + -splitindex \
    + -use \
    + -package \
    $(addprefix -classpath ,$(PRIVATE_CLASSPATH)) \
    -sourcepath $(PRIVATE_SOURCE_PATH)$(addprefix :,$(PRIVATE_CLASSPATH)) \
    -d $(PRIVATE_OUT_DIR) \
    - $(PRIVATE_CURRENT_BUILD) $(PRIVATE_CURRENT_TIME) \
    - $(PRIVATE_DROIDDOC_OPTIONS) \
    && rm -rf $(PRIVATE_OUT_ASSET_DIR) \
    && rm -rf $(PRIVATE_OUT_CUSTOM_ASSET_DIR) \
    && mkdir -p $(PRIVATE_OUT_ASSET_DIR) \
    --
    1.6.3.3
    The generating documentation will be put under out/common/host/….Once you finish it, you could revert the previous patch and pretend nothing happened
    $ cd /WHERE/TO/ANDROID/build/
    $ git reset –-hard HEAD^
    ps. I tried it on Eclair, it works.


    Update: you can tweak the stylesheet.css to make it looks better
    -body { background-color: #FFFFFF; color:#000000 }
    +body { background-color: #FFFFFF; color:#000000; margin : auto; max-width: 1024px; margin-top: 30px;}

    2008/11/30

    Starting at EFL

    Well, I want to write something about EFL first.

    [EFL], Enlightenment Foundation Libraries, is a GUI libraries which let you draw something on X. The windows manager Enlightenment is written by EFL. The position of EFL in Enlightenment is like GTK for Gnome or Qtopia for KDE.

    The maintainer make huge progress in EFL therefore it changes very fast.
    Before he make a release of EFL, we can say that EFL changes EVERYDAY.

    Rasterman, one maintainer of EFL, provided a script (get_e.sh) that you may build EFL easily.

    However, for the reason that getting more stable, Openmoko only use svn revision 36882 of EFL before it release.

    You can use this script to checkout out the source code and build it with revision 36882.

    #!/bin/bash

    sudo echo "Get Root permission" || exit
    list="eina eet evas ecore e_dbus efreet embryo edje etk edje_editor edje_viewer"

    for l in $list;do
    svn co -r 36882 http://svn.enlightenment.org/svn/e/trunk/$l
    cd $l
    ./autogen.sh || exit
    make
    sudo make install
    cd ..
    done