##c++string: std lib utilities

Needed for coding IV and GTD

  1. stringstream
  2. cin
  3. vector<char> for sorting and lower_bound
  4. list<char> for splice? could be slow but who cares in a quick coding test? Simpler than swap
  5. iomanip for output to stringstream
  6. vector<std::string>, set<std::string>
  7. getline on stringstream or cin
  8. std::string methods. Some are powerful but unfamiliar
    1. find_last_not_of()
  9. c_str and char array? seldom needed nowadays
Advertisements

y contract is attractive to employers – employment law

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.

c++ compiler to print __cplusplus

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)
#pragma message(VAR_NAME_VALUE(__cplusplus))
—-save above in dummy.cpp—-

g++ -std=c++14 dummy.cpp # shows:
dummy.cpp:7:44: note: #pragma message: __cplusplus=201300L

impressive container dumper #operator<<

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
  • setw()

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/template/containerOutputOperator.cpp

is my tested code



			

goto: justifications

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.

 

search in q[less]

  • In a q(less) screen, You can highlight not only the same AAA occurrences, but AAA or BBB. I used

/Reset|Msg_|Warn_|Primary|Secondary

  • [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

 

warehouse your curiosity google-search,esp.during work hours

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?

spare time utilization: %%strength

Very few peers are so conscious of burn^rot. Higher utilization of spare time is a key strength during my US peak + my dotcom peak + also my high school. We could analyze what’s common and what’s different between these peaks…

Outside those peaks, I also used this strength to complete my UChicago program, but the tangible benefit is smaller.

(This is different from efficiency on the job. Many efficient colleagues spend less time in office but get more done.  My style involves sacrificing personal spare time and family time.)

Looking forward, I guess this strength could be strategic for research-related domains, including any job involving some elements of research and accumulation.

A repeated manager praise for me is “broad-based”, related to this strength.

techies do quit finance

I have seen several cases, for various reasons I may not know so well. I would say not every likes/tolerates the higher pressure, high workload or the lack of creativity in the typical Wall St tech job. Some can get things done but don’t like it.

  • Many Wall St move “higher” to pure tech firms.
  • Y Li moved from M1 (or another telecom firm) to BofA and left after 2 or 3 years.
  • J Ji went to Murex, then some software vendor, then BofA but left after just 1 or 2 years.
  • Park (GS PWM CPDB team) went from Bloomberg to GS, but lasted just 1 year plus. I think he left for some university. He might return to finance.
  • Q Li moved from OC to UOB but didn’t feel good. I think she may join another bank soon.

low budget,high effort projects – avoid^accept

Fanny (the Indian young entrepreneur in Agilent) and Zhang Jun pointed out that if you look for $500 projects you will find them and if you look for $100k projects you will find them too and not much harder.

A Wall St developer isn’t that much more hardworking or smarter than a main-street developer. The effort in a project is not much higher, once you get used to it, but the compensation is much higher.

Now the key thing — in a Wall st IT project team, some parts (like A1) have higher budget in terms of man-day than other parts (like B1) so the B1 guy must work hard to get things done more quickly. Yet unappreciated.

In another unfair situation, A2 and B2 have similar man-day budget but the values are vastly different. Yet the B2 part may have equally stringent requirements. Consider a logger — High performance, high reliability. So the B developer works hard but unappreciated.

eg: I think the commissions team is under-appreciated than trading or pricing teams. Similarly, regulatory, compliance, billing … Yes you can find good reasons to say these are critical and high value, but still their relative values  are lower.

Wall St cod`IV don’t care about efficiency

Most challenging algo interviews (onsite) are really about “solve it by hook or by crook” regardless of efficiency. (Usually there isn't, but if there's an obvious brute-force solution it gives you no credit anyway.)

In the toughest algo questions, usually there's no memory capacity issue to worry about.
Occasionally, interviewer stipulates O(N logN) or O(1)
Once we solve it we can improve efficiency. It's a second phase. Can be easier than first phase.
In that case threading, sorting … are unimportant. Instead we need judicious use of trees, recursions, pattern recognition… and very clear thinking.
See [[EPI300]] and the green book by Zhou Xinfeng

worked harder as FTE than contractor@@

My experience – in terms of work attitude, professionalism, ownership, my contractor jobs was not really lower than FTE. However, longer hours were rare. When I work longer hours as contractors, manager often recognize more easily.

Personal sacrifice was lower.

Ownership of project is often with FTE.

Expectation of bonus is real as FTE.

All in all, the bitterness (and pain, blow to self-esteem…) of a poor appraisal and low bonus is deep, hard, pervasive. It last many months and is a bigger stress than marriage issues, kids poor studies, investment failures etc. I was “shaken to core” (Michelle Obama once said) by those events.

Generally I choose to work at slightly higher than the minimum level to get by.

  • as contractor — sometimes this hurts me (Citi) but often my standard is well above the manager’s
  • as FTE — I don’t like to work way harder than the minimum, because often (Stirt, GS) it’s still not good enough for various reasons, so I would feel “not worth it”.
  • I also have a conviction that managers decide which FTE they like based on non-technical reasons, so why bother to work so hard? If manager doesn’t like me then hard work won’t help a lot.

establish tech stronghold(GTD+nlg)]each team

Note – focus is job performance, not IV.

To survive in a team,need unique technical specialty in a key area.

With the possible exception of the Citi Muni team, I have not seen a banking IT team to tolerate a “dead weight” guy. To do reasonably well in any financial IT team, I often need some “hard” strength (like an subject matter expertise), not just soft skill. If within your team you have a unique technical strength in a complex and important sub-system, then you can “name your price”, and you are kind of irreplaceable. Perhaps a go-to person. Some team members don’t have any expertise but survive on strong relationships. I’m unable to do that. In the past teams, I think many team members have such a strength. If I don’t have it, my position would be less established, less solid.

  • 😦 😦 stirt? Worst experience. Was good at the insignificant preferences framework; canceled trades
  • 😦 GS? Uncomfortable position. My Perl was not top notch. My java was below Yang. I became good at Error Memos (EOS) and trailers/upfronts
  • 🙂 OC? was good at Bloomberg adapter and Guardian builtin web server to show the log files
  • 🙂 🙂 95 Green? My DB design was convincing to Ravi. My wait-notify based design was pretty hard to match.
  • 🙂 Barc? FMD, fmath
  • 😦 Macquarie? In the quant team, whatever I accomplish seems trivial to manager, since he’s too strong. I’m seen as very slow on small tasks.

tech strength^weak, as@Nov2016

My strengths – quick but more than superficial learning of (in random order):

  • finmath, financial jargon,
  • Comp Science practical topics:
    • OO fundamentals
    • algo, data structures,
    • threading
    • basic tuning of DB + others
  • language fundamentals (more respected in the java, c++, c#, SQL than python communities)
    • versatile in many important languages
  • relative familiarity with scripting, unix, SQL, but not IDE, version control etc
  • relatively quick whiteboard (not compiler) coding

This strength turned out to be extremely valuable on Wall St consulting market.

My key weakness identified in recent jobs (not counting the IV defeats):

  • learning local system
  • large existing codebase – AutoReo, GS
  • superfast GTD

%%logging decorator with optional args

Latest is Uploaded to github: https://github.com/tiger40490/repo1/blob/py1/py/loggingDecorator.py

I hope the wordpress code formatting renders the source code correctly:

def log3(funcOrMsg=None, named_arg=None):
    '''arg is Optional. You can use any of:
    @log3(named_arg='specific msg') # some prefer named argument for clarity
    @log3('msg2') or
    @log3
    '''
    arg1_isCallable = callable(funcOrMsg)
    arg1_isStr      = isinstance(funcOrMsg, basestring)
    arg1_isNone     = funcOrMsg is None

    def decorated(func):

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            if named_arg: print 'named_arg = ' + str(named_arg)
            tmp = funcOrMsg if arg1_isStr else ''
            logger.info(tmp + ' pym ver = ' + str(logger.pymodelsVer),
              extra={'name_override' : func.__name__})
              ### set name_override to func.__name__ in a kwarg to info()
            return func(*args, **kwargs)
        return wrapper
        ## end wrapper

    if arg1_isCallable:
        return decorated(funcOrMsg) # decorator received no-arg
    else:
        # decorator had kwargs   or   positional arg
        assert     arg1_isNone   or   arg1_isStr
        return decorated

avoid unsigned-int type if you ever test for positiveness

Beware in coding tests…

Even though unsigend types are self-documenting, Google style guide advises against unsigned int types as they are error-prone.

When I use size_t as a loop control variable, I need to avoid decrementing it below 0, which is something like undefined behavior for me.

size_t sz=myMap.size();
for(int i=0; i<sz-N; ++i) //sz-N can overflow to a very large number!

## c++topics seldom quizzed

(master -> pearl)
some low-level details I thought would be popular but seldom asked:
* L-value
* iterator types and implementations
* static variables outside classes
* implicit acts of magic by compiler
* array and cStr – syntax, memory, … the gory details beyond the basics
* template specialization
* ref/pointer typedef inside  templates
* non-dummy-type args in template
* MI
* enum
* exception spec
* C integration
* pimp
* fwd declaration
* namespace
* linker
* extern
* double pointers
* hiding rule
* swap – all the important usages and no-fail
* overloading and  method resolution
* casting and conversion
*** OOC and  conversion ctor
— “mid-level”
* boost Any vs Variant
* i/o stream
* regex
* file access (including random)
* serialization
* memory leak detection
* details of boost thread
* boost smart pointer beyond the shared_ptr
* std::string details