|Life| Career around the world.

【Global
<Opportunity>
 - Global –
 https://www.indeed.jobs/
 https://www.glassdoor.com/index.htm
 - European-
 https://ec.europa.eu/info/index_en

<Salary>
 https://www.levels.fyi/

<Cost & Earnings>
 https://www.numbeo.com/cost-of-living/comparison.jsp
 https://www.codementor.io/blog/best-cities-software-engineer-earnings-271vpf599k

【Taiwan】
<Opportunity>
 https://www.yourator.co/

<Salary>
 https://www.goodjob.life/

【Tools】
<Online Compiler>
 https://www.tutorialspoint.com/execute_python3_online.php
 https://www.onlinegdb.com/online_c_compiler
 https://ideone.com/

<Resume Format>
 https://resumegenius.com/

Featured post

|Tools| Git v.s Repo

一般跟別人合作開發都是使用 git。那 repo 是什麼?
repo 是 Google 開發出來的工具,用來管理 Android 的。

一份 Android code 是由許多 project 組成的,每個 project 就是一個 git project。
repo 這個工具,就是可以管理 branches 以及眾多的 git project!

> repo init 後,可以找到 .repo/manifest.xml 這會記錄你控制的 projects

*基本工作流程與對照:

repo git
repo init -u URL -m ooxx.xml -b remote_branch git clone URL
repo sync -c git pull URL remote_branch:local_branch
repo start branch_name –all git branch branch_name
git status git status
git add git add
git commit git commit
repo upload . git push


*git 好用指令:
 > 新增一個 local branch
 git branch {name}
 > 切換 branch 到 另一個 branch’
 git checkout {branch’}
 > 刪除特定 local branch
 git branch -d {name}
 > 查詢遠端的server 位置及名字
 git remote -v
 > 新增一個遠短 server
 git remote add {given_name} URL
 > 強迫 reset
 git reset –hard {local_branch}
 > 把 commit 推到遠端 branch
 git push {given_name} {local_branch}: refs/for/{remote_branch}
 > 從遠端 branch 拉 code 下來
 git pull {given_name} {remote_branch}:{local_branch}
 > 當前一個修改已 commit,又想把這次修改跟上一個修改一起 commit
 git commit –amend
 > 想上 patch 到某個已經 push 出去的 change
 git push {given_name} {local_branch}:refs/changes/{change_id}
 > 查詢某行的歷史
 git blame -L [行數] [檔案名]
 > 撿別 branch 的 commit 到目前的 branch
 git cherry-pick [sha-1]

*好用的配置
 > git commit 的模板:
 新增一個  ~/.git-template
 然後 git config commit.template ~/.git-template

 > 設置reviewers, git push rest,就會自動帶上 reviewers
 到 .git/config 編輯
 [remote “test”]
 pushurl = ssh://account@server_address:port/project_name
 push = {local_branch}:refs/for/{remote_branch}%r=someone1@mail, r=someone2@mail

*製作 patch,打 patch
 (在 branch A)
 git log
 git format-patch -1 [sha-1]
 mv ooxx.patch ~/
 (換到 branch B)
 git am [~/ooxx.patch]

*合併 commits / 分支
 git rebase -i {要固定住的那個 git log}

*把特定檔案還原到指定的 git log 時期的樣子
 git checkout {指定的 git log} {file name}
 [modify rebase script]
 https://zerodie.github.io/blog/2012/01/19/git-rebase-i/

*如果沒有圖形化介面的 gitk,可用
  git log –oneline –graph

*查看現在 local branch 是從哪的 remote 抓來的
 cat .git/FETCH_HEAD

值得注意的是:
pull 的 server / review 的 server / push 的 server 可能不同,
設置 push 的 server 時,請去確認 repo upload 時,到底是推到哪?


ref. [Coding] repo & git 的使用方法

Featured post

|Linux| Synchronization: mutex v.s. semaphore

If you use multi-threads to do something at the same time, that is a Synchronization.
You need to control threads to avoid Race Condition and Critical Section.
mutex and semaphore can solve the critical section.
But what’s different?

Mutex is an object and binary semaphore .

A semaphore is a signal, and a thread that is waiting on a semaphore can be signaled by another thread (more then 2 threads).
But you should notice that the wait and signal operations require to be executed in the correct order. Nevertheless, deadlocks will occur in semaphore.

Roughly, a mutex would be referred to as binary semaphore.
There are many dufferences, you may refer to this website.
https://www.guru99.com/mutex-vs-semaphore.html

How can we use semaphore?

// header
#include <semaphore.h>
class Foo {
    private:
        //declaration
        sem_t firstDone;
        sem_t secondDone;
    
    public:
        Foo() {
            // initialize
            sem_init(&firstDone, 0, 0);
            sem_init(&secondDone, 0, 0);
        }

        void first(function<void()> printFirst) {
            printFirst();
            //broadcast signl: first has done
            sem_post(&firstDone);
        }

        void second(function<void()> printSecond) {
            // waiting the signal from firstDone
            sem_wait(&firstDone);
            printSecond();
            //broadcast signl: second has done
            sem_post(&secondDone);
        }

    void third(function<void()> printThird) {
            // waiting the signal from secondDone
            sem_wait(&secondDone);
            printThird();
    }
};

Ref.
https://www.guru99.com/mutex-vs-semaphore.html
https://sls.weco.net/node/21326
https://jasonblog.github.io/note/linux_system/mutex_yu_semaphore_zui_da_de_cha_yi_shi.html

|C/C++| What are argc and argv ?

In main function, there are two parameters, argc and argv.

int main( int argc, char **argv)

argc := argument count, which is the number of parameters.
argv := argument value, which assign by terminal from user.
argv[0] := the name of this program
argv[1], argv[2] := enter by user


