RSS Feed

Bye-bye Xiaomi Mi 3


Prelude

Last weekend was a long story, that I my Xiaomi Mi 3 is screwed! It happened like this.

I was in the car, using the phone to surf net and go through the social networks. Then suddenly, it popped up a notification saying that my phone is too hot, asked me to cool down, with a system button “Cool Down”. I cannot guarantee that this is not a virus, but I believe that my phone doesn’t have virus. (I can hardly find the Cool Down feature online, this is the only one.) So, I pressed the Cool Down button. With this press, sorry my phone. You got a stroke, and never overcome. Bye-bye!

Recovering

Because of that one press, my phone fell into the bootloop. When I went home, I searched for some possible solutions online. And found that, the possible solution is to flash the stock ROM. I downloaded everything I needed. Moreover, the most important thing is to get all my data especially photos, which I didn’t make any backup recently.

So, I followed the steps in this wonderful page for how to perform a flash. WARNING: This will flash everything, meaning, you will loss your data, including everything in the internal storage, such as photos. So, before I flash the stock ROM, I followed this forum to learn how to restore the data.

Summary:

  1. Get all the necessary drivers and software. Actually can be found in the official site. Important software are: MiFlash. It also requires drivers which can be found here. So that you can use “fastboot” command (and also “adb” command) and detect the phone when USB connected.
  2. Get the stock ROM and recovery ROM. I used TWRP.
  3. Boot into fastboot mode (read the instruction from the “wonderful page” mentioned above).
  4. Use command-line “fastboot” to flash the recovery ROM TWRP. And boot into the recovery mode.
  5. Once successfully boot, your computer can detect the phone (as MTP), then you can access the internal storage and copy all the files.

The luckiness within the unluckiness (不幸中的大幸), I managed to boot into recovery mode. Immediately copied everything from the phone to the computer. After this, I tried to flash the stock ROM. But failed. Tried various times, but none of them work. Even wanted to boot into the TWRP recovery mode was very difficult. But luckily, I got all the photos from the phone before these.

Searched for the solution again, I found this forum. Probably my battery got serious problem.

Yet, because my phone was bought through the mobile phone shop, not from Xiaomi official website. The phone is actually from Taiwan. And there is no nearest Xiaomi service centre at my area (and never will be). So, I can only say “bye-bye” to my phone. It is the time to “let it go”.

Epilogue

Most important thing is data. As long as you have the data, put it in any phone, then that is your phone. Just like your soul and spirit resides in any body, make it you yourself!

Linux no sound after boot into Windows


Just now was trying to boot into Windows, by plugged in the HDMI cable, which supports for video only. But then, I rebooted into Linux without plugged out the HDMI cable. Then, it caused no sound in Linux.

Try 1: I killed the pulseaudio, then delete the ~/.config/pulse, and rebooted Linux. Failed.

Try 2: Run alsamixer, turned on everything, and do Try 1 again. Failed.

Then I guessed it was caused by the HDMI cable, which the Windows may assume there is audio, then caused my computer somehow ouptut the audio through the HDMI, even I rebooted into Linux.

Try 3: Plugged out the HDMI, booted into Windows. I checked the audio in Windows. It plays well. Then rebooted into Linux without plugged in HDMI. Yeah! It works. Passed.

Next level

Then I found that, though the sound works fine, my headphones doesn’t work. Tried out many methods as I asked in forum.

At the end, it is solved by shutdown, and boot again.

Arch Linux update issue


Today, when I updated Arch Linux as usual, then suddenly it brought me to the TTY, which didn’t allow me to change to other TTY (due to NVIDIA graphic card issue which has been attached with my laptop for quite a long time.)

Because I could do nothing, and not sure whether the upgrade was completed, so I made a hard reset.

Then I boot with fallback initrmfs just in case has any error. Luckily, there was no problem to boot.

Then I did a quick check on the database. And found that it was locked. Meaning, I had restarted without finishing the update. This is serious if it happened when upgrading the kernel.

