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
/** | |
* Arbitrary-length tuples | |
* ======================= | |
* | |
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible | |
* tuple lengths up to a threshold (see an example here https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts ) | |
* | |
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential | |
* to make some kinds of declarative APIs nicer and enhance type inference in some cases. | |
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting |
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
<script> | |
if (typeof Promise == "undefined") { | |
document.write('<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/polyfill.min.js"><\/script>'); | |
} | |
if (window.URL && window.URL.prototype && ('href' in window.URL.prototype)) { | |
} else { | |
document.write('<script src="https://cdn.jsdelivr.net/gh/arv/DOM-URL-Polyfill@e54d67f/src/url.min.js"><\/script>'); | |
} | |
if (typeof URLSearchParams == "undefined") { | |
document.write('<script src="https://cdn.jsdelivr.net/npm/@ungap/[email protected]/min.js"><\/script>'); |
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/sh | |
[ $# -ne 1 ] && echo "Usage: $0 name" && exit 1 | |
p=$(printf "%d" "0x$(printf "%s" "$1" | md5sum | head -c 4)") | |
# pratical port range is 1024 ~ 65535 (for app that don't require root) | |
# 64499 is the first prime number that less than 65535 - 1024 | |
port=$((p % 64499 + 1024)) | |
echo "$port" |
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
有一存有整数的数组 A[n] (n <= 2^31 - 1, 但需要的话可以再扩大), 其中 0 <= i, A[i] <= n-1 且 i!=j 时 A[i]!=A[j] (即一个排列). 用你认为*最高效*的方法求 B=A^(-1) (即对范围内满足 A[B[i]]=i 的 B) |
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
rel() { | |
[ ! -d 'target/universal/stage' ] && echo stage not exist! && return 1 | |
name=$(pwd | tr '/' '\n' | tail -n1) | |
timestamp=$(date +%Y%m%d_%H%M%S) | |
cp -r "target/universal/stage" "/apps/$name/stage-$timestamp" | |
ln -sTv "stage-$timestamp" "/apps/$name/stage" | |
} |
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
/************* | |
* colors.js * | |
************* | |
* | |
* You're almost at the exit. You just need to get past this | |
* color lock. | |
* | |
* Changing your environment is no longer enough. You must | |
* learn to change yourself. I've sent you a little something | |
* that should help with that. |
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 getint2(int *out) { | |
register int s = 0; | |
register int ch; | |
ch = getchar(); | |
bool negative = false; | |
while (ch < '0' || ch > '9') { | |
if (ch == '-') { | |
negative = true; | |
ch = getchar(); | |
break; |
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
typedef int T; | |
inline bool less(T a, T b) { | |
return a < b; | |
} | |
inline bool lessEq(T a, T b) { | |
return a <= b; | |
} |
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
static inline void putllong(long long n) | |
{ | |
static char buf[20]; | |
register int pos; | |
register long long x = n; | |
if (x == 0) { | |
putchar('0'); | |
return; | |
} | |
if (x == LLONG_MIN) { // x = -x do not work for the minimal value of long long, so process it first |
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 getint(char end) { | |
int s = 0; | |
int ch; | |
ch = getchar(); | |
while (ch != end && ch != EOF) { | |
s = s * 10 + ch - '0'; | |
ch = getchar(); | |
} | |
return s; | |
} |
NewerOlder