Skip to content

Instantly share code, notes, and snippets.

Avatar

Jōshin Steven Dee mrdomino

View GitHub Profile
View quine.hs
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 Dec 13, 2015
It’s a quine, almost.
View valenquine.hs
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)
View iter.py
#!/usr/bin/env python
"""
Example demonstrating O(1)-space iteration over binary trees.
"""
class Node(object):
"""
A binary tree node with left-child, right-child, and parent pointers.
"""
View nonascii.c
#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 Mar 25, 2017
Passphrase generator
View genpass.py
#!/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.
View 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 Aug 29, 2015
Registry sketch
View example.cc
#include <iomanip>
#include <iostream>
#include <utility>
#include "registry.h"
using std::cerr;
using std::cin;
using std::endl;
using std::ios_base;
View fib.c
#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)
View elias_unary.c
#include <hammer/glue.h>
#include <hammer/hammer.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
HParser* parser;
HBenchmarkResults* results;
View resetter.h
#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_);
You can’t perform that action at this time.