Skip to content

Instantly share code, notes, and snippets.

View fkohlgrueber's full-sized avatar

Felix Kohlgrüber fkohlgrueber

View GitHub Profile
@fkohlgrueber
fkohlgrueber / index.html
Created May 5, 2020 09:05
ResizeObserver example
<head>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Ubuntu+Mono" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/tonsky/[email protected]/distr/fira_code.css">
<style>
textarea {
font-family: Fira Code, monospace;
font-size: 12pt;
}
#measure {
I've been thinking about file formats lately. When looking at different formats, it seems like there are common concepts used in many of them, the main ones being **textual data** and **hierarchy**. These concepts are usually implemented by stacking different encoding layers. For example, the SVG format can be seen as the following stack of abstractions: `SVG -> XML -> UTF-8 -> Binary`. In this case, the hierarchy is provided by XML and the encoding of textual data is done in XML and UTF-8. You might be wondering why textual data is handled both in XML and UTF-8. The reason for this is that one cannot simply paste a UTF-8-encoded string into an SVG file and expect it to work. A lot of strings would contain characters that have a meaning to the surrounding markup. The common solution to this is to use escape characters that indicate that the character following them should not be treated as markup. But other than that, textual data is encoded in UTF-8.
Having to handle textual data encoding at two levels in
Panic context:
>
version: 796bfccac 2021-09-03 dev
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 0,
character: 3,
},
end: Position {
@fkohlgrueber
fkohlgrueber / read_to_buf.rs
Created December 14, 2021 08:46
Using const generics to make the Read trait and parsing more ergonomic
use std::io::{self, Read};
pub trait MyRead: Read {
#[inline(always)]
fn read_to_buf<const N: usize>(&mut self) -> io::Result<[u8; N]> {
let mut buf = [0; N];
self.read_exact(&mut buf)?;
Ok(buf)
}
}