Skip to content

Commit 38edd23

Browse files
authored
Merge pull request #220 from ErezBinyamin/master
Better bibliography, Fixed high traffic collision bug
2 parents a5b0495 + 5a6a80c commit 38edd23

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

share/adapters/oeis.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# oeis <val_a, val_b, val_c, ...>
1010
oeis() (
1111
local URL='https://oeis.org/search?q='
12-
local TMP=/tmp/oeis
13-
local DOC=/tmp/oeis/doc.html
12+
local TMP=$(mktemp -d oeis.XXXXXXX)
13+
local DOC=${TMP}/doc.html
1414
local MAX_TERMS_LONG=30
1515
local MAX_TERMS_SHORT=10
1616
mkdir -p $TMP
@@ -53,6 +53,7 @@ oeis() (
5353
[[ -f $TMP/section && $(wc -c < $TMP/section) -ne 0 ]] \
5454
&& cat ${TMP}/section | sort -u \
5555
|| printf 'No code snippets available.\n'
56+
rm -rf $TMP
5657
return 0
5758
fi
5859
# Print ID
@@ -92,22 +93,24 @@ oeis() (
9293
if [[ -f $TMP/code_snippet && $(wc -c < $TMP/code_snippet) -ne 0 ]]
9394
then
9495
# Get authors
95-
cat ${TMP}/code_snippet \
96-
| grep -o ' _[A-Z].* [A-Z].*_, [A-Z].*[0-9]' \
96+
grep -o ' _[A-Z].* [A-Z].*_, [A-Z].*[0-9]' ${TMP}/code_snippet \
97+
| sed 's/,.*//' \
9798
| sort -u \
9899
> ${TMP}/authors
99100
i=1
100101
# Replace authors with numbers
101102
while read author
102103
do
103104
author=$(<<<"$author" sed 's/[]\\\*\(\.[]/\\&/g')
104-
sed -i "s|${author}|[${i}]|" ${TMP}/code_snippet
105-
echo "[${i}] [${author}]" | tr -d '_' >> ${TMP}/bibliograpy
105+
sed -i "s|${author}.*[0-9]|[${i}]|" ${TMP}/code_snippet
106+
author=$(echo $author | tr -d '_\\')
107+
author_url='https://oeis.org/wiki/User:'"$(echo ${author} | tr ' ' '_')"
108+
echo "[${i}] [${author}] [${author_url}]" \
109+
>> ${TMP}/bibliograpy
106110
let i++
107111
done <${TMP}/authors
108112
# Print snippet
109-
cat ${TMP}/code_snippet \
110-
| sed 's/^/ /'
113+
sed 's/^/ /' ${TMP}/code_snippet
111114
else
112115
printf "${SECTION^^} unavailable. Use :list to view available languages.\n"
113116
fi
@@ -161,6 +164,7 @@ curl cheat.sh/oeis/A2/python
161164
# List all available implementations of the A2 OEIS sequence
162165
curl cheat.sh/oeis/A2/:list
163166
"
167+
rm -rf $TMP
164168
return 1
165169
fi
166170
# Error statements
@@ -175,6 +179,8 @@ curl cheat.sh/oeis/A2/:list
175179
| sed 's/,//' \
176180
| rev \
177181
| sed 's/&.*/]/'
182+
rm -rf $TMP
183+
return 0
178184
)
179185
180186
oeis $@

0 commit comments

Comments
 (0)