Skip to content

Instantly share code, notes, and snippets.

@redbug312
Last active April 16, 2016 05:02
Show Gist options
  • Save redbug312/39949b8a2f99921b7bb0d11ff21b84da to your computer and use it in GitHub Desktop.
Save redbug312/39949b8a2f99921b7bb0d11ff21b84da to your computer and use it in GitHub Desktop.
My C++ Snippets for Visual Studio Code.
{
"Local Debug": {
"prefix": "DEBUG",
"body": [
"#define FLAG fprintf(stderr,\"\\033[32;1m#FLAG\\033[0m\\n\");",
"#define BIN(x) {fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = \"); \\",
"\tfor(int i=15;i>=0;--i)fprintf(stderr,\"%c\",((x)&(1<<i))?'1':'0'); \\",
"\tfprintf(stderr,\"\\n\");}",
"#define INT(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %d\\n\", x);",
"#define CHR(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %c\\n\", x);",
"#define STR(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %s\\n\", x);",
"#define PTR(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %p\\n\", x);",
"#define ARR(x,len) {fprintf(stderr, \" \\033[33;1m#DEBUG:\\033[0m \"); \\",
"\tfor(int i=0;i<len;++i)fprintf(stderr,\"%5d%c\",x[i],\" \\n\"[(i+1)%8==0||i==len-1]);}",
"#define VEC(x) {fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"); \\",
"\tfor(int i=0;i<(int)x.size();++i)fprintf(stderr,\"%5d%c\",x.at(i),\" \\n\"[(i+1)%8==0||i==(int)x.size()-1]);}"
],
"description": "Define common checking macros to debug"
},
"Compare Function": {
"prefix": "CMP",
"body": [
"\nint cmp(const void *pA, const void *pB)",
"{",
"\tint A = *(int *)pA, B = *(int *)pB;",
"\tif(A == B) return 0;",
"\telse return (A < B) ?-1 :1 ;",
"} // qsort(base, num, size, comparetor)\n"
],
"description": "Simple non-decreasing integer comparing function for qsort"
},
"Timer ": {
"prefix": "TIMER",
"body": [
"clock_t begin, end;",
"double timeCnt;",
"begin = clock();",
"/* program to test */",
"end = clock();",
"timeCnt = (double)(end - begin) / CLOCKS_PER_SEC;",
"fprintf(stderr, \"Time: %lf sec\\n\", timeCnt);\n"
],
"description": "Test the time the program spent. <ctime> inclusion needed."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment