Skip to content

Instantly share code, notes, and snippets.

@randomdude999
randomdude999 / countdown.cpp
Last active January 27, 2023 20:18
Solver for the problem posed in Another Roof's video about the game show Countdown
#include <array>
#include <bitset>
#include <unordered_map>
#include <iostream>
#include <vector>
// from https://github.com/martinus/unordered_dense
// direct link: https://github.com/martinus/unordered_dense/raw/v3.0.2/include/ankerl/unordered_dense.h
#include "unordered_dense.h"
@randomdude999
randomdude999 / tinysleep.asm
Last active June 28, 2023 19:11
tiny versions of the POSIX sleep utility (for x86 Linux)
; optimized version of https://reddit.com/comments/l4wfoo/_/gkrkhkb/
; usage:
; nasm tinysleep.asm
; chmod +x tinysleep
; ./tinysleep 5
bits 64
db 0x7F, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x02, 0x00, 0x3E, 0x00, 0x01, 0x00, 0x00, 0x00
db 0x78, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00
@randomdude999
randomdude999 / bfcrunch_fmt.py
Created October 23, 2019 15:39
Result formatter for BF-Crunch output
target = input("Target text: ")
total_len, init_seg = input("BFCruch output: ").split(": ")
start_pointer, _, path = input().partition(", ")
path = eval("["+path+"]")
tape_segment = eval("["+input()+"]")
tape_offset = min(x[0] for x in path)
out = init_seg
cur_pos = int(start_pointer)
@randomdude999
randomdude999 / stderr.txt
Created June 16, 2019 20:54
tcc output for a rather odd filename
$#000p#"<>:#,_@#1*66*57::*86**278\-1:*57$p
":1: error: declaration expected
@randomdude999
randomdude999 / lsc_rpl_rewrite.py
Last active September 14, 2018 21:40
lappysheep's LSCRPL rewrite
import math
import decimal
Dec = decimal.Decimal
import functools
try:
import readline
except ImportError:
pass
@randomdude999
randomdude999 / gcd_and_lcm.py
Last active November 4, 2017 12:52 — forked from endolith/gcd_and_lcm.py
GCD and LCM functions in Python
import math
import functools
# Greatest common divisor of more than 2 numbers. Am I terrible for doing it this way?
def gcd(*numbers):
"""Return the greatest common divisor of the given integers"""
return functools.reduce(math.gcd, numbers)
# Least common multiple is not in standard libraries? It's in gmpy, but this is simple enough:
@randomdude999
randomdude999 / apt-moo.patch
Last active September 3, 2016 07:40
Patch for apt moo. (Apply to apt-private/private-moo.cc, apt version 1.3_rc4)
68c68
< std::cerr << getMooLine() << std::endl;
---
> std::cerr << getMooLine(); // getMooLine already has a newline
166c166
< time_t const timenow = time(NULL);
---
> struct timespec timenow;
168c168,169
< localtime_r(&timenow, &april);
@randomdude999
randomdude999 / archive.lua
Last active May 22, 2016 18:35
ComputerCraft archive format
-- a computercraft archive format
-- by randomdude999
local function get_rel_path(file, prefix)
local file = fs.combine(file,'') -- make path more correct
local prefix = fs.combine(prefix, '')
return fs.combine(file:gsub(prefix, ''), '')
end
local function recurseList(start)
@randomdude999
randomdude999 / xkcd.py
Last active January 26, 2016 17:09
Command line xkcd client
#!/usr/bin/env python3
# A command line xkcd client
# Requires python and the requests module (available from pip)
# simplejson is recommended (from pip), but standard json will do
# readline is recommended, but not required
# Note: settings are configured for linux, on Windows you might have to change
# some settings (lines 48-51)
# Copyright © 2016 randomdude999