grub didn’t detect windows

I installed parabola GNU/Linux alongside windows 7 recently. After a reboot, I couldn’t see the Windows entry. I did install os-prober before installing grub.

Then I figured there must be something wrong with the grub installation, so I reinstalled grub, but still no luck.

OK, I know you don’t really enjoy the story, you’re here for the solution, I just want you to make sure that your situation is quite similar to mine. And here the answer is:

1, mount the partition where Windows exists.

2, run os-prober, if you didn’t install it, now is the time. It should detect you windows now.

3, reinstall grub or regenerate grub configuration file.

There you go, you have your windows entry back.

The point is, you have to mount the partition first for os-prober to detect your windows.

为什么是乐天?

因为萨德的原因,乐天被很多中国民众抵制,乐天也是受到了实实在在的损失。但突然想到,整个萨德事件,美国是主犯,韩国是帮凶,乐天只是个小跟班,小喽喽。按道理,最该被抵制的应该是领头的那个,美国,但偏偏是乐天这个小跟班成了众矢之的,为什么?

我个人想到以下两点:

1,老大们实力太大。中国不可能直接抵制美韩,停止与它们的经济往来。但你乐天这个小跟班就不行了,没了你我一样过,不收拾你收拾谁?!

2,与实力不符的态度。萨德系统必不是一个乐天提供一个地皮就能部署得起来的系统, 我相信萨德的部署会有很多韩国公司、集团、组织的参与。它们都保持了低调,没有招来抵制。惟有乐天表示,即使遭受重大损失,也要配合政府部署萨德。连美韩都说,这是用来对付朝鲜的,以避免刺激中国。乐天这强硬的挑衅态度成功地激怒了中国民众。又一例祸从口出。

以上两点,乐天实力不够,还表现了与实力不符的态度,成为众矢之的也是必然,活该遭受损失。

design pattern note

The best way to use patterns is to load your brain with them and then recognize places in your designs and existing applications where you can apply them.

Design Principle    Identify the aspects of your application that vary and seperate them from what stays the same.

All ptterns provide a way to let some port of a system vary indepentently of all other parts.

Design Principle    Program to an interface, not an implementation.

Design Principle    Favor composition over inheritance.

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

Design Principle   Strive for loosely coupled designs between objects that interact.

Design Principle  Classes shoud be open for extension, but close for modification.

The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

leetcode 537. Complex Number Multiplication

Orignal question can be found here.

My solution is as follows:

char* complexNumberMultiply(char* a, char* b)
{
  int a_real, a_vir, b_real, b_vir;
  char *result = (char *) malloc(1024 * sizeof(char));
  sscanf(a, "%d+%di", &a_real, &a_vir);
  sscanf(b, "%d+%di", &b_real, &b_vir);
  sprintf(result, "%d+%di", a_real *  b_real - a_vir * b_vir, a_real * b_vir + a_vir * b_real);
  return result;
}

leetcode 482. License Key Formatting

Orignal question can be found here.

My solution is as follows:

char* licenseKeyFormatting(char* S, int K)
{
  int s_len = strlen(S);
  int len = 0;
  for(int i=0; i<s_len; ++i)
    {
      if(S[i] != '-')
        ++len;
    }
  int result_len = 0;
  int cur = 0;
  if(len<=K)
    {
      char *res = (char *)malloc((len+1) * sizeof(char));
      res[len] = 0;
      for(int i=0; i<s_len; ++i)
        {
          if(S[i] != '-')
            {
              if(S[i]>='a' && S[i]<='z')
                res[cur] = S[i] - 'a' + 'A';
              else
                res[cur] = S[i];
              ++cur;
            }
        }
      return res;
    }
  if(len%K== 0)
    result_len = len/K+len-1;
  else
    result_len = len/K+len;
  char *result = (char *)malloc((result_len+1) * sizeof(char));
  result[result_len] = 0;

  cur = 0;
  for(int i=s_len-1; i>=0; --i)
    {
      if(S[i] != '-')
        {
          if((cur+1)%(K+1) == 0)
            {
              result[result_len - 1 - cur] = '-';
              ++cur;
            }
          if(S[i]>='a' && S[i]<='z')
            result[result_len -1 - cur] = S[i] - 'a' + 'A';
          else
            result[result_len -1 - cur] = S[i];
          ++cur;
        }
    }
  return result;
}

leetcode 94. Binary Tree Inorder Traversal

Orignal question can be found here.

My solution is as follows:

int* inorderTraversal(struct TreeNode* root, int* returnSize)
{
        int* result=(int*)malloc(sizeof(int)*512);
        *returnSize=0;
        if(root == NULL)
                return result;
        inorderTraversalCore(root, result, returnSize);
        return result;
}

void inorderTraversalCore(struct TreeNode* root, int* array, int* returnSize)
{
        if(root->left != NULL)
                      inorderTraversalCore(root->left, array, returnSize);
        array[*returnSize] = root->val;
        ++(*returnSize);
        if(root->right != NULL)
                       inorderTraversalCore(root->right, array, returnSize);
}

leetcode 404. Sum of Left Leaves

Orignal question can be found here.

My solution is as follows:

int sumOfLeftLeaves(struct TreeNode* root)
{
  int result = 0;
  int *result_p = &result;
  sumCore(root, 0, result_p);
  return result;
}

void sumCore(struct TreeNode* root, int flag, int *result_p)
{
  if(root == NULL)
    return;
  if(flag==1 && root->left==NULL && root->right==NULL)
    {
      *result_p += root->val;
      return;
    }
  if(root->left != NULL)
    sumCore(root->left, 1, result_p);
  if(root->right != NULL)
    sumCore(root->right, 0, result_p);
}

leetcode 409. Longest Palindrome

Orignal question can be found here.

My solution is as follows:

int longestPalindrome(char* s)
{
  int result = 0;
  int one_more = 0;
  int hash[52]={0};
  for (int i=0; i<strlen(s); ++i)
    {
      if(s[i]>='a' && s[i]<='z')
        ++hash[s[i]-'a'];
      else if(s[i]>='A' && s[i]<='Z')
        ++hash[s[i]-'A'+26];
    }
  for (int i=0; i<52; ++i)
    {
      if(hash[i]%2 == 1)
        one_more = 1;
      result += (hash[i]/2)*2;
    }
  if(one_more == 1)
    ++result;
  return result;
}