Skip to content

Instantly share code, notes, and snippets.

@ruuda
ruuda / clocks.hs
Created March 29, 2019 16:14
Clock emoji
main = putStrLn $ [1..12::Int] >>= (\t -> [t, 30 + t * 100]) >>= (\t -> ":clock" ++ (show t) ++ ": ")
@ruuda
ruuda / default.nix
Last active September 29, 2023 07:03
Monadic Nix Example
{ pkgs ?
import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/13b2903169f18ac98ed737effb36dabc48051978.tar.gz";
sha256 = "1ql9ychp7w7ciqyb7am22b9hrlsz2sppgjflgr0ffw92gvwi3m64";
}) {}
}:
with pkgs;
let
outer = stdenv.mkDerivation {
@ruuda
ruuda / printtags.sh
Created August 26, 2017 12:21
Print all tags in a directory containing flac files
metaflac --block-type=VORBIS_COMMENT --list *.flac | grep = | sed -E 's/^.+]: //' | column -s = -t | sort | uniq
@ruuda
ruuda / fire.llvmstack
Created May 21, 2017 20:52
Fire program for LLVM stack machine
r = sin(t * 0.2 + i * 7) + 0.4 * sin(t + i * 11) + 0.1 * sin(7 * t + i * 13) / 1.5
h = min(r, 0.5) * 2.0 * 0.32
s = sin(0.75pi * r + 0.25pi)
v = r
r = (sin(t * 0.2 + i * 7) + 0.4 * sin(t + i * 11) + 0.1 * sin(7 * t + i * 13)) * 0.666
h = min(r, 0.5) * 0.32
s = sin(0.75pi * r + 0.25pi)
v = r
@ruuda
ruuda / ledwall.glsl
Last active December 19, 2019 00:23
LED wall shader
// Simulates n colored point lights (LEDs) shining at a wall from a distance wd.
// Wall distance; increase for more fuzzy lights,
// decrease for sharper point lights.
float wd = 0.15f;
const int nLights = 4;
const vec3 lights[nLights] = vec3[](
vec3(1.0f, 0.0f, 0.0f),
vec3(0.0f, 1.0f, 0.0f),
#![feature(test)]
extern crate test;
macro_rules! unroll_10 {
{ $x: block } => {
$x $x $x $x $x $x $x $x $x $x
}
}
@ruuda
ruuda / kanikmijnbierbuitenzetten.html
Last active October 22, 2016 18:48
Can I keep my beer outdoors?
<html>
<!--
Copyright 2016 Ruud van Asseldonk
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
-->
<head>
@ruuda
ruuda / basic-proxy.hs
Last active July 28, 2022 16:52
Minimal proxy server in Haskell
#!/usr/bin/env stack
{- stack
--resolver lts-7.3
--install-ghc
runghc
--package base
--package bytestring
--package dns
--package http-client
--package http-types
@ruuda
ruuda / bench_texture_upload.rs
Created February 15, 2016 20:57
Benchmark Glium texture upload performance
#![feature(test)]
#[macro_use]
extern crate glium;
extern crate test;
use glium::DisplayBuild;
use glium::glutin;
fn fill_image() -> Vec<u8> {
@ruuda
ruuda / scrub.sh
Last active August 29, 2015 14:02
Scrub flac music collection
#!/bin/sh
# Timestamp starting the scrub.
echo -n 'initiating scrub at ' >> scrub.log
date >> scrub.log
# Enumerate all flac files, run `flac -tsw` (test silent, warning as error) on it,
# and output the filename to scrub.log if it fails.
find /path/to/music -type f -name '*.flac' | while read file; do
flac -tsw "$file" || echo "$file" >> scrub.log