Skip to content

Instantly share code, notes, and snippets.

View aynik's full-sized avatar

Pablo Vazquez aynik

View GitHub Profile
@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'
@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 / 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 / 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 / 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 / models.py
Last active November 10, 2020 14:31
from django.db import models
class Item(models.Model):
title = models.CharField(max_length=128)
class GroupItems(models.Model):
group = models.ForeignKey(Group)
item = models.ForeignKey(Item)
class Group(models.Model):
class FieldRoot(object):
def __init__(self, __id__, __parent_repr__=lambda x: x):
self.__id__ = __id__
self.__parent_repr__ = __parent_repr__
def __repr__(self):
return self.__parent_repr__(self.__id__)
def __embed__(self, child, __id__):
return child(__id__,
const SOLID = "SOLID";
const LIQUID = "LIQUID";
const GAS = "GAS";
const transitions = {
[SOLID]: {
melt: LIQUID,
sublimate: GAS,
},
[LIQUID]: {
#!/usr/bin/env node
// discogs2spotify <spotify-playlist-id> <start-year>-<end-year> [discogs search params]
const args = require("minimist")(process.argv);
const Spotify = require("spotify-web-api-node");
const Discogs = require("disconnect").Client;
const Confirm = require("prompt-confirm");
const Prompt = require("prompt-base");
const DISCOGS_USER_TOKEN = "<DISCOGS_USER_TOKEN>";
@aynik
aynik / ping-rng.js
Created March 31, 2018 10:27
Entropy from ping roundtrips
#!/usr/bin/env node
// requires: npm i -g get-stdin net-ping
// usage: ping-rng [bits?] < hosts
const stdin = require('/usr/local/lib/node_modules/get-stdin')
const ping = require('/usr/local/lib/node_modules/net-ping')
let sid = 0
const probe = async (hosts) => {