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
| ls | grep -E -v 'file1|file2|file3' | xargs rm -rf |
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> | |
| #include <stdint.h> | |
| #include <assert.h> | |
| #define TAG_BITS 4 | |
| #define TAG_MASK 0xF | |
| #define TAG_INT 3 | |
| #define bit(p, n) (((uintptr_t)(p) & (1 << (n))) != 0 ? 1 : 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 <stdio.h> | |
| typedef struct T { | |
| int i, j; | |
| float f; | |
| } T; | |
| int main(void) | |
| { | |
| T a = { 1, 2, 3.14 }; |
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> | |
| #define and && | |
| #define or || | |
| #define not ! | |
| #define when(exp) if (exp) | |
| #define unless(exp) if (not (exp)) | |
| static void open_and_read(int files, char *filenames[]) | |
| { |
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
| function pingpong(n) | |
| n = n or 3 | |
| coro = coroutine.create(function (msg) | |
| for i = 1, n do | |
| io.write(msg, " ") | |
| msg = coroutine.yield("pong") | |
| end | |
| end) | |
| local _, msg = coroutine.resume(coro, "ping") | |
| for i = 1, n 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
| function count(s, e) | |
| s = s or 0 | |
| e = e or s + 10 | |
| --[[ | |
| coro = coroutine.create(function () | |
| for i = s, e do | |
| coroutine.yield(i) | |
| end | |
| end) | |
| --]] |
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 | |
| BACKUPDIR=$HOME/backups | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $(basename "$0") FILE..." | |
| exit 0 | |
| fi | |
| if [ ! -d $BACKUPDIR ]; then |
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 | |
| read -a files <<< $(echo *.{lua,go}) | |
| echo "Read ${#files[@]} files:" | |
| for f in "${files[@]}"; do | |
| echo " $f" | |
| done |
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 | |
| declare -A table | |
| table[foo]=1 | |
| table[bar]=2 | |
| table[baz]=3 | |
| for i in "${!table[@]}"; do | |
| echo "$i: ${table[$i]}" |
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
| function clone(o, ...) | |
| assert(type(o) == "table", "clone works on objects (tables) only") | |
| local c = setmetatable({}, {__index = o}) | |
| if c.init ~= nil then | |
| c:init(...) | |
| end | |
| return c | |
| end | |
| local o1 = {a = 1, b = 2, n = "o1"} |