Pages

2011-08-16

THREE


人有三样东西是无法隐瞒的,咳嗽、穷困和爱;你想隐瞒越欲盖弥彰。
人有三样东西是不该挥霍的,身体、金钱和爱;你想挥霍却得不偿失。
人有三样东西是无法挽留的,时间、生命和爱;你想挽留却渐行渐远。
人有三样东西是不该回忆的,灾难、死亡和爱;你想回忆却苦不堪言。

《洛丽塔》

2011-08-13

Store extra info in pointer

A pointer is at least align to 4 bytes, in all architectures.
That means, the lowest 2 bits are always 0 :)
For example in kernel standard rbtree (include/linux/rbtree.h),

struct rb_node
{
    unsigned long  rb_parent_color;
#define    RB_RED       0
#define    RB_BLACK    1
    struct rb_node *rb_right;
    struct rb_node *rb_left;
} __attribute__((aligned(sizeof(long))));



rb_parent_color is a pointer to it's parent, while bit 0 represents the color of the parent.


They've defined a macro to say hello world to it's parent,
#define rb_parent(r)   ((struct rb_node *)((r)->rb_parent_color & ~3))

2011-08-10

sshd config

/etc/ssh/ssh_config and /etc/ssh/sshd_config
In the latter, set some to control remote ssh login.
I.e.

Port 22
Protocol 2
PermitEmptyPasswords no
PermitRootLogin no  # can't login as root
AllowUsers xxx        # nobody can login except for xxx

For the last 2, login from a remote host, the server'll say 
'Permission denied, please try again.'
As u didn't input the right password.

2011-08-03

Haskell's otherwise is function, not language keyword


Inside Prelude, there is:

otherwise :: Bool
otherwise = True


For guards, it's more readable.

The frame size of xxx bytes is larger than 1024 bytes

Maybe a stack-allocated local variable inside a function which is larger than 1024 bytes.

From a stack-overflow thread:
STACK_CHECK_MAX_FRAME_SIZE
The maximum size of a stack frame, in bytes. GNU CC will generate probe instructions in non-leaf functions to ensure at least this many bytes of stack are available. If a stack frame is larger than this size, stack checking will not be reliable and GNU CC will issue a warning. The default is chosen so that GNU CC only generates one instruction on most systems. You should normally not change the default value of this macro.

STACK_CHECK_FIXED_FRAME_SIZE
GNU CC uses this value to generate the above warning message. It represents the amount of fixed frame used by a function, not including space for any callee-saved registers, temporaries and user variables. You need only specify an upper bound for this amount and will normally use the default of four words.

STACK_CHECK_MAX_VAR_SIZE
The maximum size, in bytes, of an object that GNU CC will place in the fixed area of the stack frame when the user specifies `-fstack-check'. GNU CC computed the default from the values of the above macros and you will normally not need to override that default.

2011-08-01

Git excluding & including

It traps me a lot.

Ever I just known setting some wildcard patterns in .gitignore to exclude useless files.
If some object files( .o ) are in a lot of dirs with different depth, 
like a/a.o, a/b/b.o, a/b/c/c.o
then I have to set 
*/*.o
*/*/*.o
*/*/*/*.o
in .gitignore
Oh, it's a nightmare.

.git/info/exclude is the very file to achieve that.
*.o is enough.

In some circumstances, we need a few including from the excluding type,
set a ! (bang) at the beginning of the name.


A clear instance from gitignore manual page:



    $ git status
    [...]
    # Untracked files:
    [...]
    #       Documentation/foo.html
    #       Documentation/gitignore.html
    #       file.o
    #       lib.a
    #       src/internal.o
    [...]
    $ cat .git/info/exclude
    # ignore objects and archives, anywhere in the tree.
    *.[oa]
    $ cat Documentation/.gitignore
    # ignore generated html files,
    *.html
    # except foo.html which is maintained by hand
    !foo.html
    $ git status
    [...]
    # Untracked files:
    [...]
    #       Documentation/foo.html
    [...]