Test:

#include <stdio.h>

int main( int argc, char **argv ){
    int i = 0;
    printf( “argc = %d\n”, argc);
    for( i=0; i!=argc; ++i){
        printf( “argv[%d] = %s\n”, i, argv[i] );
    }
    return 0;
}

|C/C++| Use dlopen and dlsym to get handler of dynamic library(.so)

If you have a dynamic library (libtest.so) and there is a function (int test_foo(float)) in this library, how can I reuse the function in another library?

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

int main(int argc, char **argv)
{
   void     *handle;
   
   // An function pointer, for point to test_foo
   int   (*test_foo_pointer)(float);
   char     *error;

   //open the target library libtest.so
   handle = dlopen("libtest.so", RTLD_LAZY);
   if (!handle) {
       fprintf(stderr, "%s\n", dlerror());
       exit(EXIT_FAILURE);
   }

   dlerror();    // Clear any existing error


   // get test_foo and assign to test_foo_pointer 
   test_foo_pointer = dlsym(handle, "test_foo");
   
   if ((error = dlerror()) != NULL)  {
       fprintf(stderr, "%s\n", error);
       exit(EXIT_FAILURE);
   }

   dlclose(handle);
   exit(EXIT_SUCCESS);
}


|Android| How was the Android system after power up?

This article will stand on high level to scan initialization modules.

User press power key ……

First, Boot ROM
 - Loads the BootLoader into RAM and starts executing.

Second, BootLoader
 - Start up and find the system kernel.
 - Bootloader is a place where manufacturers put their locks
  and restrictions.
 - Detects external RAM
 - Setups the network, memory … etc, which requires to run Kernel.

Third, Kernel
 - Setup cache
  Protected memory
  Scheduling
  Loads drivers
  Starts kernel daemons
  Mounts root file system
  Initializing Input/Output
  Starts interrupts
  Initializes process table ……
 - Looks for “init” in system files
 - Launch root process

Forth, Init
 - Mounts directories like /sys, /dev or/proc
 - Runs /init.rc script. The init.rc is responsible for the initial set up of the system.

Fifth, (Android) Zygote: 
 - VM process that starts as the system boots
 - app_process launces Zygote

Sixth, SystemServer
 - Load a native library called android_servers

ref. for Android: https://maoao530.github.io/2017/01/06/android-start/

refs.
https://blog.csdn.net/a4262562/article/details/76779236
https://danielmaker.github.io/blog/linux/start_kernel.html
https://cjworld1208.pixnet.net/blog/post/8014497
http://embeddedvenkatpari.blogspot.com/2016/05/how-to-load-firmware-using-pil.html?m=1
https://www.twblogs.net/a/5b8d19262b717718833b2c22
http://albert-oma.blogspot.com/2016/07/embedded-u-boot.html?m=1

|Telephony| Initialize com.android.phone

This article will focus on Telephony framework and Phone App initialization flows.
There are many key words arranged by initial steps.

Android Q.

First, you should know the role of “SystemServer” in Android.
 - ActivityManagerService up

Second, (Service) Telecom service
 - TelecomLoaderService loads Telecom service
 - path: /android/applications/sources/services/Telecomm/
     /android/frameworks/base/telecomm/

Third, (APP) Create PhoneAPP
 - (see AndroidManifest.xml, android:persistent=”true”)
  PhoneAPP will reborn after killed
 - path: /packages/services/Telephony/…/PhoneApp.java

Forth, (Framework) PhoneFactory brings up GsmCdmaPhone
 - onCreate() in PhoneApp, it will create PhoneGlobals
 - Initialize PhoneFactory.makeDefaultPhones
 - Create monitor service tracker, including ServiceStateTracker, CallTracker, …, and RIL

ref.
Telephony解析之整体架构简介
Telephony解析之Phone启动流程

|Java| Say Hello to JNI

Although Java is easy to transfer platforms, we still need some C++/C libraries to control drivers or basic modules.

JNI can be an interface between Java and C++/C.
The following article will teach you step by step.

OS: Ubuntu 18.04
Java: Open JDK 8


Step 1. Implement Java: HelloWorldJNI.java

class HelloWorldJNI {
    private native void printByC();
    public static void main(String[] args) {
        new HelloWorldJNI().printByC();
    }
    static {
        System.setProperty("java.library.path", "~/Desktop/JNI/");
        System.loadLibrary("HelloWorldJNI");
    }
}

Step 2. Generate Class and Header
(open your terminal)
$ javac HelloWorldJNI.java
$ javah -jni HelloWorldJNI

Then HelloWorldJNI.class and HelloWorldJNI.h are created.

HelloWorldJNI.h:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorldJNI */

#ifndef _Included_HelloWorldJNI
#define _Included_HelloWorldJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorldJNI
 * Method:    printByC
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorldJNI_printByC
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Step 3. Implement your C++/C library: HelloWorldJNI.c

#include <jni.h>
#include <stdio.h>
#include "HelloWorldJNI.h"

JNIEXPORT void JNICALL Java_HelloWorldJNI_printByC (JNIEnv *env, jobject obj){

    printf("Hello from C\n");
    return;
}

Step 4. Build C++/C library as .so
(open your terminal)
$ gcc -shared -I/usr/lib/jvm/java-8-openjdk-amd64/include -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux HelloWorldJNI.c -o libHelloWorldJNI.so

The name ,”lib“+name.so, is important because the definition of “System.loadLibrary” will recognize “lib”.

Step 5. Test
(open your terminal)
$ java HelloWorldJNI


OUTPUT:
$ Hello from C

https://github.com/zivww/HelloJNI

WordPress.com.

Up ↑