Skip to content

Instantly share code, notes, and snippets.

@cedws
cedws / defer.sh
Last active Apr 15, 2020
Go-like defer 'keyword' for shell
View defer.sh
#!/bin/sh
DEFER=
defer() {
DEFER="$*; ${DEFER}"
trap "{ $DEFER }" EXIT
}
View sway_dockerfile_fedora29
# This Dockerfile is not pure and should not be used as anything other than a reference.
# You can build an image by running `docker build -t sway -f fedora29 .`
FROM fedora:29
# Install build dependencies.
RUN dnf install -y git gcc meson ninja-build
# Install dependencies.
RUN dnf install -y wayland-devel wayland-protocols-devel mesa-libEGL-devel mesa-libGLES-devel libdrm-devel libgbm-devel libxkbcommon-devel libudev-devel pixman-devel libinput-devel libevdev-devel systemd-devel cairo-devel libpcap-devel json-c-devel pam-devel pango-devel pcre-devel gdk-pixbuf2-devel
@cedws
cedws / fast-dims.py
Last active Oct 11, 2018
Get the dimensions of a remote image... fast.
View fast-dims.py
import asyncio
import aiohttp
# I'm importing Pillow-SIMD for increased performance, but you can use ordinary Pillow if you wish.
from PIL import ImageFile
# The remote image we'll be finding the dimensions for.
SOURCE = "http://rustacean.net/assets/rustacean-orig-noshadow.png"
View brainfuck.rs
const PROGRAM: &str = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
const MAX_SCOPES: usize = 16;
const ALLOC_BLOCK_SIZE: usize = 128;
#[derive(Copy, Clone)]
enum Instruction {
PointerLeft,
PointerRight,
Increment,
Decrement,