Maven – different between -DskipTests and -Dmaven.test.skip=true

sometime when we build maven, junit will also be invoked to test code.

usually, these unit test will fail because of development machine configures are different.

there are two commands which could skip test.

1
2
$ mvn package -DskipTests
$ mvn package -Dmaven.test.skip=true

“-DskipTests” is to build test source code but don’t run them.
“-Dmaven.test.skip=true” don’t do anything for test source code, do not compile and do not run for test code.

Qt – ListView SetModel tip

when developing qt, QStringList should be display on ‘ui->listView’, However, following code won’t work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
...
    QDir myDir("C:\\");
 
    QStringList filter("*");
    QStringListModel model;
    QStringList filesList = myDir.entryList(QStringList(filter),QDir::Files | QDir::Dirs);
    model.setStringList(filesList);
    ui->listView->setModel(&model);
...
}

because ‘model’ object will be delete after function is done.

ui->listView will not be able to get model object.

move to MainWindow ‘model’ to MainWindow declare will be good.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QStringListModel model;
private:
    Ui::MainWindow *ui;
};
 
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
...
    QDir myDir("C:\\");
 
    QStringList filter("*");
 
    QStringList filesList = myDir.entryList(QStringList(filter),QDir::Files | QDir::Dirs);
    model.setStringList(filesList);
    ui->listView->setModel(&model);
...
}

oracle – oracle 11g installation

when installing oralce 11g and choose enterpise, during installation, installer will pop up and said some ear is not found.

Here are steps to make it work.
extract win64_11gR2_database_1of2.zip into win64_11gR2_database_1of2 folder first.

Then extract win64_11gR2_database_2of2.zip into win64_11gR2_database_2of2 folder.

copy all 4 files in database/ stage/ components folder in win64_11gR2_database_2of2 folder(unziped) & paste them (no replacement) in database/ stage/ components folder in win64_11gR2_database_1of2 (unziped).

default username is ‘SYSMAN’ and password is string installer asking for and priviledge is ‘Normal’.

WordPress – Database Scheme

when installing wordpress,
using salt

https://api.wordpress.org/secret-key/1.1/salt/

to get random string text as ID of website.

in scheme.php whose path is (wp-admin/includes/schema.php)

$blog_tables has table name, scheme, and all information wp need.

Step By Step.
1. After clicking on ‘Installing wordpress’, dbDelta(‘all’) will call wp_get_db_schema(‘all’) in schema.php to get all sql script.

1
2
3
4
5
6
7
8
9
10
11
function dbDelta( $queries = '', $execute = true ) {
..	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) )
	    $queries = wp_get_db_schema( $queries );
..
}
 
function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
...
	make_db_current_silent(); // here we go to dbDelta
...
}

in scheme.php:
function populate_options()

wordpress will load default theme which defined in WP_DEFAULT_THEME.

spacemacs – install spacemacs

install spacemacs is very simple.
make sure using emacs version >= 24.5

but the keypoint is to remove “.emacs” file.
it will force emacs to load config from “.emacs.d” folder.

in windows, %HOME% must be set to a path for .emacs.d

Linux:
$ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Windows:
> cd %HOME%
> git clone https://github.com/syl20bnr/spacemacs .emacs.d

spacemacs

on mac os, sometime lock file is very annoying.

every time you edit it, emacs will ask you to choose s,p,q,?,

check more details.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html

Here is code to make it work.
;; for mac os x
(setq auto-save-default nil)
(setq create-lockfiles nil)

TCC – dynarray_add

This is very common function in TCC state.

here is main logical.

1
2
3
4
5
6
7
dynarray_add(void ***ptab, int *nb_ptr, void *data) 
{
...
pp= *ptab; nb=*nb_ptr;
pp[nb++] = data;
...
}

what dynarray_add do is simple. input array has just 3 parts that is double pointer, index and value.

then assign data to double pointer just like assign string to char array.

Here is sample call stack, it call to add pathname into library_paths.

1
2
3
dynarray_add(p_ary, p_nb_ary, str.data);
tcc_split_path(TCCState *s, void ***p_ary, int *p_nb_ary, const char *in)
tcc_split_path(s, (void ***)&s->library_paths, &s->nb_library_paths, pathname);

the define of library_paths is following

1
2
3
4
5
6
struct TCCState {
...
    char **library_paths;
    int nb_library_paths;
...
}

ionic side menu left button and right button disappear

When doing Ionic project, one problem that sometime nav buttons for side menu will disappear, this is very annoying.

Here is sample code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<ion-side-menu-content>
  <ion-nav-bar class="bar-positive">
 
    <ion-nav-buttons side="left">
      <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
      </button>
    </ion-nav-buttons>
 
    <ion-nav-buttons side="right">
      <button class="button button-icon button-clear ion-navicon" menu-toggle="right">
      </button>
 
    </ion-nav-buttons>
  </ion-nav-bar>
 
  <ion-nav-view name="centre-panel"></ion-nav-view>
 
</ion-side-menu-content>

The solution is following: adding enable-menu-with-back-views=”true” to ion-side-menus

1
<ion-side-menus enable-menu-with-back-views="true">

Lucene – Build Lucene and import to eclipse.

This is first article on Lucene source code analysis.
There are two ways to get source code, one of them are download directly form lucene’s WebSite http://www.apache.org/dyn/closer.lua/lucene/java/6.2.1

you could choose to download lucene-6.2.1-src.tgz and release binary build lucene-6.2.1.tgz .

However, lucene-6.2.1-src.tgz are not easy to import to eclipse.run “ant -p” to check all commands and “ant eclipse” command is not ready yet. you have to check out https://github.com/apache/lucene-solr. From readme you could find the following message
“To compile the sources run ‘ant compile’
To run all the tests run ‘ant test’
To setup your ide run ‘ant idea’, ‘ant netbeans’, or ‘ant eclipse’”

install ivy for ant.
Download ivy file such as “apache-ivy-2.4.0-bin.zip” and put to ant library file.

after git clone from https://github.com/apache/lucene-solr, run “ant eclipse” and then run eclipse , “Import” -> “Existing Projects into workspace”

TCC – string index from char str[1] to str[len]

Check TokenSym declaration firstly, TokenSym is to store a single token info.

1
2
3
4
5
6
7
8
9
10
typedef struct TokenSym {
    struct TokenSym *hash_next;
    struct Sym *sym_define; /* direct pointer to define */
    struct Sym *sym_label; /* direct pointer to label */
    struct Sym *sym_struct; /* direct pointer to structure */
    struct Sym *sym_identifier; /* direct pointer to identifier */
    int tok; /* token number */
    int len;
    char str[1];
} TokenSym;

when malloc memory, it will alloc TokenSym+len.

1
ts = tcc_malloc(sizeof(TokenSym) + len);

the later on, memcpy copy str with len to str memory.
Of course, str[1] will be out of range, but extra len memory is appended.
therefore, str[1] is expanded to str[len].

This is very popular within TCC’s struct declaration.

1
2
memcpy(ts->str, str, len);
ts->str[len] = '\0';