/** based on this solution: http://stackoverflow.com/a/10966395 */ /** Macros to auto-generate enum and to string function */ #define GENERATE_ENUM_LINE(PREFIX, ENUM) PREFIX##_##ENUM, #define GENERATE_ENUM_CASE_STRING(PREFIX, ENUM) case PREFIX##_##ENUM: return #ENUM; #define GENERATE_ENUM(NAME, MEMBERS) \ enum NAME { MEMBERS(NAME, GENERATE_ENUM_LINE) }; \ static const char * NAME##String (enum NAME e) \ { \ switch (e) { MEMBERS(NAME, GENERATE_ENUM_CASE_STRING) } \ return("Unknown Type"); \ } /** define enum */ #define FRUIT_ENUM_MEMBERS(NAME, FRUIT) \ FRUIT(NAME, apple) \ FRUIT(NAME, orange) \ FRUIT(NAME, grape) \ FRUIT(NAME, banana) /** and then generate it */ GENERATE_ENUM(fruitEnum, FRUIT_ENUM_MEMBERS) /** use enum and string converter */ #include <stdio.h> int main() { enum fruitEnum e; e = fruitEnum_apple; printf("e = %s\n", fruitEnumString(e)); e = fruitEnum_apple; printf("e = %s\n", fruitEnumString(e)); e = fruitEnum_orange; printf("e = %s\n", fruitEnumString(e)); e = fruitEnum_grape; printf("e = %s\n", fruitEnumString(e)); e = fruitEnum_banana; printf("e = %s\n", fruitEnumString(e)); e = -1; printf("e = %s\n", fruitEnumString(e)); return 0; }
ColorBrewer
Color advice for maps: http://colorbrewer2.org/
Choosing the right estimator
Multi-Dimensional Bresenham Line in C++
Implementation of a multi-dimensional Bresenham Line algorithm in C++ using STL.
#include <vector> /** Multi-dimenstional Bresenham line algorithm */ std::vector< std::vector <int> > Bresenham(std::vector<int> &from, std::vector<int> &to) { std::vector<int> current; for (size_t i=0; i<from.size(); i++) current.push_back(from[i]); std::vector<int> diff; for (size_t i=0; i<from.size(); i++) diff.push_back(to[i] - from[i]); int num_steps = 0; for (size_t i=0; i<diff.size(); i++) num_steps = std::max(num_steps, (int)floor(std::abs(diff[i]))); std::vector<int> step; for (size_t i=0; i<diff.size(); i++) step.push_back(diff[i]/num_steps); std::vector< std::vector <int> > output; for (int i=0; i<num_steps; i++) { std::vector pt; for (size_t j=0; j<current.size(); j++) pt.push_back(floor(current[j])); output.push_back(pt); for (size_t j=0; j<current.size(); j++) current[j] = current[j] + step[j]; } return output; }
Fast key repeat rate
On Windows 7:
On Linux:
xset r rate DELAY RATE
This works for me:
- delay: 150 ms
- rate: 15 ms
On Mac OSX
echo "Set a fast keyboard repeat rate, " defaults write NSGlobalDomain KeyRepeat -int 1 echo "Set a shorter Delay until key repeat" defaults write NSGlobalDomain InitialKeyRepeat -int 12
thread debugging
Valgrind has a thread error detector:
http://valgrind.org/docs/manual/drd-manual.html
mutrace measures mutex contention
http://0pointer.de/blog/projects/mutrace.html
LTTng has a lot of cool features too.
System tap looks interesting too:
https://sourceware.org/systemtap/
c++ reflection
I just found these 3 links. Haven’t tested them yet.
http://root.cern.ch/drupal/content/reflex
http://www.extreme.indiana.edu/reflcpp/
http://www.ischo.com/xrtti/index.html
Cool page about radar
parsing options using libc’s argp
For the longest time I used getopt to parse options in my C/C++ programs. Only today I discovered argp.h (which is a part of GNU libc). argp adds documentation line for each flag in long options as well as formats a help message for you. Below is a link and a quick example
http://www.gnu.org/software/libc/manual/html_node/Argp-Example-3.html#Argp-Example-3
ssh escape sequence
Help sequence is:
ENTER ~?
This will output available options:
user@host:~$ ~? Supported escape sequences: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~C - open a command line ~R - Request rekey (SSH protocol 2 only) ~^Z - suspend ssh ~# - list forwarded connections ~& - background ssh (when waiting for connections to terminate) ~? - this message ~~ - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.)