Skip to content

Instantly share code, notes, and snippets.

View dpiponi's full-sized avatar
🧱
In material form

Dan Piponi dpiponi

🧱
In material form
View GitHub Profile
/*
* This is a literate quine. That means that
* 1. the comments will tell you a little about how it works and
* 2. if you compile and run it its output will be identical to its source
* code even though it doesn't look at its original source. It literally
* contains within itself a complete recipe for how to display itself.
*
* Quines are ten a penny. This one is unusual because
* 1. its main loop consists solely of a loop to print characters
* generated by a function called programChar() and
import System.IO
import Data.List
rot :: Int -> String -> String
rot n s =
let (body, tail) = splitAt n s
in tail ++ body
lookups :: [String] -> [String] -> [String]
lookups [] _ = []
@dpiponi
dpiponi / main.hs
Created February 17, 2018 20:16
Infinitely differentiable stochastic functions
{- LANGUAGE UnicodeSyntax -}
import Prelude hiding (sum)
import Control.Monad
import qualified System.Random as R
import qualified Data.Map.Strict as M
--
-- Define formal power series
-- I'm just using lists of coefficients rather than defining a new type.
@dpiponi
dpiponi / main.py
Created June 3, 2018 00:59
Tring to generate random vectors that look like eigenvalues of random matrices
from __future__ import print_function
import argparse
import torch
import torch.utils.data
from torch import nn, optim
from torch.nn import functional as F
from torchvision import datasets, transforms
from torchvision.utils import save_image
import numpy
This code can be used to model very unlikely disruptions to your code,
eg. hits by cosmic rays.
This is the cosmic ray monad:
> data Cosmic a = Cosmic { central::a, side::[a] } deriving Show
Cosmic a b is considered equal to Cosmic a' b' if
a==a' and b is a permutation of b'.
@dpiponi
dpiponi / shallow.py
Created July 21, 2018 18:02
Shallow image prior
# Trying to get a handle on "Deep Image Prior"
# at https://dmitryulyanov.github.io/deep_image_prior
# This is a toy version with a single purely linear
# convolution layer
# The goal is to start with an image with high res detail,
# corrupt a few bits, and then
# repair the corrupt bits using an a priori model
# that simply says "we can make the image from a lower resolution
@dpiponi
dpiponi / test.lhs
Last active August 26, 2018 10:47
Invert infinite upper triangular matrix
> scale :: Num a => a -> [a] -> [a]
> scale a bs = map (a *) bs
Invert an infinite upper triangular matrix with 1 on diagonal
[
[1, b₀₁, b₀₂, b₀₃, …],
[1, b₁₂, b₁₃, …],
[1, b₂₃, …],
]
@dpiponi
dpiponi / wasps.py
Created June 11, 2019 04:39
A neural network to learn like in the paper "Transitive inference in Polistes paper wasps"
from __future__ import print_function
import sys
# If you don't know jax, check it out
# https://github.com/google/jax
import jax.numpy as np
import jax.scipy as scipy
from jax import jit, random, value_and_grad
<html>
<body>
<button type="button" id="start">
Switch me on to start
</button>
<HR>
<div>
@dpiponi
dpiponi / README.txt
Created August 6, 2019 04:26
Sandpile emulator in 6502 assembly language for Acorn Atom.
`RUN` to assemble
`GOTO s` to start it