Libraryless. Click here for Pure Java version (1697L/11K/35K).
1 | !752 |
2 | |
3 | static PersistentMap<S, S> cache; |
4 | |
5 | p {
|
6 | cache = new PersistentMap("cache");
|
7 | } |
8 | |
9 | answer {
|
10 | if "spell *" exceptionToUser {
|
11 | S n = m.unq(0); |
12 | if (isInteger(n)) {
|
13 | S val = cache.get(n); |
14 | if (val != null) ret val; |
15 | |
16 | S html = loadPage("https://www.ego4u.com/en/cram-up/vocabulary/numbers/generator?param=" + n + "&show=Show");
|
17 | L<S> tok = htmlcoarsetok(html); |
18 | int i = 0; |
19 | while (i < l(tok) && !tok.get(i).startsWith("cardinal number "))
|
20 | i += 2; |
21 | i = indexOf(tok, "<li>", i); |
22 | |
23 | if (i >= 0) {
|
24 | val = tok.get(i+1); |
25 | cache.put(n, val); |
26 | ret val; |
27 | } |
28 | } |
29 | } |
30 | |
31 | if "fill spell numbers cache *" {
|
32 | int max = min(m.psi(0), 1000), made = 0; |
33 | for (int i = 0; i < max; i++) |
34 | if (cache.get(str(i)) == null) {
|
35 | askSelf("spell " + i);
|
36 | ++made; |
37 | } |
38 | ret "OK, made numbers up to " + max + " (" + made + " new). Cache size now: " + cache.size();
|
39 | } |
40 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1002589 |
| Snippet name: | Call Number Maker Bot (ego4u.com) with cache |
| Eternal ID of this version: | #1002589/1 |
| Text MD5: | 1e5bac9b38b27f3e3895f079f3e189fe |
| Transpilation MD5: | c062e5c025c46bfab08e1363a43e46e8 |
| Author: | stefan |
| Category: | eleu |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-02-03 17:40:50 |
| Source code size: | 1003 bytes / 40 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 895 / 1295 |
| Referenced in: | [show references] |