Reading the /var/log/pacman.log, I found that some packages were not updated. Then I just simply did a pacman command, and I got these message,

ldconfig: File /usr/lib/libqca.so is empty, not checked.
ldconfig: File /usr/lib/libQt5QuickTest.so is empty, not checked.
ldconfig: File /usr/lib/libQt5QuickParticles.so is empty, not checked.
...

Read the forum, the solution to re-install the packages that own these files. So I used pkgfile to search fo the owner of these files. Then, re-installed each packages found.

Then I just made sure all the packages were installed properly with

pacman -Dk #previously is testdb

Social media


Different social media usage:

Facebook – Family and friends status.

Google+ – Official tech news or blogs.

Twitter – Celebrities personal status.

Weibo – China celebrities personal status.

Instagram – Celebrities’ photos.

Reddit – Community and specific topic discussion.

WordPress – Nothing but blog posts.

C++ revisit


I liked C programming, as it is low level and the compiler is widely available. Using C language can demonstrate the understanding of pointer and memory. You can implement a linked list or a hash table by using C. So that you can understand better how the linked list and hash table work.

But as long as you want to build some end user applications, C language is never a good choice. Choosing a language for our product is important. We do not develop a web application using low level programming language. It is totally impractical.

C and C++

Do not think that C language is an old language. It can survive until today because it has some powerful features (yet I cannot name them out, because I am not a C developer). There are new features on C99 and C11. But practically to solve higher level problem like game development, C++ is much more better than C. (But there is a better choice like Lua.)

Syntax

Why is C++ better than C? From the syntax level, it is easier to read and easier to write. For example,

strtolower(trim(myString));

where myString is a C string, then trim() is a function that returns trimmed string, strtolower() is another function that returns the string with lower case. (The function names I used here is based on PHP.) So, we can see, when we read or write, we need to read from right to left: trim then strtolower. And the parentheses needs to be matched properly.

On the other hand for C++,

myString->trim()->strtolower();

Let’s say myString is a customized object, namely MyString, that manipulates the string. So, the syntax is much more intuitive. myString calls the trim() method and returns the MyString object, so that we can continue with strtolower() that returns MyString object. This is called method chaining.

Object oriented

Object oriented is a wondrous invention! It is so powerful that most programming languages today support object oriented. Inheritance, polymorphoism, and interface, these features reduce a lot of tremendous works. You can implement object oriented in C (using library such as GObject), but C language is not designed for object oriented.

Because of syntax and the object oriented, I prefer C++ than C.

String

Another advantage of C++ is the string. C string is an array of character, with the fixed size. It is not dynamic as C++ string. For example, you want to perform strcat(), you need to have a larger buffer to store the strcat() result. And if you want to do it with dynamic memory allocation, then you have to free the memory manually. This is exhaustive.

Object method

Related to method chaining, in C++ we can write the methods. In C, because it is using struct, to implement something like method is troublesome. For example,

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

typedef struct {
    int a;
    int (*b)(int a);
} MyType;

int myTypeMethod(int a) {
    return a+20;
}

MyType* myTypeNew() {
    MyType* myType = (MyType*)malloc(sizeof(MyType));
    myType->a = 20;
    myType->b = myTypeMethod; //There is no method in struct, so we assign the callback function
    return myType;
}

void myTypeDelete(MyType** myType) {
    free(*myType);
    *myType = NULL;
}

int main(int argc, char** argv) {
    MyType* myType = myTypeNew();
    printf("%d\n", myType->a);
    printf("%d\n", myType->b(20));
    myTypeDelete(&myType);
    return 0;
}

Because C doesn’t have namespace, but we can do something like namespace by using prefix.

C++11, C++14, C++1z

If you are not C++ lover, you may think that C++ is an archaic programming language. Just like HTML and JavaScript, there are ongoing proposals for the new features for C++. That is why, C++ is not dying yet. There are some notable features I need to state here.

New syntax

“auto” data type

#include <iostream>
#include <typeinfo>
using namespace std;

