Skip to content

Instantly share code, notes, and snippets.

package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
-- This module serves as the root of the `Json` library.
-- Import modules here that should be built as part of the library.
import Std
inductive Json where
| null : Json
| bool (b: Bool)
| number (n: Int)
| array (a: List Json)
from abc import ABC, abstractmethod
from typing import Callable, Generic, Iterable, Iterator, Optional, Tuple, TypeVar, Union
T = TypeVar('T')
U = TypeVar('U')
class Functor(ABC, Generic[T]):
@abstractmethod
def fmap(self, f: Callable[[T], U]) -> 'Functor[U]':
raise NotImplemented

Parsers and DOM

  • xml-rs: roughly XML 1.0, low-level StAX-style streaming parser; no DTD validation;
  • xmlparser: very similar to xml-rs
  • quick-xml: almost zero-copy,
  • roxmltree: a read-only zero-copy "DOM" based on the source data. Not streaming? XML 1.0.
  • rxml: "alpha-quality" restricted SAX parsing of XML 1.0 with namespacing.
    • minidom builds on it, focused on xmpp
@EarlGray
EarlGray / bitbuilder.rs
Created June 20, 2023 22:10
encoding state of a Builder into a const generic bitmask
/// This is an example of encoding state of a Builder
/// into a const generic bitmask. [`PipelineBuilder`]
/// only allows `.build()` when all of the fields have
/// been set.
/// This requires a scary nightly feature that rustc
/// marks with a stark warning:
/// ```ignore
/// the feature `generic_const_exprs` is incomplete
/// and may not be safe to use and/or cause compiler crashes
@EarlGray
EarlGray / status.py
Last active July 7, 2023 22:48
dmytrish's swaybar
#!/usr/bin/env python3
"""
A swaybar implementation.
Current plugins:
- keyboard layout state and tracking
- PulseAudio-compatible sound: device, volume and mute status
- power supply: on battery/ac, percentage, time to emtpy/full
- network: the name of the primary connection, `nmmenu` on click
- time in different formats

#coding

We all know that 5 % 3 is 2 (I use % as the modulo operation sign). What about -5 % 3 or -5 % -3 in your favorite programming language?

Turns out, there are different answers.

Python

>>> 5 % 3
#!/usr/bin/env python3
"""
This is a driver for Gravity 16x2 LCD (single-color, not RGB) for Raspberry Pi.
It is tested on Raspberry Pi Zero W with
- i2c_arm,baudrate=100000
- i2c_arm,baudrate=400000
- dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1
"""
@EarlGray
EarlGray / Dmytrish Sleep Service.md
Last active January 12, 2022 20:35
dmytrish-sleep.service

This is a set of systemd timers and services that ensures that computer goes to bed at night (00:00-07:00), hopefully helping me to go to bed as well.

dmytrish-sleep.timer starts sending desktop notifications about computer going to sleep 1 minute before the night start and then suspends the computer. Then it tries to ensure that computer sleeps during the night time: it puts computer back to sleep in a loop until the morning time.

@EarlGray
EarlGray / SetExample.coq
Last active November 14, 2021 15:12
Proving X ∪ Y ∪ Z ∩ X ∪ Y ∩ (X \ Z) = X ∪ Y in Coq
Require Import Coq.Sets.Ensembles.
Require Import Coq.Sets.Powerset_facts.
Require Import Coq.Setoids.Setoid.
Section SetExample.
Variable U: Type.
Definition USet := Ensemble U.
Notation "X ∩ Y" := (Intersection U X Y) (at level 41).