Libraryless. Click here for Pure Java version (1549L/10K/36K).
!747 m { static new Map<S, S> entries; static S pattern = "meta * - just got it from the web. snippet * now has md5 * and title *."; p { readLocally("entries"); print(entries.size() + " entries in cache."); makeAndroid("Snippet Cache Bot. v2."); } static void addEntry(S e) { entries.put(extractID(e), e); // TODO: compare timestamps saveLocally("entries"); } static S getEntry(S roughID) { S id = formatSnippetID(unquote(roughID)); S e = entries.get(id); if (e == null) { // Load from web! S title = getSnippetTitle(id); S md5 = getSnippetMD5(id); e = "meta " + quote(now()) + " - just got it from the web. snippet " + quote(id) + " now has md5 " + quote(md5) + " and title " + quote(title) + "."; addEntry(e); } return e; } static S extractID(S e) { new Matches m; if (!find3("snippet *", e, m)) return null; return formatSnippetID(unquote(m.m[0])); } static S extractMD5(S e) { new Matches m; if (!find3("md5 *", e, m)) return null; return unquote(m.m[0]); } static S extractTitle(S e) { new Matches m; if (!find3("title *", e, m)) return null; return unquote(m.m[0]); } static synchronized S answer(S s) { new Matches m; // put new information in store if (match3(pattern, s, m)) { print("New entry: " + structure(m.m)); addEntry(s); return "OK, stored."; } // retrieve information if (match3("get md5 of snippet *", s, m)) return extractMD5(getEntry(m.m[0])); if (match3("get title of snippet *", s, m)) { return extractTitle(getEntry(m.m[0])); } // other commands if (match3("please consolidate", s, m)) return "OK, nothing to consolidate."; return null; } }
Began life as a copy of #1001216
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001237 |
Snippet name: | Snippet Cache Bot v2 |
Eternal ID of this version: | #1001237/1 |
Text MD5: | 6cb3d4237cc2537a7767e9ef26041415 |
Transpilation MD5: | 206e25e33be374684cf844834f34475d |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-04 15:04:39 |
Source code size: | 1940 bytes / 80 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 582 / 666 |
Referenced in: | [show references] |