使用Gii生成的CountrySearch不能使用的问题

When I following the steps in http://www.yiiframework.com/doc-2.0/guide-start-gii.html .
try to generate some CRUD operate for country table.
I following the details steps which tutorial told. but when I visit http://localhost/index.php?r=country%2Findex , I got below exception.

1
The table does not exist: {{%country_search}}

The reason why this exception throws. Because Yii2 assume there exist
country_search table in you MySQL, but if you look inside you code, the
CountrySearch extends from Country, so it should use the same table as Country
class. what you should do to fix this issue. you only need create a tableName
method to tell Yii2 which table name need to use.

1
2
3
4
 public static function tableName()
{
return "Country";
}

使用boost的bind

#include <algorithm>
#include <map>
#include <iostream>
#include "boost/bind.hpp"

using namespace std;

void printPair(const pair<int, int>& elem)
{
  cout << elem.first << "->" << elem.second << endl;
}

class Test {

public:
Test() {
  myMap.insert(make_pair(4, 40));
  myMap.insert(make_pair(5, 50));
  myMap.insert(make_pair(6, 60));
  myMap.insert(make_pair(7, 70));
  myMap.insert(make_pair(8, 80));
}

void printResult() {
  int a = 10;
  //using static method with two argument
  for_each(myMap.begin(), myMap.end(), boost::bind(&Test::printPair, _1, a)); 
  //using static method with one argument
  for_each(myMap.begin(), myMap.end(), boost::bind(&Test::printPair2, _1)); 
  //using instance method
  for_each(myMap.begin(), myMap.end(), boost::bind(&Test::printPair3,  boost::ref(*this), _1)); 
}

static void printPair(const pair<int, int>& elem, int a)
{
  cout << elem.first << "->" << elem.second << ";a=" << a << endl;
}

static void printPair2(const pair<int, int>& elem)
{
  cout << elem.first << "2->" << elem.second <<  endl;
}

void printPair3(const pair<int, int>& elem)
{
  cout << elem.first << "3->" << elem.second <<  endl;
}



private:
  map<int, int> myMap;
};

int f(int a, int b) {
    return a - b;
}

int main(int argc, char** argv)
{
  map<int, int> myMap;
  myMap.insert(make_pair(4, 40));
  myMap.insert(make_pair(5, 50));
  myMap.insert(make_pair(6, 60));
  myMap.insert(make_pair(7, 70));
  myMap.insert(make_pair(8, 80));

  for_each(myMap.begin(), myMap.end(), &printPair); 
  Test t;
  t.printResult();

  //using bind create a new method then call it with 1
  int c = boost::bind(f, _1, 2)(1); 
  std::cout << "c:" << c << endl;

  c = boost::bind(f, 10, _1)(1); 
  std::cout << "c:" << c << endl;

  //exchange the argument
  c = boost::bind(f, _2, _1)(1, 2); 
  std::cout << "c:" << c << endl;
  return (0);
}

如何让git使用vim而不是vi

我的vim有很多配置,每次使用git提交时,总是提示说一些配置不能正确加载。
google了以下发现,git默认使用的vi而不是vim来编辑提交信息的。
可以使用以下命令来修改git的default editor

  • git config –global core.editor “vim”

当使用vim编辑commit msg时,希望直接退出,而不是退出后提交

当使用vim编辑commit msg时,如果我们按正常的:wq,退出vim,git后自动提交。
但是有时候我们希望直接退出并且不进行本次修改的提交。
怎么办呢?
两种方法:

  • 提供一个空的提交信息,并退出,仓库一般都会检测提交是否有描述,如果没有,提交会失败。
  • 让vim异常退出。可以kill掉vim或者使用:cq (quit with an error code)

引用

Knowing yourself -- From Beyond Feeling

Knowing yourself
你能如实回答如下的问题吗?能的话,回答之后,好好反省。
Am I quiet or talkative?
Generally optimistic or pessimistic?
Hard-working or lazy?
Fearful or brave?
Serious or easygoing? Modest or proud?
Competitive or noncompetitive?
Am I nervous or at ease with strangers?
Do I retain my poise and presence of mind in emergencies?
Am I confident in everything I do?
Do I resent certain types of people (the popular classmate,for example)?
Would I be more accurately classified as a leader or a follower?

How trustworthy am I?
Can I keep a secret, or must I reveal it to at least one or two others?
Am I loyal to my friends? Do I ever use people?
How sensitive am I to the feelings of others?
Do I ever purposely hurt others?
Am I jealous of anyone?
Do I enjoy causing trouble?
Do I sow seeds of suspicion and dissension among people?
Do I rush to spread the latest gossip?
Do I talk behind friends’ backs?
Are my comments about others usually favorable or unfavorable?
Do I criticize other’s real or imagined faults as a means of boosting my own
ego?
Do I keep my promises?
How tolerant am I of people’s faults and mistakes?

