Skip to content

Instantly share code, notes, and snippets.

@s4y
s4y / lasercube.py
Last active November 14, 2023 00:41
LaserCube controller
#!/usr/bin/env python3
# This is a proof of concept for controlling a LaserCube
# (https://www.laseros.com) over the network. RUNNING THIS CODE WITH A REAL
# LASERCUBE CAN BE PHYSICALLY DANGEROUS. PLEASE BE CAREFUL, AND, IF IN DOUBT,
# USE THE SAFETY LENS!
# Copyright 2021 Sidney San Martín
#
# Permission to use, copy, modify, and/or distribute this software for any
// https://stackoverflow.com/questions/15095909/from-rgb-to-hsv-in-opengl-glsl
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
@s4y
s4y / hue.md
Created November 28, 2020 05:21
FFmpeg get hue from RGB

The following FFmpeg filter will populate the red channel of a video with the hue of the video:

geq=r='if(eq(st(3,max(max(st(0,r(X,Y)/255),st(1,g(X,Y)/255)),st(2,b(X,Y)/255))),ld(0)),(ld(1)-ld(2))/(ld(3)-min(ld(1),ld(2))),if(eq(ld(3),ld(1)),2+(ld(2)-ld(0))/(ld(3)-min(ld(0),ld(2))),4+(ld(0)-ld(1))/(ld(3)-min(ld(0),ld(1)))))*42*ld(3)'

You can make a grayscale video by appending the following:

 , geq=g='r(X,Y)':b='r(X,Y)'
@s4y
s4y / index.html
Last active August 10, 2020 13:31
A fun little button. Uses WebGL. License: CC BY 4.0
<!DOCTYPE html>
<meta name=viewport content="width=device-width">
<style>
html, body, #app {
height: 100%;
}
html {
background: rgb(220, 0, 220, 1);
}
@s4y
s4y / common
Last active April 22, 2020 23:51
Viz default state
:fn sin 1
:fn cos 1
:fn vec2.1 1
:fn vec2 2
:fn vec3 3
:fn vec3.1 1
:fn vec3.2 2
:fn vec4.1 1
:fn vec4.2 2
:fn vec4.3 3
@s4y
s4y / Whole Foods delivery watcher.scpt
Last active April 24, 2020 03:12
AppleScript which reloads a Whole Foods delivery confirmation page and displays a notification when time slots are available or it otherwise needs attention (e.g. because an item has become unavailable)
tell application "Safari"
repeat
repeat with theWindow in every window
repeat with theTab in every tab of theWindow
if name of theTab contains "Reserve a Time Slot" then
set checkoutWindow to theWindow
set checkoutTab to theTab
end if
end repeat
end repeat
@s4y
s4y / self_signed.sh
Created January 3, 2020 19:59
Generate a self-signed IP address certificate which can be installed on iOS by AirDropping cert.pem
# IP_ADDRESS_HERE -> 192.168…
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem -reqexts SAN -extensions SAN -config <(cat /System/Library/OpenSSL/openssl.cnf <(printf '[SAN]\nsubjectAltName=IP:IP_ADDRESS_HERE\nextendedKeyUsage=serverAuth\nbasicConstraints=critical,CA:TRUE'))
@s4y
s4y / raymarch_cube_slices.py
Created September 23, 2019 12:16
A ray marched cube (runs in Pythonista)
# coding: utf-8
import scene
import motion
preamble = """
precision highp float;
varying vec2 v_tex_coord;
uniform vec2 u_sprite_size;
uniform sampler2D u_texture;
# Reference: https://github.com/macvim-dev/macvim/wiki/building
class Macvim < Formula
desc "GUI for vim, made for macOS"
homepage "https://github.com/macvim-dev/macvim"
head "https://github.com/s4y/macvim.git", :branch => "stateful-render"
depends_on :xcode => :build
depends_on "cscope"
depends_on "lua"
depends_on "python"
@s4y
s4y / unbak.py
Created March 7, 2019 08:09
Recover data from Apple backup files
#!/usr/bin/env python3
# See https://www.downtowndougbrown.com/2013/06/legacy-apple-backup-file-format-on-floppy-disks/
import os
import pathlib
import struct
import sys
f = open(sys.argv[1], 'rb')