Skip to content

Instantly share code, notes, and snippets.

@s4y
s4y / LICENSE.md
Created August 26, 2011 17:11
For Mac OS X: Get a list of running processes, and tell if a particular process is running, by name

Copyright (c) 2010 DeepTech, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE O

@s4y
s4y / capture_hls.md
Last active February 3, 2024 12:39
Capture an HLS stream from the beginning with ffmpeg
ffmpeg -live_start_index -99999 -i 'https://….m3u8' -c copy something.ts
#include <inttypes.h>
#include <stdlib.h>
typedef enum {
UTF8_OK = 0,
UTF8_ERROR = 4,
} utf8_decode_state_t;
typedef struct {
utf8_decode_state_t state;
@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
@s4y
s4y / mdtest.c
Created April 16, 2012 03:37
A C program that prints ANSI escapes for bold and italic Markdown text
#include <stdio.h>
#include <stdbool.h>
#define STYLE_UNDERLINE "\033[4m"
#define STYLE_NO_UNDERLINE "\033[24m"
#define STYLE_BOLD "\033[1m"
#define STYLE_NO_BOLD "\033[22m"
int main (int argc, char const *argv[]) {
@s4y
s4y / gist:1215700
Created September 14, 2011 02:12
child_process.execFile example
var child_process = require('child_process');
// exec: spawns a shell.
child_process.exec('ls -lah /tmp', function(error, stdout, stderr){
console.log(stdout);
});
// execFile: executes a file with the specified arguments
child_process.execFile('ls', ['-lah', '/tmp'], function(error, stdout, stderr){
console.log(stdout);
// 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 / 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