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 <alloca.h> | |
| #include <string.h> | |
| __attribute__((always_inline)) | |
| static inline void print_rsp() { | |
| #if defined(__x86_64__) | |
| void *rsp = NULL; | |
| asm ("mov %%rsp, %0;" | |
| :"=r"(rsp) /* output */ |
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/python3 | |
| import secrets | |
| NUMBER_OF_WORDS = 4 | |
| NUMBER_OF_DIGITS = 3 | |
| SYMBOLS = ['#', '@', '!', '$', '%'] | |
| WORDS = None | |
| def main(): | |
| pw = '' |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <meta charset="utf-8"> | |
| <title>Arabic Bidirectional Text Example</title> | |
| <base href="https://nilput.com/"> | |
| <link rel="alternate" type="text/html" title="Arabic Bidirectional Text Example" href="https://nilput.com/pages/arabic"> | |
| <link rel="author" type="text/html" title="Turki's personal website" href="https://nilput.com"> | |
| <link rel="icon" href="/favicon.ico"> | |
| <link rel="stylesheet" href="/css/fonts/custom_fa.css"> | |
| <meta name="viewport" content="width=device-width, initial-scale=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
| /* | |
| In many cases, we have situations where we need to define a lot of constants / data definitions. | |
| examples: enums, definitions such as cpu instructions encodings, http message response types, lookup tables, etc.. | |
| this method is seen in many projects and it's a good solution to the problem, it avoid redundancy and code duplication, | |
| and it help maintain a single source of truth. | |
| */ | |
| #include <stdio.h> | |
| enum item_type { FRUIT, VEGETABLE }; |
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
| #!/bin/bash | |
| function die() { | |
| echo "$*" >&2 | |
| [ -n "$tmp" -a -d "$tmp" ] && rm -rf "$tmp" | |
| exit 1; | |
| } | |
| tmp="$(mktemp -d -t cexec-XXXXXX)" && [ -n "$tmp" -a -d "$tmp" ] || die "couldn't create tmp dir"; | |
| [ "$1" = '-h' ] && die "$(printf "Usage: $0 <<<'C Source code")" | |
| cat <(printf "#include <%s.h>\n" stdio stdlib string) \ | |
| <(printf 'int main(int argc,char *argv[]){') \ |
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
| #!/bin/bash | |
| function die() { | |
| rm -r "$tmp_dir" | |
| exit 1; | |
| } | |
| if [ "$#" -lt 1 ]; then | |
| echo "Usage: $0 [java source file]" | |
| exit 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
| #include <stdio.h> | |
| struct base { | |
| const struct vt *vt; | |
| }; | |
| struct vt { | |
| void (*who)(struct base *b); | |
| void (*talk)(struct base *b); | |
| }; | |
| struct cat { | |
| struct base base; |
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
| //C tcp server/client example | |
| // some of this is based on https://gist.github.com/oleksiiBobko/43d33b3c25c03bcc9b2b | |
| // which has a couple of problems in the time of writing this. | |
| // | |
| // this handles multiple clients without blocking, without threads, without multiprocessing, using poll() | |
| // | |
| // Author: github.com/nilput <[email protected]> | |
| // license: BSD-3 |
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
| ///author: github.com/nilput <[email protected]> | |
| //license: BSD-3 | |
| #include <assert.h> | |
| #include <stdint.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <stdio.h> | |
| #include <limits.h> | |
| #if CHAR_BIT != 8 |
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
| //find prime near power of two using openssl | |
| //author: github.com/nilput | |
| //compile using: cc genp2.c -o genp2 $(pkg-config --cflags libssl) $(pkg-config --libs libssl) | |
| #include <openssl/bn.h> | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <stdbool.h> | |
| #include <string.h> | |
| #include <assert.h> |