8/24/2008

Play Tetris with Emacs by "M-x tetris"

You can play Tetris with Emacs by inputting command "M-x tetris". I played it and captured the movie. (env : Ubuntu-7.10-Desktop)

Original Text (Japanese)

8/15/2008

Serious Shortage of PG and SE in Japan

Programmers and System Engineers are shortage in Japan. It is because they are treated badly. Do you know 3K? 3K are Kitsui(hard), Kaerenai(can't come home because of the work is very busy) and Kyuryo ga yasui(bad pay).

Recently, we hear 7K! 7K is old 3K + new 4K. Kisoku ga kibishi(strict rule), Kyuka ga torenai(take no leave of absence), Kesyo ga noranai(make-up isn't on a roll because of skin roughness caused by tiredness) and Kekkon dekinai(can't marry because of no encounter to the opposite sex and busyness).

Therefore, even university students who majors in computer science are unwilling to be PG or SE. So, the companies employ not only science students (who don't major in computer science) but also liberal arts students!

A professor said we(university students who majors in CS) should enter "Matomona" companies which treat us as software engineers. For example, Google, Microsoft, Sun Microsystems, ... They are all foreign affiliated company^^; In other words, many Japanese company aren't "Matomo" and treat us as a cogwheel of the company.

I think IT companies have no future in Japan if nothing is done.

8/13/2008

Cannot Compile C Programs in Initial Ubuntu

Ubuntu is very useful and one of Linux distribution I recommend for Linux beginner.

However, we can't compile C programs by gcc even "Hello, world!" because of not installed C developer's libraries. I think that it is a hole many beginners developing in Ubuntu fall into.

Therefore, I wrote how to install C developer's libraries "libc-dev" and editor "Emacs" in Ubuntu.

Debian Packages

Because Debian packages is available in Ubuntu, We can install many software by "apt-get" command. However, Ubuntu doesn't the administrator's account "root" from consideration on security. Therefore, we use "sudo" command instead of "su" command in order to run commands need administrative privilege. That is, we generally use "sudo" command to install a package. package means the package's name you install.

$ sudo apt-get install package

Developer's library in C: libc6-dev

Run the following command in a terminal(shell). Answer "y" to questions during install.

$ sudo apt-get install libc6-dev

Editor: emacs

$ sudo apt-get install emacs

Original Text(Japanese)

8/11/2008

Review: National Museum of Emerging Science and Innovation

I went to Miraikan (National Museum of Emerging Science and Innovation) in Odaiba in Japan. Its Curator is Japanese 2nd astronaut Mr.Mouri! I saw the permanent exhibit which has 4 fields: 1.Innovation and the Future, 2.Information Science and Technology for Society, 3.Life Science, and 4.The Earth Environment and Frontiers. I major in Computer Science, so I was looking forward to look at the 1st and 2nd areas.

1. Innovation and the Future

This sector shows micro machines, robots, condensed matter physics(superconductivity, electromagnetic induction), and so on.

Acceleration Sensor ModuleJapanese game "Kirby Tilt N' Tumble" is displayed as an example of using acceleration sensor. Recently, Nintendo Wii Remote Controller uses this device. This picture is an acceleration sensor of mine. We can buy such a module at a low price in Akihabara in Japan.

A midget model of linear motor car: well-known application of superconductivity is there. The midget runs very slowly but it is truly a linear motor car. An interpreter taught the mechanism to a family.

There are some robots which can control by children. I saw a children operating a robot and fetching a block by robot's arms. He looks very joyful!

2. Information Science and Technology for Society

There is a high-profile model in this area. It is a model of the Internet. It is constructed of the models of nodes, packets, lines, and routers. It seems to show the packet routing.

Another topic of this area is the interface between humans and computers. We can see and use optical interfaces, speech recognition devices and so on.

Only 12 Commands for Emacs Beginners

Emacs has very many commands, so beginners are apt to dislike Emacs. I also did.

However, I learned a few commands of Emacs someday. Then I became to use Emacs so-so and to enjoy Emacs! By learning the least commands, I became able to use emacs! Since then, Emacs is one of my favorite editors.

Therefore, I listed up only 12 commands for Emacs beginners.

Notation

  • C-x : to type "Ctrl" key and "x" key at the same time.
  • M-x : to type "Meta"("Alt") key and "x" key at the same time.
  • C-x C-y : to type C-x, then type C-y.

Launch Emacs

Normal :
> emacs filename
Other Window :
> emacs filename &
in Current Shell (<- Useful!) :
> emacs filename -nw

File

  • C-x C-f : Open File
  • C-x C-s : Save File
  • C-x C-c : Save File and Exit Emacs

Edit

  • C-@ : Set Mark
  • C-w : Cut (from Mark to Cursor)
  • M-w : Copy (from Mark to Cursor)
  • C-y : Paste
  • C-_ : Undo

Other

  • C-z : Interrupt (Return to Shell)

If you launched Emacs in a Shell(emacs filename -nw), it is useful to return the Shell by this and to restart the Emacs by "fg" command.

Original Text(Japanese)

8/09/2008

Compute Determinant of 3x3-Matrix with Sarrus' Method

I wrote a program which computes determinant of 3x3-matrix with Sarrus' Method because someone accessed my blog in order to find a program computing determinant of 3x3-matrix. This program is written in C.

Of course, we can calculate it by Cofactor Expansion, but Sarrus' Method is much easier than it. So, I use Sarrus' Method.

Function to Compute Determinant of Matrix

int det(int a[3][3]) {
  return a[0][0]*a[1][1]*a[2][2]
       + a[0][1]*a[1][2]*a[2][0]
       + a[0][2]*a[1][0]*a[2][1]
       - a[0][2]*a[1][1]*a[2][0]
       - a[1][2]*a[2][1]*a[0][0]
       - a[2][2]*a[0][1]*a[1][0];
}

Main Function for Test

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int a[3][3], i, j;

  if(argc == 1) {
    a[0][0] = 1; a[0][1] = 2; a[0][2] = 3;
    a[1][0] = 4; a[1][1] = 5; a[1][2] = 6;
    a[2][0] = 7; a[2][1] = 8; a[2][2] = 9;
  } else if(argc == 10) {
    for(i=0; i<3; i++)
      for(j=0; j<3; j++)
 a[i][j] = atoi(argv[3*i+j+1]);
  } else {
    printf("Usage:\n");
    printf("./a.out\n");
    printf("   or\n");
    printf("./a.out a11 a12 a13 a21 a22 a23 a31 a32 a33");
  }

  printf("a =\n");
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      printf("%3d", a[i][j]);
    }
    printf("\n");
  }
  printf("\n");

  printf("det(a) = %d\n", det(a));

  return 0;
}

