Skip to content

Instantly share code, notes, and snippets.

View mrdomino's full-sized avatar

Steven Dee (Jōshin) mrdomino

View GitHub Profile
@mrdomino
mrdomino / quine.hs
Last active December 12, 2015 06:59
e '\\' = "\\\\"
e '\n' = "\\n"
e '\"' = "\\\""
e x = [x]
q = concatMap e
m s = s ++ "\"" ++ q s ++ "\""
main = putStrLn $ m s
where s = "e '\\\\' = \"\\\\\\\\\"\ne '\\n' = \"\\\\n\"\ne '\\\"' = \"\\\\\\\"\"\ne x = [x]\nq = concatMap e\nm s = s ++ \"\\\"\" ++ q s ++ \"\\\"\"\nmain = putStrLn $ m s\n where s = "
@mrdomino
mrdomino / valenquine.hs
Last active September 20, 2023 15:04
It’s a quine, almost.
t [] = []
t (c:[]) = []
t (c:cs) = c:t cs
g s = s ++ " and growing."
main = do
putStr s
print s
putStrLn $"m = (g.t)\n\n\n\n " ++ show m
s = "t [] = []\nt (c:[]) = []\nt (c:cs) = c:t cs\ng s = s ++ \" and growing.\"\nmain = do\n putStr s\n print s\n putStrLn $\"m = (g.t)\\n\\n\\n\\n \" ++ show m\ns = "
m = (g.t)
@mrdomino
mrdomino / iter.py
Last active September 15, 2023 01:28
#!/usr/bin/env python
"""
Example demonstrating O(1)-space iteration over binary trees.
"""
import weakref
class Node:
"""
A binary tree node with left-child, right-child, and parent pointers.
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
static void
usage(const char* argv0)
{
fprintf(stderr,
"Usage: %s\n"
" Passes spans of non-ASCII characters from stdin to stdout, "
@mrdomino
mrdomino / genpass.py
Last active March 25, 2017 22:12
Passphrase generator
#!/usr/bin/env python3
"""
Generates random memorable passphrases.
This script builds a set of unique suitable words from a dictionary file, then
produces one or more passphrases chosen at random form that set. It also
optionally prints estimates of the entropy (i.e. difficulty to guess) of the
produced passphrases based on the number of items in the set and the number of
words per phrase.
@mrdomino
mrdomino / run-synergy
Created December 11, 2014 14:12
Run synergy
#!/bin/sh
SERVER=stevens-mac-mini.local
SYNERGY_DIR="$HOME/.config/synergy"
function getpass {
cat "$SYNERGY_DIR/pass" | tr -d '\n' | md5sum | cut -d' ' -f1
}
@mrdomino
mrdomino / example.cc
Last active August 29, 2015 14:13
Registry sketch
#include <iomanip>
#include <iostream>
#include <utility>
#include "registry.h"
using std::cerr;
using std::cin;
using std::endl;
using std::ios_base;
@mrdomino
mrdomino / fib.c
Last active August 29, 2015 14:14
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
uint64_t* fibs;
size_t fib_len;
int
expand_fibs(uint64_t x)
#include <hammer/glue.h>
#include <hammer/hammer.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
HParser* parser;
HBenchmarkResults* results;
#include <utility>
template <typename T, typename U = T>
class ScopedRestore {
public:
explicit ScopedRestore(T* it):
ref_(*it), old_val_(*it) {}
~ScopedRestore() noexcept(noexcept(this->ref_ = std::move(this->old_val_))) {
using std::move;
ref_ = move(old_val_);