Skip to content

Instantly share code, notes, and snippets.

View fkohlgrueber's full-sized avatar

Felix Kohlgrüber fkohlgrueber

View GitHub Profile
@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)
}
}
Panic context:
>
version: 796bfccac 2021-09-03 dev
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 0,
character: 3,
},
end: Position {
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
@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/FiraCode@1.207/distr/fira_code.css">
<style>
textarea {
font-family: Fira Code, monospace;
font-size: 12pt;
}
#measure {
// tested using nix 0.15.0
extern crate nix;
use std::path::Path;
use nix::pty::{posix_openpt, grantpt, unlockpt, ptsname};
use nix::fcntl::{OFlag, open};
use nix::sys::{stat, wait};
use nix::unistd::{fork, ForkResult, setsid, dup2};
use nix::libc::{STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
  • Feature Name: syntax_tree_patterns
  • Start Date: (fill me in with today's date, YYYY-MM-DD)
  • RFC PR: (leave this empty)
  • Rust Issue: (leave this empty)

Summary

Introduce a DSL that allows to describe lints using syntax tree patterns.

Initial configuration:

  • queue with capacity for 3 elements
  • two producers p1, p2 and one consumer c1
  • queue contains one element "x" at the first position
  • Thread p1 wants to insert an element "Y"

Pointers and queue content at initial configuration:

@fkohlgrueber
fkohlgrueber / Quadrate.java
Created December 7, 2017 18:08
Quadratzahlen
public class Quadratzahlen
{
public static void main(String[] args)
{
// Aufgabe: gib die ersten zehn Quadratzahlen auf der Konsole aus.
//
// Korrekte Ausgabe:
// 1 4 96 16 25 36 49 64 81 100
import subprocess
def to_hex(byte_string):
return " ".join("{:02x}".format(b) for b in byte_string)
def to_bin(byte_string):
return " ".join("{:08b}".format(b) for b in byte_string)
@fkohlgrueber
fkohlgrueber / cython-benchmark.ipynb
Last active October 28, 2017 14:09
cython benchmark
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.