converting btw epoch, HHMMSS ..

  • Note epoch is second-level, not millisecond level.
  • Note epoch is timezone agnostics. It’s always defined in the UTC.
  • Note struct tm is the workhorse. It can break up a time object into the year/weekday/…/second components

–to convert from epoch to HHMMSS:
time_t tt = secSinceEpoch_as_integer;
time_t tt = time(NULL); //Or you can get current time
struct tm * ptm = gmtime(&tt);


c++split string on custom delimiter char

For a longer delimiter, you may need string.find()

ifstream f1(fileName.c_str());
string line;
while(getline(f1, line)){
  for(int i=1; ;++i){
        int pos = line.find_first_of("\t");
        string token = line.substr(0,pos);
        cerr<<i<<" : " <<token<<endl;
        if (line == token) break; //there's no more tab in the line
        line = line.substr(pos + 1);

binary search in sorted vector of Tick pointer

Note the mismatched args to the comparitor functions.

(I was unable to use a functor class.)

std::vector<Tick const*> vec;
int target;
bool mylessFunc(Tick const * tick, unsigned int target) {
     //cout<<tick->ts<<" against "<<target<<endl; 
     return tick-ts < target;
lower_bound(vec.begin(),vec.end(),target, mylessFunc);

bool mygreaterFunc(unsigned int target, Tick const * tick){
     //cout<<a->ts<<" against "<<target<<endl; 
     return tick->ts > target;
upper_bound(vec.begin(),vec.end(),target, mygreaterFunc)

## vi/less cheatsheet

  • ~~~~ command mode #roughly ranked
  • [3] dt — “dta” delete until the next “a”
  • R — Overwrite each character one by one until end of line. Useful if the replacement content is similar to original?
  • [2] 9s — wipe out 9 characters (including current) and enter insert-mode. Better than R when you know how many chars (9) to change
  • C — wipe out from cursor to END of line and puts you into insert-mode
  • A — to append at END of current line
  • capital O — open new line above cursor
  • Ctrl-R to re-do
  • from inside q(LESS), type a single “v” to launch vi
  • [1] ctrl-^ — to switch to “the other file”
  • [3] :e# — is same
  • cw — wipe out from cursor to end of word and puts you into insert mode
    • c2w or 2cw
  • no simple command to delete 5 characters

–paging commands in vi and less

  • jump to end of file: capital G == in both vi and LESS
  • jump to head of file: 1G == in both vi and LESS
  • page dn: Ctrl-f == in both; LESS also uses space
  • page up: Ctrl-b == in both; LESS also uses b

— now q(less)

  • [3] /ctrl-R — search without metacharacters

[3] means vi receives 3 keystrokes