int main(int argc, char** argv) {
  int a = 10;
  auto b = a;
  cout << b << endl;
  cout << typeid(b).name() << endl; //"i" as integer
  float c = 20.0f;
  b = c;
  cout << b << endl;
  cout << typeid(b).name() << endl; //Still "i"
  return 0;
}

“auto” is just like “var” in C#.

foreach

Most modern programming languages allows foreach keyword, like JavaScript, PHP, and even Python. Though Python uses “for” keyword, it works actually like foreach in PHP.

#include <iostream>
using namespace std;
int main(int argc, char** argv) {
  int a[] = { 4, 5, 3, 2, 1 };
  for(auto item : a) {
    cout << item << endl;
  }
  return 0;
}

Another foreach,

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char** argv) {
  vector<int> a{ 4, 5, 3, 2, 1 };
  for_each(a.begin(), a.end(), [](auto &item) {
      cout << item << endl;
    });
  return 0;
}

The above code can only be compiled with c++14 standard. If using c++11 standard, we must use “int” instead of “auto”.

Lambda expression

Lambda expression, a.k.a anonymous function. If you are working with JavaScript, such as

var a = [ 4, 5, 3, 2, 1 ];
var found = a.find(function(item) {
    if(item == 2)
        return item;
});

So, the above example shows that the parameter of the find() is a function, without a function name. This is a common syntax in functional programming. Functional programming is a trend of most modern programming language. The anonymous function is also supported by PHP. The advantage of functional programming is the elimination of side effects and avoiding changing state of the data. Therefore, it is a good paradigm for parallel programming.

Therefore, looking at the example above, there is some syntax like,

  ([](int b) {
    cout << b << endl;
  })(12);

Which is similar to JavaScript,

(function(b) {
    console.log(b);
})(12);

In C++, the squared bracket is used to capture the variable of the scope. (I think it is similar to PHP “using” keyword.)

Previously, we can use the callback function like,

#include <iostream>
using namespace std;

int foo(int (*cb)(int, void*), int size, void* data) {
  return cb(size, data);
}

int callback(int size, void* data) {
  int sum = 0;
  int* intData = (int*)data; //typecast
  for(int i=0;i<size;i++) {
    sum += intData[i];
    cout << intData[i] << endl;
  }
  return sum;
}

int main(int argc, char** argv) {
  int a[] = { 4, 5, 3, 2, 1 };
  int sum = foo(callback, 5, a);
  cout << sum << endl;
  return 0;
}

Since we can use anonymous function, we need not to create a callback function like above. This can be written as,

#include <iostream>
using namespace std;

int foo(int (*cb)(int, void*), int size, void* data) {
  return cb(size, data);
}

int main(int argc, char** argv) {
  int a[] = { 4, 5, 3, 2, 1 };
  int result = foo([](int size, void* data) {
      int sum = 0;
      int* intData = (int*)data;
      for(int i=0;i<size;i++) {
        sum+= intData[i];
        cout << intData[i] << endl;
      }
      return sum;
    }, 5, a);
  cout << result << endl;
  return 0;
}

Multi-threading, asynchronous programming, promise

We can implement multi-threading using other libraries like pthread. But with C++11, you can create thread without third party libraries, perform sleep, sleep by milliseconds or even nanoseconds. There is also library for mutex (mutually exclusive).

C++11 also supports asynchronous programming like C# and promise like JavaScript. With the lambda expression, the syntax shares some similarities with C# and JavaScript. With async, we can do something at the background (using thread), and use the result later. With promise, you can promise to return some value, else throw an exception.

Regular expression

