This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Note-Title { | |
font-weight: 700; | |
margin-top: 0.5em; | |
} | |
.Note-Text { | |
font-size: 0.8em; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function render() { | |
const filter = filterEl.value.trim(); | |
const filteredNotes = notes.filter(note => { | |
if (!filter) return true; | |
return note.title.includes(filter) || note.text.includes(filter); | |
}); | |
notesEl.innerHTML = filteredNotes.map(Note).join(""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let notes = []; | |
function render() { /**/ }; | |
fetch("src/notes.json") | |
.then(response => response.json()) | |
.then(_notes => (notes = _notes)) | |
.then(render) | |
.catch(e => console.error(e)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Note(note) { | |
const { title, text } = note; | |
return ` | |
<div class='Note'> | |
<div class='Note-Title'> | |
${title} | |
</div> | |
<div class='Note-Text'> | |
${text} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function render() { | |
notesEl.innerHTML = notes.map(Note).join(""); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Notes</title> | |
<meta charset="UTF-8" /> | |
<link rel="stylesheet" type="text/css" href="src/styles.css"></link> | |
</head> | |
<body> | |
<input id="filter"> | |
<div id="notes"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BSON = require('bson'); | |
const DOC_LIMIT = 16777216; | |
async function insert(column) { | |
// identificators for our column | |
const ids = [column._id]; | |
const { _id, type } = column; | |
// lets calculate column size with empty array | |
const docMinSize = Math.max( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateColumnSize(column) { | |
let size = 0; | |
size += 4; // 4 bytes for int32 for a document size | |
// `_id` key-value where _id value is a string | |
// 10 bytes + ? = 1(value type) + 3(`_id` key length) + 1(key terminator) + 4(int32 string length) + ?(value length) + 1(string value terminator) | |
size += 10 + column._id.length; | |
// `type` key value with 'string' as value | |
// 17 bytes = 1(value type) + 4(`type` key length) + 1(key terminator) + 4(int32 string length) + 6(`string` length) + 1(string value terminator) | |
size += 17; | |
// `values` array with string or null values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let doc = { values: [null] }; | |
console.log(BSON.serialize(doc)); | |
// <Buffer 15 00 00 00 04 76 61 6c 75 65 73 00 08 00 00 00 0a 30 00 00 00> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let doc = { values: ['first'] }; | |
console.log(BSON.serialize(doc)); | |
// <Buffer 1f 00 00 00 04 76 61 6c 75 65 73 00 12 00 00 00 02 30 00 06 00 00 00 66 69 72 73 74 00 00 00> |
NewerOlder