This file contains 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
#!/bin/bash | |
shopt -s extglob | |
SCRIPT_NAME="$(basename $0)" | |
LOG_FILE="${0%.*}.log" | |
DATE_FORMAT="%F %H:%M:%S %z" | |
PID_MAX="$(cat /proc/sys/kernel/pid_max)" |
This file contains 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
int ** int2dArray(int row, int col) { | |
int i, **ret = (int **) malloc(sizeof(int *) * row + sizeof(int) * row * col); | |
for (i = 1, ret[0] = (int *)(ret + row); i < row; ++i) { | |
ret[i] = ret[i-1] + col; | |
} | |
return ret; | |
} |
This file contains 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
int* getReturnColumnSizes(int row, int col) { | |
int* returnColumnSizes = (int*) malloc(sizeof(int) * 1 * row); | |
for (int i=0; i<row; i++) { | |
returnColumnSizes[i] = col; | |
} | |
return returnColumnSizes; | |
} |
This file contains 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
int listReverse(struct ListNode** head) { | |
int node_count = 0; | |
struct ListNode *tmp = NULL, *walker = *head; | |
if (walker != NULL) { | |
node_count = 1; | |
while (walker->next != NULL) { | |
tmp = walker->next; | |
walker->next = tmp->next; | |
tmp->next = *head; |
This file contains 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
char ***char3dArray(int length, int width, int height) { | |
// ret[height][width][length] | |
char ***ret = (char ***) malloc(sizeof(char **) * height + sizeof(char *) * height * width + sizeof(char) * height * width * length); | |
char **first_row = (char **)(ret + height); | |
char *first = (char *)(first_row + height * width); | |
memset(first, 0, sizeof(char) * height * width * length); | |
for (int i=0, j, wl = width * length; i<height; ++i) { | |
ret[i] = first_row + i * width; |
This file contains 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
void doFree(void * allocate, ...) { | |
void *target = allocate; | |
va_list args; | |
va_start(args, allocate); | |
while (target != NULL) { | |
free(target); | |
target = va_arg(args, void *); | |
} |
This file contains 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
int compare(const void *a, const void *b) { | |
const char *aa = *(const char **)a; | |
const char *bb = *(const char **)b; | |
return strcmp(aa, bb); | |
} | |
qsort(strings, stringsSize, sizeof(char *), compare); |