-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrun
executable file
·77 lines (66 loc) · 2.53 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# unofficial "strict mode": http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
function stats {
find . -type f ! -path '*.spec.js' \
! -ipath '*test.*' \
! -ipath '*tests.*' \
! -ipath '*Test.java' \
! -path '*/tests/*' \
! -path '*/runner.mips' \
! -path '*/node_modules/*' \
! -path '*/elm-stuff/*' \
! -path './.git/*' \
! -path '*.md' \
! -path '*/vendor/*' \
! -path '*/CMakeFiles/*' \
| awk 'BEGIN { FS="." } { counts[$NF]++ } END { for (a in counts) printf("%s %s \n", counts[a], a) }' \
| sort -n -r \
| awk '{ print $2 " " $1 }' \
| grep -E '^(clj|py|js|c|cs|cpp|hs|rkt|elm|rs|mips|asm|go|java|sh) \d+' \
| awk 'BEGIN { names["py"] = "Python"
names["js"] = "JavaScript"
names["c"] = "C"
names["cs"] = "C#"
names["cpp"] = "C++"
names["clj"] = "Clojure"
names["hs"] = "Haskell"
names["rkt"] = "Racket"
names["rs"] = "Rust"
names["mips"] = "MIPS assembly"
names["asm"] = "x86-64 assembly"
names["java"] = "Java"
names["sh"] = "Bash"
names["go"] = "Go"
names["elm"] = "Elm"}
{ printf("| %s | %s |\n", names[$1], $2) }'
}
function make-readme {
echo "
My solutions for problems from Exercism, Leetcode, Project Euler etc in a
number of languages. Mostly an exercise in side-by-side comparison of languages,
to increase my understanding of those I don't use day to day.
| Language | Problems solved |
| --- | --: |
$(stats)
| J | 0 |
| Prolog | 0 |
"
}
function prep-all {
touch "$1.txt"
if [ ! -e "$1.js" ] ; then echo '#!/usr/bin/env node' > "$1.js"; fi
if [ ! -e "$1.hs" ] ; then echo '#!/usr/bin/env runghc' > "$1.hs"; fi
# if [ ! -e "$1.ml" ] ; then echo '#!/usr/bin/env ocaml' > "$1.ml"; fi
if [ ! -e "$1.py" ] ; then echo '#!/usr/bin/env python' > "$1.py"; fi
if [ ! -e "$1.clj" ] ; then echo '#!/usr/bin/env lein-exec' > "$1.clj"; fi
if [ ! -e "$1.rkt" ] ; then echo '#!/usr/bin/env racket --script' > "$1.rkt"; fi
chmod +x "$1.*"
}
# compile and run c sharp
function cs {
mcs -out:/tmp/out.exe "$1" && mono /tmp/out.exe
}
# if called with interpreter, run fn that matches first arg
[[ ${BASH_SOURCE[0]} = "$0" ]] && eval "$1" "${@:2}"