This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
char *name; | |
size_t len; | |
int value; | |
} option_t; | |
void display_cmd_fn(option_t opt); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#define DEFER(func) __attribute__((__cleanup__(func))) | |
static void free_char(char **p) { | |
if (p == NULL) return; | |
if (*p == NULL) return; | |
free(*p); | |
*p = NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define macro_var(name) name##__LINE__ | |
#define defer(start, end) for ( \ | |
int macro_var(_i_) = (start, 0); \ | |
!macro_var(_i_); \ | |
(macro_var(_i_) += 1), end) \ | |
/** | |
Example usage: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# allows user to git show by the number the commit appears in git log | |
# 1 is the first commit, 2 is the second, etc... | |
git_show() { | |
re='^[0-9]+$' | |
if ! [[ $1 =~ $re ]]; then | |
return | |
fi | |
sha="$(git log -$1 --format="%H")" | |
shaSplit=(${sha//\n/ }) | |
git show ${shaSplit[$(($1 - 1))]} |