Skip to content

Instantly share code, notes, and snippets.

View aynik's full-sized avatar

Pablo Vazquez aynik

View GitHub Profile
@aynik
aynik / fsm.ts
Last active May 18, 2021 13:51
Strongly typed FSM
type Transitions<T, P> = {
[K in keyof Partial<T>]: (
payload: P
) => {
type: keyof T & T[K];
payload: P;
} | void;
};
function createReducer<T, P>(transitions: Transitions<T, P>) {
@aynik
aynik / optics.ts
Created July 25, 2021 04:07
Typescript Optics
export interface Lens<A, B> {
(a: A): B;
(a: A, b?: B): A;
}
export function prism<A, B>() {
return function (get: (a: A) => B, set: (a: A, b?: B) => A): Lens<A, B> {
function prismImpl(a: A): B;
function prismImpl(a: A, b?: B): A;
function prismImpl(a: A, b?: B): B | A {
@aynik
aynik / proxyLens.ts
Last active August 1, 2021 14:11
Type safe proxy lens
export type Getter<A, B> = (a: A) => B;
export type Setter<A, B> = (b: B, a: A) => A;
export type ProxyLensOperations<A, B> = {
get(a?: A): B;
set(b: B, a?: A): A;
put(b: B, a?: A): ProxyLens<A, A>;
mod(mod: (b: B) => B): ProxyLens<A, B>;
iso<C>(bcGet: Getter<B, C>, bcSet: Setter<B, C>): ProxyLens<A, C>;
};
@aynik
aynik / index_1.js
Last active December 27, 2021 02:04
Augmented Storefront API Example
import express from "express";
import { graphqlHTTP } from "express-graphql";
import { introspectSchema, wrapSchema } from "@graphql-tools/wrap";
import { stitchSchemas } from "@graphql-tools/stitch";
import { print } from "graphql";
import fetch from "node-fetch";
@aynik
aynik / in.sh
Created January 23, 2022 15:57
audio io
#!/usr/bin/env bash
TMP_INPUT=$(mktemp)
PARTS="$TMP_INPUT 1 $TMP_INPUT 2"
SAMPLE_RATE="${SAMPLE_RATE:=16000}"
N_POINTS="${N_POINTS:=64}"
FREQUENCIES="${FREQUENCIES:=1000,6000}"
halve $1 $TMP_INPUT
echo $PARTS | env SAMPLE_RATE=$SAMPLE_RATE N_POINTS=$N_POINTS FREQUENCIES=$FREQUENCIES \
xargs -P 2 -n 2 bash -c 'amodem send -i $0.$1 -o $0.$1.raw'
#!/usr/bin/env bash
set -eu
SKIP_TRACKS=$((${SKIP_TRACKS:=0} + 1))
while ALBUM="$1" && [ ! -z "$ALBUM" ]; do
find "$ALBUM" -iname "*.flac" \
| sed -e 's:\(.*/\)\([^/]*\):\2 \1\2:' \
| sort -n \
| sed -e 's:[^/]* ::' \
@aynik
aynik / sox-coreaudio-full-device-names.patch
Created February 13, 2022 17:22
Sox coreaudio full device names
--- src/coreaudio.c
+++ src/coreaudio.c
@@ -152,6 +152,7 @@ static int setup(sox_format_t *ft, int is_input)
for (i = 0; i < device_count; i++)
{
char name[256];
+ property_size = sizeof(name);
status = AudioDeviceGetProperty(devices[i],0,false,kAudioDevicePropertyDeviceName,&property_size,&name);
lsx_report("Found Audio Device \"%s\"\n",name);
@aynik
aynik / modem-qam.py
Last active February 12, 2024 13:45
QAM/OFDM Audio Modem
#!/usr/bin/env python3
import os
import sys
import types
import struct
import itertools
import functools
import collections
@aynik
aynik / .bashrc
Created April 6, 2022 02:51
Bashrc lite
# Path
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Return if non-interactive
case $- in
*i*) ;;
*) return;;
esac
shopt -s histappend
@aynik
aynik / deinterleave.c
Last active June 8, 2022 09:13
interleave / deinterleave
#!/usr/bin/env C -m
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void deinterleave(const char *out_even_fname, const char *out_odd_fname, int bytes)
{
int c;
FILE *fout_odd, *fout_even;
fout_odd = fopen(out_odd_fname, "wb");