Skip to content

Instantly share code, notes, and snippets.

@Munksgaard
Munksgaard / flake.nix
Created February 14, 2024 18:33
elixir 1.17-dev
{
description = "elixir";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {

Futlixir

Mix.install([
  {:nx, "~> 0.6"},
  {:exla, "~> 0.6"}
])

Nx.global_default_backend(EXLA.Backend)
# Change this according to your device
################
# Variables
################
# Date and time
date_and_week=$(date "+%Y/%m/%d (w%V)")
current_time=$(date "+%H:%M:%S")
#############
@reserved_characters ~c":/?#[]@!$&'()*+,;="
@spec is_char_reserved(byte) :: boolean
defguard is_char_reserved(character) when character in @reserved_characters
MIX_ENV=prod mix run bench.exs
Operating System: Linux
CPU Information: Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
Number of Available Cores: 8
Available memory: 15.30 GB
Elixir 1.14.3
Erlang 25.3
Benchmark suite executing with the following configuration:
warmup: 2 s
// Generated by Futhark 0.25.0 (prerelease - include info below when reporting bugs)
// git: 6a2e6e1 (Sun Apr 30 19:03:19 2023 +0200) [modified]
// We need to define _GNU_SOURCE before
// _any_ headers files are imported to get
// the usage statistics of a thread (i.e. have RUSAGE_THREAD) on GNU/Linux
// https://manpages.courier-mta.org/htmlman2/getrusage.2.html
#ifndef _GNU_SOURCE // Avoid possible double-definition warning.
#define _GNU_SOURCE
#endif
def cap [n] (xs: [n]f64) =
map (\x -> x / f64.maximum xs) xs
def comb' [n] (delay: i64) (intensity: f64) (xs: [n]f64): [n]f64 =
loop xs = copy xs for i in delay..<n do
let xs[i] = xs[i] + intensity * xs[i - delay]
in xs
entry comb delay intensity = map (cap <-< comb' delay intensity)
@Munksgaard
Munksgaard / audio.fut
Created December 22, 2022 10:50
A futhark literate script showing how we can create audio
-- # Generating audio with literate Futhark
--
-- Sound is vibrations in the air that are picked up by our ears. Vibrations
-- can be described using sine-curves. Computers are ultimately discrete in
-- nature, so in order to produce sound we have to approximate sine-curves using
-- sampling. Let's see how that works in practice.
-- We start by defining some global variables that we're going to use.
-- First, the volume which we wish to output at.
@Munksgaard
Munksgaard / Makefile
Created December 20, 2022 19:15
Music in Futhark
.PHONY: all
all:
futhark c futmusic.fut
rm -f output.wav
echo "" | ./futmusic -b | tail -c+18 | head -c-1 | ffmpeg -f s8 -i - output.wav
mpv output.wav
@Munksgaard
Munksgaard / gist:f35769477104185bc529c7df43c80d75
Last active December 15, 2022 10:49
Fun types counterexamples
let (y: Int) = 42
let (xss: [y][x]Int) =
kernel x <= y do
let (xs: [x]Int) = iota(x)
in (xs)
let (z: Int) = 42
let (xs: [x]Int) =
if z then
let (x: Int) = 4