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 <stdint.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| uint16_t compile(const char *prog, uint8_t *tape, uint16_t tape_len, uint8_t **idx, uint8_t eval) { | |
| uint16_t elapsed = 1; | |
| while(*prog) { | |
| uint16_t traveled = 1; |
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
| int match(const char *needle, const char *haystack) { | |
| while(*haystack || *needle) { | |
| if(*needle == '*') { | |
| if(*(needle + 1) == '\0') { | |
| return 1; | |
| } else if(*(needle + 1) == '*') { | |
| needle += 1; | |
| } else if(*(needle + 1) == *haystack) { | |
| needle += 1; | |
| } else if(*haystack == '\0') { |
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 <ctype.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| int main(int argc, char **argv) { | |
| for(argc -= 1, argv += 1; *argv; argc -= 1, argv += 1) { | |
| char *idx = *argv; | |
| char *begin = NULL; | |
| char *end = 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
| #include <stdint.h> | |
| #include <stdio.h> | |
| uint32_t numeric_ip4(const char *ip) { | |
| uint32_t octets = 0; | |
| uint8_t octet = 0; | |
| for(; *ip; ip += 1) { | |
| if(*ip == '.') { | |
| octets = (octets << 8) | octet; |
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
| #!/usr/bin/env bash | |
| b64_encode() { | |
| local idx=0 numerics table_idxs table_idx encoded | |
| local table=( {A..Z} {a..z} {0..9} + / ) | |
| for (( ; idx < ${#1}; idx+=3 )); do | |
| read -ra numerics < <( | |
| printf '%d %d %d\n' "'${1:idx:1}" "'${1:idx+1:1}" "'${1:idx+2:1}" | |
| ) |
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
| #!/usr/bin/env bash | |
| clear() { | |
| printf "\x1b\x5b\x48\x1b\x5b\x32\x4a" | |
| } | |
| red() { | |
| local red=$'\x1b\x5b\x33\x31\x6d' | |
| local rst=$'\x1b\x28\x42\x1b\x5b\x6d' | |
| printf %s%s%s "$red" "$1" "$rst" |
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
| #!/usr/bin/env bash | |
| numeric() { | |
| printf %d "$(( $(printf %d \'"${1,}") - $(printf %d \'a) ))" | |
| } | |
| vigenere_enc() { | |
| local key=$1 plain=$2 idx {plain,key}_pos incr offset | |
| for (( idx = 0; idx < ${#plain}; idx += 1 )); do |
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
| #!/usr/bin/env bash | |
| cols=$(tput cols) line="" | |
| while (( ${#line} < cols + ${#1} )); do | |
| if (( ${#line} < ${#1} )); then | |
| line=${1:$((${#1}-${#line}-1)):1}$line | |
| else | |
| line=" $line" | |
| fi |
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
| #!/usr/bin/env bash | |
| # The variables are checked dynamically | |
| # shellcheck disable=SC2034 | |
| seconds() { | |
| local day hour minute second span time | |
| (( day = $1 / 60 / 60 / 24 )) | |
| (( hour = $1 / 60 / 60 % 24 )) | |
| (( minute = $1 / 60 % 60 )) | |
| (( second = $1 % 60 )) |
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
| #!/usr/bin/env bash | |
| bin() { | |
| local str num=$1 | |
| while (( num > 0 )); do | |
| str=$(( num % 2 ))$str | |
| (( num /= 2 )) | |
| done |