Am I truthful with other people? With myself?
How objective am I in assessing my skills and talents?
How intelligent am I?
How studious(hard) am I in school?
How many different roles do I play with other people?
Which of those roles are authentic(real)?
Which roles are masks designed to hide aspects of myself I would be ashamed or
embarrassed to have others see?
How reasonable are my plans for the future?
Do I work well under pressure?

Critical Thinking Inventory

  1. 只有先了解自己,才能前进. 很多人活了一辈子,连自己的优势,劣势都没有分清楚.
  2. Exactly what influences have shaped my identity? How have they done so?
    How has my self-image been affected? In what situations am I less an
    individual because of these influences?

  3. In what ways am I like the good thinker (as outlined in Chapter 2)?
    In what ways like the poor thinker? What kinds of situations seem to bring out
    my best and worst qualities?

  4. To what extent has my perspective on truth been reasonable? (Refer to Chapter 3 if necessary.)

  5. How careful am I about separating hearsay and rumor from fact?
    About distinguishing the known from assumptions or guesses? How difficult is
    it for me to say “I don’t know”?

  6. How consistent am I in taking the trouble to make my opinions informed?

  7. To what extent do I think that “mine is better” (not only the personal “mine” but the ethnocentric “mine” as well)?
    In what ways has this kind of thinking affected my view of personal problems
    and public issues?
    To what extent does it affect my ability to listen to those who disagree with
    me?
    My ability to control my emotions? My willingness to change my mind and revise
    a judgment?

  8. In what matters am I inclined to assume too much, take too much for granted?

  9. To what degree do I tend to have the either/or outlook, expecting that the right answer will always be extreme and never moderate?
  10. To what or to whom do I feel the strongest urge to conform? In what situations has this conformist tendency interfered with my judgment?
  11. Do I tend to be an absolutist, demanding that truth be neat and simple, or a relativist, claiming that everyone creates his or her own truth?
    In what ways has my characteristic tendency hindered my development as a
    critical thinker?

  12. In what matters am I most biased toward change? Am I overly accepting of change or overly resistant to it?
    What is the cause of this tendency and how can I best control it?

  13. In what situations do I seek to confirm my biases rather than control them?
    In what situations do I interpret evidence in a way that flatters my bias?

  14. How often do I approach issues with a double standard, overlooking flaws in arguments that agree with mine and nitpicking those that disagree?

  15. To what extent do I tend to jump to conclusions?
    Do I tend to do so more in certain areas? If so, which?
    Do I draw my conclusions prematurely purely for the sake of convenience?
    Am I motivated by the desire to sound authoritative and impress people?

  16. To what extent do I overgeneralize?
    What kinds of stereotypes do I most readily accept? Racial? Religious? Ethnic?

  17. To what extent do I oversimplify complex matters?
    Am I simply unwilling to take the trouble to learn the truth in its
    complexity?
    Or do I feel threatened by answers that are not neat and tidy? What has made
    me this way?

  18. What errors of expression do I most often commit?
    Reasoning that if B follows A, A must be the cause of B? Shifting the issue to
    avoid difficult or embarrassing discussions?
    Contradicting myself? Arguing in a circle? Making meaningless statements?
    Confusing real with bogus(false) authorities? Making false analogies? Using
    irrational appeals?

  19. Which of the following errors are most characteristic of my responses to challenges and criticism of my ideas:
    automatic rejection? shifting the burden of proof? straw man? attacking the
    critic rather than discussing the issue?

使用tcmalloc,它的central freelist很多,一直没有释放

在项目中,使用到了tcmalloc作为自己的内存分配库,但是使用了一段时间后,发现central freelist中的内存一直没有释放给系统。

最后检查了一下,发现原因是:

tcmalloc事先后分配一大块内存,减少分配内存的系统调用,每次会根据需要分配一个或多个page;

central freelist是用span管理的,一个span是多个page,

thread cache 中使用的小内存会从span中割一块,导致span的引用计数加1。

出现 central
freelist中用很多内存,但是就是释放不了,原因就是span的引用计数没有归零,倒是tcmalloc没有将整个span释放给系统。

解决方法:

1. 不使用cache,将用- DSMALL_BUT_SLOW 将 tcmalloc从新编译一遍;

2. 检查自己的代码,看看那些地方的连续内存,只释放了一部分。

参见:

http://blog.csdn.net/lantianjialiang/article/details/50510890

https://groups.google.com/forum/#!topic/google-perftools/glLYD1o2_-U