Skip to content

Instantly share code, notes, and snippets.

@LunarLambda
LunarLambda / fizzbuzz-befunge.md
Last active Jan 28, 2021
Weird Coding - FizzBuzz in Befunge
View fizzbuzz-befunge.md

Weird Coding - FizzBuzz in Befunge

Jan 28 2021

I seem to have a real infatuation with unconvential programming challenges. Whenever I get to do something completely new that is at the same time simple enough to take no more than a day or two, but also far enough 'out there' that just looking up the solution is out of the question, my brain really seems to light up.

So, after rewatching [Tom Scott's video about the FizzBuzz interview question][fizzbuzz-yt], I figured a fun brain teaser would be to try and implement FizzBuzz in [Befunge][befunge], an esoteric programming language I am quite fond of.

Without much fanfare, here it is:

@LunarLambda
LunarLambda / Makefile
Created Jan 12, 2021
Brainfuck interpreter written in x86_64 assembly
View Makefile
tbf: tbf.o
# Note: needs LLVM linker.
ld.lld -s -pie -o tbf tbf.o
# ld -s -pie -o tbf tbf.o -I/lib/ld-linux-x86-64.so.2
tbf.o: tbf.nasm
nasm -f elf64 -o tbf.o tbf.nasm
.PHONY: clean
clean:
@LunarLambda
LunarLambda / Cargo.toml
Last active Jan 8, 2021
Windows DLL injection in Rust without limitations of DllMain (32 and 64-bit Intel)
View Cargo.toml
[package]
name = "dinj"
version = "0.1.0"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies.winapi]
version = "0.3"
@LunarLambda
LunarLambda / null.c
Created Dec 15, 2020
Linux - safe nullptr deref using /proc/sys/vm/mmap_min_addr (requires root)
View null.c
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main() {
int fd = open("/proc/sys/vm/mmap_min_addr", O_WRONLY);
if (fd == -1) {
@LunarLambda
LunarLambda / screenie.sh
Created Oct 25, 2020
screenie - screenshot script using maim/slop/xclip
View screenie.sh
#!/bin/sh
#
# screenie - screenshotting script
# Universal Flags
# N.B. -o disables OpenGL in Slop.
# This can rarely cause graphical distortion but allows selection screenshots in fullscreen games.
MAIM_FLAGS="-f png -m 5 -u -o"
SLOP_FLAGS="-s -b 2 -n 1"
@LunarLambda
LunarLambda / nilism.lua
Created Sep 27, 2020
nilism - no gods, no crashes, only nil
View nilism.lua
function good()
return nil
end
debug.setmetatable(nil, {
__add=good,
__sub=good,
__mul=good,
__div=good,
__mod=good,
@LunarLambda
LunarLambda / slowcat.c
Created Sep 25, 2020
slowcat - quick & dirty visualization tool for <link>
View slowcat.c
#include <stdio.h>
#include <unistd.h>
unsigned char BUF[4096] = {0};
int main() {
setbuf(stdout, NULL);
while (!feof(stdin)) {
int read = fread(BUF, 1, 4096, stdin);
@LunarLambda
LunarLambda / config
Created Sep 9, 2020
screenie - wrapper around maim/slop & xclip for fast screenshotting (+ i3 mode config)
View config
set $screenie_mode "Screenie: [S]election [W]indow [D]esktop [C]olorpicker"
mode $screenie_mode {
set $exec exec --no-startup-id
set $exit mode default
set $cmd_s screenie selection
set $cmd_w screenie window
set $cmd_d screenie screen
set $cmd_c screenie colorpicker
@LunarLambda
LunarLambda / enum_tryfrom.rs
Created Aug 22, 2020
Rust: Automatic TryFrom for C-like enums using macros
View enum_tryfrom.rs
#[macro_export]
macro_rules! enum_tryfrom {
// Grammar of a C-like Rust enum, with the addition of having `: $ty` after the name.
// We have to match it as an ident so we can pass it into `#[repr($ty)]` below.
// This unfortunately allows something like `C` or `rust` to be accepted
// if a type with that name was in scope. Let's just assume people won't do that.
// There are ways around it, but they would add extra noise to this already wacky macro.
// So this will have to do for demo purposes.
(
$(#[$outer:meta])*
@LunarLambda
LunarLambda / srcloc.rs
Created Jul 25, 2020
Tiny Rust module for displaying locations in source files.
View srcloc.rs
//! Utilities for displaying locations in source files.
use std::fmt::{self, Display, Formatter};
/// The displayed filename when reading from the standard input.
pub const STDIN_FILENAME: &str = "<stdin>";
/// The default displayed filename.
pub const DEFAULT_FILENAME: &str = "<unknown>";