All posts by Pistolfly

Software Engineer in Tokyo, Japan

Rename branch

To rename branch, you can use -m option of git branch.

Rename <oldbranch> to <newbranch>

$ git branch -m <oldbranch> <newbranch>

Rename current branch to <newbranch>

$ git branch -m <newbranch>

If <newbranch> exists, -M instead of -m must be used to force the rename to happen.

If the return value of a command is greater than 128, it means that the command is terminated by signal

If the return value of a command is greater than 128, it means that the command is terminated by signal.

$ man bash
The return value of a simple command is its exit status, or 128+n if the command is terminated by signal n.

Example:

$ some_command
$ echo $?
139

In the above example, the return value is 139. Because 139=128+11 it means that the command was terminated by signal 11.
See `man signal` and you will find that signal 11 is SIGSEGV and it means segmentation violation.

Record shell input/output in file

$ script [file]

Run `script` command and a new shell starts up and records the input/output in the specified file until the shell is terminated.

To exit, `exit`.

If file is omitted, input/output are recorded in the file named 'typescript' in the current directory.

By default the log file is overwritten. If you want to append it, add the -a option.

Chaging log output destination path with log4net

log4net.Repository.ILoggerRepository[] repositories = log4net.LogManager.GetAllRepositories();
foreach (log4net.Repository.ILoggerRepository repository in repositories)
{
    foreach (log4net.Appender.IAppender appender in repository.GetAppenders())
    {
        log4net.Appender.FileAppender fileAppender = appender as log4net.Appender.FileAppender;
        if (fileAppender != null)
        {
            appender.File = "log.log"; // Set log output destination path
            appender.ActivateOptions();
        }
    }
}

* Although I have set File, I have to set File in configuration XML file.

log4netで設定したログ出力先パス、ファイル名の取得: DOBON.NETプログラミング掲示板過去ログ
log4netでのログ出力について - Insider.NET - @IT)

Print a pointer as an array using GDB

You can print an array using `print` command (p) with GDB, but it is useful to print a pointer such as function parameter as an array using operator @.
Operator @ regards the left operand of @ as the address and prints the data of the left operand as an array for the number equivalent to the right operand.

(gdb) list
34
35	void func(int v[], int len)
36	{
(gdb) p v[0] @ len
$1 = {4470, 5197, 2482, 1016, 4154, 9986, 8313, 6873, 8517, 5857, 9019, 8002, 349, 9817, 365, 1018, 2269, 9759, 7092, 8674, 4902, 3890, 9746, 7668, 792, 3842, 4053, 6422, 630, 4880, 9996, 7164, 8392, 8469, 2959, 8380, 6533, 1795, 4296, 9964, 8259, 7474, 72, 2948, 3681, 501, 3994, 508, 9544, 941, 8054, 2186, 7418, 8684, 3224, 7322, 3822, 5022, 3085, 8341, 2296, 4073, 1034, 9839, 7067, 1197, 739, 7028, 2809, 6610, 8633, 483, 3017, 9634, 4758, 8101, 7604, 4018, 2174, 5014, 6600, 3754, 2854, 4798, 3921, 2124, 9889, 1147, 2409, 6105, 224, 6973, 5937, 2953, 8614, 9101, 3399, 8431, 2226, 3548}

Source: Arrays - Debugging with GDB

svn add all files except ignored files, svn del all missing files at once

To schedule all files and directories in your working copy for addition to the repository recursively, you can do it like below.

$ svn add * --force

Because svn add * can't add files which are not under version control yet in directories which are under version control, --force is needed. But in this case ignored files and directories in current directory are also added.
It also attempts to add files under version control, so many warnings show. It's ugly.

At last I found out there is no good way as long as I am using svn only.

To add all files except ignored files and delete all missing files at once, you can create an alias which filters output of svn status using grep and replaces it using sed like below.

~/.bashrc

alias svndel="svn st | grep '^!' | sed -e 's/\![ ]*/svn del /g' | sh"
alias svnadd="svn st | grep '^?' | sed -e 's/\?[ ]*/svn add /g' | sh"

It's very convenient!

Source: svn に登録されていないファイルをまとめて svn add:Goodpic
svn addがめんどくさいので | firegoby

How to input control characters

Emacs

C-q <Control Character>

Example: Input escape character

C-q C-[

Shell, Vim

Ctrl+V <Control Character>

Example: Input escape character

Ctrl+V Ctrl+[

How to find a letter which should be pressed in combination with Control key?

<Control Character> in above explanation should be input in combination with Control key. The letter which should be input with Control key is a letter which is produced by setting 7th bit of the letter you want to input to 1, that is to say, by adding 0x40(64).
You can find it in `man ascii` etc.

Example:
Escape character is 0x1B(27).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x5B(91).
0x5B(91) is '['.
Therefore, to input escape character press Ctrl+[.

Line feed is 0x0A(10).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x4A(74).
0x4A(74) is 'J'.
Therefore, to input line feed press Ctrl+J.

Source: https://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
エスケープ文字の入力方法 - nelnalog.note