Author Archives: wudi

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';

Google CodeJam – Problem B. Rank and File

https://code.google.com/codejam/contest/4304486/dashboard#s=p1&a=2

the idea is very simple, every items on the matrix will appear even time, therefore, for the row which is missing, all items should have odd times.

the code is following

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
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
int main(int argc,char **argv) 
{ 
  int N;
  int array[3000];
  scanf("%d\n",&N);
 
  for(int i=0;i<N;i++)
  {
	  int T;
	  scanf("%d\n",&T);
	  memset(array,0,sizeof(int)*3000);
 
	  int temp;
	  for(int m=0;m<2*T-1;m++)
	  {
		  for(int n=0;n<T;n++)
		  {
			scanf("%d",&temp);
			array[temp]++;
		  }
	  }
 
	  printf("Case #%d: ",(i+1));
 
	  for(int m=0;m<3000;m++)
	  {
		  if(array[m]>0 && array[m]%2==1)
		  {
			  printf("%d ",m);
		  }
	  }
	  printf("\n");
  }
 
  return 0; 
}

Google CodeJam – Problem A. The Last Word

https://code.google.com/codejam/contest/4304486/dashboard#s=p0&a=2

This problem is very simple, use basic linked operation will be enough,

it only compare the head item and tail item.

if new item > head item, then new item will be inserted into head.

if new item <= head item, then it will be inserted int tail. check following code.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
struct element
{
	char c;
	struct element *next;
};
 
int main(int argc,char **argv) 
{ 
	int N;
	char c;
	scanf("%d\n",&N);
 
	char array[2000];
 
	for(int i=0;i<N;i++)
	{
		memset(array,0,sizeof(char)*2000);
 
		scanf("%s\n",array);
 
 
		struct element *tail;
		struct element *head = (struct element *)malloc(sizeof(struct element));
		memset(head,0,sizeof(struct element));
		head->c = array[0];
		head->next = NULL;
		tail = head;
 
		for(int j=1;array[j]!='\0';j++)
		{
			if(array[j]>=head->c)
			{
				struct element *e = (struct element *)malloc(sizeof(struct element));
				e->c = array[j];
				e->next = head;
				head = e;
			}
			else
			{
				struct element *e = (struct element *)malloc(sizeof(struct element));
				e->c = array[j];
				e->next = NULL;
				tail->next = e;
				tail = e;
			}
		}
		printf("Case #%d: ",i+1);
		struct element *p = head;
		for(;;)
		{
			if(p!=NULL){
				printf("%c",p->c);
				p=p->next;
			}
			else
				break;
		}
		printf("\n");
 
	}
 
	return 0; 
}