Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@evincarofautumn
evincarofautumn / matches.ktn
Last active December 20, 2015 12:18
Using pattern matching to do pattern matching
// Tests whether a string matches a file glob pattern, in
// which '*' matches any number of characters, '?' matches
// a single character, and anything else matches itself.
def matches:
->{ string pattern }
if (string pattern {isEmpty} on &&): true
else:
false
string peel ->{ ms ss }
option ms: ->s
@evincarofautumn
evincarofautumn / yubikey-scrabble.pl
Last active December 20, 2015 14:18
Finding the best Scrabble word that could appear in a YubiKey password.
#!/usr/bin/env perl
#
# yubikey-scrabble.pl
#
# Finding the best Scrabble word that could appear in a YubiKey password.
#
# cpan List::UtilsBy
# chmod +x yubikey-scrabble.pl
# ./yubikey-scrabble.pl
@evincarofautumn
evincarofautumn / convolve.cpp
Created August 22, 2013 20:56
Experimenting with space-filling curve access order for image convolution.
#include <array>
#include <cstdint>
#include <cstdlib>
#include <climits>
using namespace std;
uint32_t interleave(const uint16_t x, const uint16_t y) {
uint32_t result;
for (int i = 0; i < sizeof(uint16_t) * CHAR_BIT; ++i)
result |= (x & 1u << i) << i | (y & 1u << i) << (i + 1);
def s{><replicate}
getLine{' 'neChar}span{readInt fromSome}toBoth->{w n}
w 0 if(n 2>){><}..
{<>w>< -{'X's}{' 's}both if(n 2%0=){><}cat say}each
@evincarofautumn
evincarofautumn / overloaded-lambdas.cpp
Created August 29, 2013 19:53
Overloaded lambdas in C++11.
#include <iostream>
#include <string>
#include <utility>
using namespace std;
template<class... Fs> struct Overload;
template<class F, class... Fs>
struct Overload<F, Fs...> : Overload<Fs...> {
@evincarofautumn
evincarofautumn / token-pasting.c
Last active December 22, 2015 10:29
Token pasting junk.
#define CAT(A, B) A##B
#define CAT_(A, B) CAT(A, B)
#define QUOTE(A) #A
#define QUOTE_(A) QUOTE(A)
#define PREFIX __
#define SYMBOL(A) QUOTE_(CAT_(PREFIX, A))
SYMBOL(hello)
@evincarofautumn
evincarofautumn / ghcfilt
Last active December 23, 2015 13:49
A simple decoder like `c++filt` for z-encoding–mangled names.
#!/usr/bin/perl
# Originally written and placed in the public domain by Ashley Yakeley, 2003.
use warnings;
use strict;
use Pod::Usage;
use Getopt::Long;
my $help = 0;
@evincarofautumn
evincarofautumn / gist:3c2309e7941751573eb4
Created August 14, 2014 05:02
Statistical manipulations in Kitten.
// “μσ” calculates the mean and standard deviation of a list, given the sum of the squares of the elements, the sum of the elements, and the reciprocal of the length. Uses real characters for more mathiness.
// With local variables, in infix:
def μσ (float float float → float float):
→ ss s in;
s ×. in → μ;
(ss ×. in −. μ sq) sqrt → σ;
μ σ
// With local variables, in postfix:
@evincarofautumn
evincarofautumn / adaptive-wrap-fill-context-prefix
Last active August 29, 2015 14:05
Hack to make “adaptive-wrap-prefix-mode” work with tabs and show a fill indicator.
(defun adaptive-wrap-fill-context-prefix (begin end)
"Like `fill-context-prefix', but with length adjusted by `adaptive-wrap-extra-indent'."
;; Note: fill-context-prefix may return nil; See:
;; http://article.gmane.org/gmane.emacs.devel/156285
(let* ((fcp (or (fill-context-prefix begin end) ""))
(fcp-len (string-width fcp)))
(if (>= adaptive-wrap-extra-indent 0)
(concat (make-string fcp-len ?\ )
"│"
(make-string adaptive-wrap-extra-indent ?\ ))
@evincarofautumn
evincarofautumn / sigsegv-experiments.c
Last active August 29, 2015 14:07
SIGSEGV experiments
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
static char *buffer1;
static char *buffer2;
static const int page_size = 1 << 12;