Output

$ ./det
a =
  1  2  3
  4  5  6
  7  8  9

det(a) = 0
$ ./det 1 6 -2 5 -3 4 -1 -2 4
a =
  1  6 -2
  5 -3  4
 -1 -2  4

det(a) = -122

Main Function for Test(Simple Version)

I prepare simple version of test function for beginners of programming.

#include <stdio.h>

int main(int argc, char *argv[]) {
  int a[3][3];

  a[0][0] = 1; a[0][1] = 2; a[0][2] = 3;
  a[1][0] = 4; a[1][1] = 5; a[1][2] = 6;
  a[2][0] = 7; a[2][1] = 8; a[2][2] = 9;

  printf("det(a) = %d\n", det(a));

  return 0;
}

Original Text(Japanese)

Implement Simple Shell - UNIX System Programming

I implemented a simple shell in programming language C with UNIX system calls. Now it has only following functions, but I will add some functions(Redirection, Pipe, Background running, ...) in future.
  1. Run inputed commands.
  2. "exit" command.
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>

#define MAX_ARGS 10
#define MAX_LEN  100

void child(int argc, char *argv[MAX_ARGS]);

int main()
{
  int argc, n = 0;
  int status;
  char input[MAX_LEN], *argv[MAX_ARGS], *cp;
  const char *delim = " \t\n"; /* delimiters of commands */

  while (1) {
    /* show a prompt */
    ++n;
    printf("command[%d] ", n); 

    /* read a line */
    if (fgets(input, sizeof(input), stdin) == NULL) {
      /* inputed EOF(Ctrl-D) */
      printf("Goodbye!\n");
      exit(0);
    }

    /* split the input to commands with blank and Tab */
    cp = input;
    for (argc = 0; argc < MAX_ARGS; argc++) {
      if ((argv[argc] = strtok(cp,delim)) == NULL)
        break;
      cp = NULL;
    }
    /* exit this shell when "exit" is inputed */
    if(strcmp(argv[0], "exit") == 0) {
      printf("Goodbye!\n");
      exit(0);
    }
    pid_t pid = fork();
    if(pid == -1) {
 /* failed to fork() */
      perror("fork");
      exit(1);
    } else if(pid == 0) {
 /* child process */
      child(argc, argv);
    } else {
 /* parent process */
      wait(&status);
    }
  }
}

void child(int argc, char *argv[MAX_ARGS]) {
  execvp(argv[0], argv);
}
Result
****@ubuntu-vm:~/work/os$ gcc -Wall s_shell.c
****@ubuntu-vm:~/work/os$ ./a.out
command[1] ls
#ex01.c#  execlp0.c   fileio1.c~  fileio4.c~  s_shell.c
a.out     execve0.c   fileio2.c   foo         system0.c
ex1.c     execve0.c~  fileio2.c~  fork0.c     wait0.c
ex1.c~    fileio0.c   fileio3.c   fork0.c~    wait0.c~
ex2.c     fileio0.c~  fileio3.c~  hello.c
ex2.c~    fileio1.c   fileio4.c   httpget.c
command[2] cat hello.c
#include <stdio.h>
int main() {
  printf("hello, world!\n");
  return 0;
}
command[3] gcc -Wall hello.c
command[4] ./a.out
hello, world!
command[5] exit
Goodbye!
****@ubuntu-vm:~/work/os$ 
Reference site Original Text(Japanese)