forked from heyman/heynote
-
Notifications
You must be signed in to change notification settings - Fork 18
/
scratchpad.txt
48 lines (31 loc) · 1.2 KB
/
scratchpad.txt
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
Idea for backing up notes: when saving, save as ${name}-${currTimeMsEncoded}.edna.txt and ${name}-${name}.edna.txt
${currTimeEncoded} is integer as milliseconds since epoch base32-encoded as a sortable string.
That way we embed creation time in the note, they are sorted by time and it's simple and conflict free compared to e.g. adding unique numberic prefix like `-1`, `-2` etc.
It breaks if time is messed up but that's acceptable.
function encodeBase32(num) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; // RFC 4648 base32 alphabet
let result = '';
do {
result = chars[num % 32] + result;
num = Math.floor(num / 32);
} while (num > 0);
return result;
}
function encodeCurrentTimeBase32() {
const timeInMillis = Date.now(); // Get current time in milliseconds since epoch
return encodeBase32(timeInMillis); // Convert that time into a base32 string
}
// Usage
console.log(encodeCurrentTimeBase32());
----------------------------------------------------------------
settings:
Keymap: [default]
# Input settings
[ ] Auto-close brackets and question marks
# Gutters
[ ] Show line number
[ ] Show fold gutter
Theme: [Light]
Font family:
Font size:
Version: 1.3