Skip to content

Instantly share code, notes, and snippets.

View ypujante's full-sized avatar

Yan Pujante ypujante

View GitHub Profile
@ypujante
ypujante / Fire.wgsl
Last active September 1, 2024 18:26
Example WebGPU Shader Toy shaders
// ported from https://www.shadertoy.com/view/4ttGWM
fn rand(n: vec2f) -> f32 {
return fract(sin(cos(dot(n, vec2f(12.9898,12.1414)))) * 83758.5453);
}
fn noise(n: vec2f) -> f32 {
const d = vec2f(0.0, 1.0);
var b = floor(n);
var f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
@ypujante
ypujante / gen_macos_iconset.py
Created November 25, 2022 18:19
Generate a macos iconset (.icns) from an svg file using Google Chrome
#!/usr/bin/env python3
import sys
import tempfile
from pathlib import Path
import subprocess
import os
import platform
scale = 1.0
@ypujante
ypujante / svg_2_png.py
Last active August 19, 2024 19:41
Convert an svg to a png using Google Chrome
#!/usr/bin/env python3
import argparse
import tempfile
from pathlib import Path
import subprocess
import os
import platform
scale = 1.0
@ypujante
ypujante / extract_vocals.py
Created October 18, 2020 18:42
python 3 script to extract vocals from a song using the Docker researchdeezer/spleeter image
#!/usr/bin/env python3
# Example:
# > cd /tmp
# extract_vocals.py '/Users/ypujante/Music/iTunes/iTunes Music/Music/Janet Jackson/Janet/08 This Time.m4a'
# Generates /tmp/08 This Time/vocals.wav and /tmp/08 This Time/accompaniment.wav
import argparse
import os
import subprocess
@ypujante
ypujante / tm-log.sh
Created September 18, 2020 13:51
Display TimeMachine logs (acts like tail -f)
#!/usr/bin/env bash
# Usage: tm-log.sh [last]
# last: displays up to "last" events before streaming. defaults to 1h (see --last option for log)
LAST=${1:-1h}
ARGS=( --info --predicate 'processImagePath contains "backupd" and subsystem beginswith "com.apple.TimeMachine"' )
# Implementation note: tr -u and sed -l are required (nothing shown until buffer full otherwise!)
#include <JukeboxTypes.h>
/**
Replace code like this:
TJBox_Value values[] = {noteCVValue, gateCVValue};
JBOX_TRACEVALUES("Note CV ^0 Gate CV ^1 ", values, 2);
with
@ypujante
ypujante / Kotlin_JS_SubmitFormViaFetch.kt
Created June 11, 2019 14:36
Example snippet code to post the content of a form to a rest api which then returns some json response using kotlin compiled (=transpiled) to javascript and the fetch api
// This is an example snippet code to post the content of a form to a rest api which
// then returns some json response using kotlin compiled (=transpiled) to javascript
//
// <form method="POST" action="<url to rest api which returns json>">
// ...fields...
// <input type="button" id="my-submit-button" value="Click Me!">
// </form>
import org.w3c.dom.HTMLInputElement
import org.w3c.xhr.FormData
@ypujante
ypujante / CLI_args_to_ktor_server.build.gradle
Last active June 4, 2019 13:30
Pass command line arguments to ktor server
// ... build.gradle
// ...
def webFolder = new File(project.buildDir, "web")
// ...
task run(type: JavaExec, dependsOn: [jvmMainClasses, jsJar]) {
main = "sample.SampleJvmKt"
classpath {
[
@ypujante
ypujante / webserver.sh
Created August 29, 2017 15:43
Start a local web server (nginx) serving local files using docker
#!/bin/bash
PORT=80
WWW_DIR=`pwd`
###############################################################################
#
# Function Name : usage()
# Arguments : N/A
# Return Result : N/A, exit 0
@ypujante
ypujante / PublishSubjectBehavior.kt
Created July 5, 2017 14:47
Backing code to Stack Overflow PublishSubject question
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import java.util.*
// see https://stackoverflow.com/questions/44634758/unexpected-behavior-with-rxjava2-publishsubject
fun withAutoConnect() {
val subject = PublishSubject.create<Int>()