Regular expression is so important for text processing. C++11 supports regular expression. There are different regular expression syntax: BRE (basic regular expression) is the default syntax used by “grep” command, ERE (extended regular expression, and Perl regular expression. Perl regular expression is very powerful. If you use Python, JavaScript, Ruby, and C#, you will find that they have different syntax.

However, interestingly C++ uses ECMAScript regular expression syntax by default (though we can choose BRE, ERE, or awk). That means, if you know JavaScript RegExp, then you will have no problem with C++ regex.

(I see the converging features of the different programming languages, which means these features are useful, intuitive, and influential.)

 

Garbage collection

So far, there is no good garbage collection for C++.

 

Another thing I have to state. Because of the networking and big data, parallel programming is a demand and the trend. To make sure the data is immutable, functional programming becomes handy.

Openbox + tint2


Previously I was using Xfce4. Then, because of the heavy working environment, I tried the lighter desktop environment, LXDE. But still, it has some limitations that made me choose to use Openbox window manager only.

Pros and cons of Xfce4

Xfce4 is lightweight comparing to GNOME or KDE. I like it, because of the conventional design like the task manager. Furthermore another thing I like is the “aerosnap” feature like Windows, which I can view the two windows side by side. However, when running Windows in VirtualBox and other applications, I can feel the obvious slowness in the computer. It is really reducing my working performance. That is why I decided to change to LXDE.

Pros and cons of LXDE

LXDE is lighter than Xfce4. So, running a lot of heavy applications does not slow down the computer like Xfce4. But there was one issue I faced. The LXDE pager (workspace) does not allow me to drag and drop the applications to move among the workspaces.

As a result, I decided to use something lighter than Xfce4 and I can drag and drop the applications among the workspaces easily.

Openbox and tint2

I had experienced Openbox with tint2 when I was using my old laptop. Openbox is nice and highly customisable. Tint2 allows me to set number of workspaces, and easily to move the applications to other workspaces. However, tint2 does not have applets or plugins like Xfce4 or LXDE.

There is one feature I need, that is to see CPU usage, so that I know whether there is any application causes high CPU usage. As a result, I installed Conky and display the CPU usage at the corner of the desktop.

Openbox + tint2

Openbox + tint2

Conky

For the Conky, the following is the conky.conf

conky.config = {
    alignment = 'bottom_right',
    background = false,
    border_width = 0,
    cpu_avg_samples = 2,
	default_color = 'white',
    default_outline_color = 'BBBBBB',
    default_shade_color = '444444',
    draw_borders = false,
    draw_graph_borders = false,
    draw_outline = false,
    draw_shades = false,
    use_xft = true,
    font = 'DejaVu Sans Mono:size=1', --by size 1 then only there will have no space after cpugraph
    gap_x = 0,
    gap_y = 2,
    minimum_height = 5,
	minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'desktop',
	own_window_transparent = true,
	own_window_argb_visual = true,
	own_window_argb_value = 255,
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = false,
    show_graph_range = false,
	double_buffer = true,
	imlib_cache_size = 10,
}

conky.text = [[
	${cpugraph 27,40 000000 FFFFFF -l}
]]

Cloud9


Cloud9 is a web-based IDE good for collaboration and online development. You can store your large project on the remote server, and use any computer including netbook with a web browser to develop your system.

Now, the problem I faced when using C9 on my Chromium. Firstly, the address bar, tabs, and bookmarks occupy some space in the window. This results a non-editor look and feel. This makes me feel lacking of something. Secondly, the worst part is the shortcut key like Ctrl+W. By pressing this shortcut key, it will invoke the web browser closing window instead of the C9 shortcut key. Meaning, the shortcut key of the web browser has higher precedence than C9 itself.

I looked for the C9 official Chrome extension, namely Cloud9, but it just works like a bookmark. I tried also Cloud 9 IDE Shortcut. It works better than official Cloud9 Chrome extension. Yet, I need to enter my username and password for the first time. Another drawback is the missing of the window icons like minimize, maximize/restore, and close, and title bar, which results difficulty to resize and maximize/restore.

Looks for some solutions. The easiest way is to invoke

chromium --app=https://ide.c9.io/

Yay! Now I can use the shortcut keys and it looks like native text editor!

Chromium running C9 as app

Chromium running C9 as app

If you are serious, you can write the manifest.json to create the C9 web app, then you can have a custom icon instead of Chromium icon.