Needed for coding IV and GTD
- vector<char> for sorting and
- list<char> for splice? could be slow but who cares in a quick coding test? Simpler than swap
- iomanip for output to stringstream
- vector<std::string>, set<std::string>
- getline on stringstream or cin
- std::string methods. Some are powerful but unfamiliar
- c_str and char array? seldom needed nowadays
Genn told a real story in her firm — An old senior officer was demoted twice but he still refuse to resign.
Q: Why the individual has upper hand over the employer? Because the employment law protects the individual.
Companies can’t easily lay off employees. That’s one reason contract is a popular among employers.
Based on http://stackoverflow.com/questions/1562074/how-do-i-show-the-value-of-a-define-at-compile-time:
#define VALUE(x) #x
#define VAR_NAME_VALUE(var) #var “=” VALUE(var)
—-save above in dummy.cpp—-
g++ -std=c++14 dummy.cpp # shows:
dummy.cpp:7:44: note: #pragma message: __cplusplus=201300L
Compared to the standard dump(), This is slightly harder to write but convenient to use and impressive in an interview:
- operator template, agnostic of the payload type
- operator overload
To support other containers beside list, you can copy paste this function and change the 2nd arg type. Thanks to the auto keyword, nothing else needs change.
When I attempted to consolidate to a single function template to handle all container types, then cout<<“any_string” also picks up this function inadvertently 😦
https://github.com/tiger40490/repo1/blob/cpp1/cpp/88miscLang/containerDumpOperator.cpp is my tested code
Best-known use case: break out of deeply nested for/while blocks.
- Alternative — extract into a function and use early return instead of goto. If you need “goto: CleanUp”, then you can extract the cleanup block into a function returning the same data type and replace the goto with “return cleanup()”
- Alternative — extract the cleanup block into a void function and replace the goto with a call to cleanup()
- Alternative (easiest) — exit or throw exception
Sometimes none of the alternatives are easy. To refactor the code to avoid goto requires too much testing, approval and release. The code is in a critical module in production. Laser surgery is preferred — introduce goto.
- In a q(less) screen, You can highlight not only the same AAA occurrences, but AAA or BBB. I used
- [2/3] /ctrl-R — search without metacharacters
- -i, then /needle — case insensitive
[3/4] means vi/less receives 3 keystrokes; we hit 4 keys including shift or ctrl …
–search can fail with super-long lines. See also http://www.greenwoodsoftware.com/less/bugs.html
- Symptom — if you navigate to the correct region of the big text file, then the search does hit the target word.
- Solution — use grep to confirm
Many people have a habit — immediately search on-line when a particular news catches their attention. Or it could be a name, a product, a jargon, a fact, a number, a question, something search-able, but something not related to their immediate task and don’t require immediate investigation.
If we warehouse the curiosity, very often we realize that topic is not worth searching. This is similar to a help desk’s internal policy:
Depending on the urgency, wait N minutes before reacting to a request. When you do reach out to the user, she will likely need it less urgently than if you ask her now.
Statistics — when I look back at my google searches, most of them are low value and no urgency. I wonder if you can ask google to show your own search history.
This rule requires self-discipline, something most adults and kids lack.
This rule applies not only during office hours. It applies whenever you need concentration. Non-trivial learning is one major area affected.
How do we warehouse? Write it on a piece of paper?