Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
@matklad
matklad / example.zig
Last active July 10, 2025 20:16 — forked from andrewrk/example.zig
async await demo
// No futures
//
// Soundtrack: https://www.youtube.com/watch?v=rFH4jCW_LzM&list=RDrFH4jCW_LzM
//
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const Io = std.Io;
pub fn main() !void {
@matklad
matklad / idea.nix
Last active September 2, 2024 23:03
Using JetBrains JDK with Intellij IDEA on nixos
# Put this file into `~/.config/nixpkgs/overlays/idea.nix`.
# Then, install IDEA with `nix-env -iA nixos.idea-community`.
self: super:
{
jbsdk = super.callPackage ~/config/nix/jbsdk.nix {}; # you might need to override this path.
idea-community = let
version = "2017.2.3";
const Self = @This();
const mem = std.mem;
const eof = error.EndOfStream;
const std = @import("../std.zig");
const Reader = struct {
context: *const anyopaque,
readFn: *const fn (context: *const anyopaque, buffer: []u8) anyerror!usize,
pub const Error = anyerror;
@matklad
matklad / 01.py
Created September 28, 2018 18:04
decorators.py
def max(*args):
"""Finds the largest argument."""
print(f"max{args} = ...")
ret = 0
for x in args:
ret = ret if x < ret else x
print(f"max{args} = {ret}")
return ret
#!/bin/sh
echo `# <#`
mkdir -p ./zig
wget https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz -O ./zig/zig-linux-x86_64-0.10.1.tar.xz
tar -xf ./zig/zig-linux-x86_64-0.10.1.tar.xz -C ./zig --strip-components=1
rm ./zig/zig-linux-x86_64-0.10.1.tar.xz
echo "Zig installed."
@matklad
matklad / data.csv
Last active February 15, 2023 23:21
Measuring latencies of text editors in 2020
VS Code (compositor disabled) Sublime3 (compositor disabled) Kitty (compositor disabled) Emacs (compositor disabled) IntelliJ Idea(compositor disabled) VS Code (compositor enabled) Sublime3 (compositor enabled) Kitty (compositor enabled) Emacs (compositor enabled) IntelliJ Idea (compositor enabled)
33.11 6.51 28.80 3.57 5.58 43.03 23.69 32.88 26.51 24.32
11.41 6.86 16.23 3.72 5.44 18.95 21.41 34.74 25.58 27.36
23.91 7.46 12.08 3.23 6.52 29.17 22.13 42.68 21.77 25.10
15.02 7.21 15.29 3.76 7.14 37.95 23.81 32.55 26.18 25.69
14.32 6.93 14.38 3.71 5.40 30.00 27.72 23.69 22.69 27.63
14.09 7.53 28.89 3.84 6.03 31.61 24.66 39.54 25.33 26.98
14.72 7.51 14.65 3.65 6.25 48.57 18.52 21.66 20.52 26.54
13.87 6.77 28.89 3.17 5.50 47.22 23.33 40.54 24.05 25.85
14.36 6.61 14.36 3.71 5.61 42.68 23.04 32.98 25.21 26.66
pub trait Handler: Sized {
fn address(&mut self, state: &mut Machine, opcode: Opcode, position: usize) -> Control;
}
type OpFn<H> = fn(this: &mut H, state: &mut Machine, opcode: Opcode, position: usize) -> Control;
// We would like to write this, but Rust's const-eval is not good enough for that yet :(
// const fn mk_table<H: Handler>() -> [OpFn<H>; 256] { }
// So, we have to express this as type-level function (trait)
def print_all_sets():
n = 3
g = Gen()
while not g.done():
print([g.gen(1) == 1 for _ in range(3)])
class Gen:
def __init__(self):
self.v = []
pub struct WasmRefCell<T>(core::cell::RefCell<T>);
impl<T> WasmRefCell<T> {
pub const fn new(initial_value: T) -> WasmRefCell<T> {
WasmRefCell(core::cell::RefCell::new(initial_value))
}
pub fn with<U, F: FnOnce(&mut T) -> U>(&self, f: F) -> U {
f(&mut *self.0.borrow_mut())
}
pub struct TestResource {
path: &'static str,
cell: OnceCell<Vec<u8>>,
}
impl TestResource {
pub const fn new(path: &'static str) -> TestResource {
TestResource { path, cell: OnceCell::new() }
}
pub fn bytes(&self) -> &[u8] {