Skip to content

Instantly share code, notes, and snippets.

View stash's full-sized avatar
🎯
Focusing

Jeremy Stashewsky stash

🎯
Focusing
View GitHub Profile
@stash
stash / led-test.js
Created December 4, 2020 22:35
Prototype "blinky" host scripts for QMK keyboards over Raw HID
// Raw HID "blinky" interface protocol test script
// Can also be modified to identify the LED index of each key!
const EventEmitter = require('events');
const HID = require('node-hid');
const VENDOR_ID = 12951;
const PRODUCT_ID = 18806;
const RAW_USAGE_PAGE = 0xFF60;
const RAW_USAGE_ID = 0x61;
@stash
stash / DistanceMatrix.cs
Last active April 2, 2024 11:53
Efficient distance matrix storage structure in C#
/// <summary>
/// Efficient storage of a distance matrix.
/// </summary>
/// <remarks>
/// This is a storage space efficient data-structure for edge weights in an undirected graph, where edges are specified as a pair of integer verticies.
///
/// Let "dAB" be the distance from point A to point B, where A and B are positive integers indexing points.
///
/// A full, unoptimzied matrix would look like this:
/// <code>
@stash
stash / heartbeat.hlsl
Last active February 18, 2020 23:43
Heartbeat function in HLSL
// Approximates a heartbeat
// Roughly approximates mathematical formula:
// x = t * f * PI
// y = h * sin(x)^(2 * p + 1) * sin(x + d)
// where
// f is frequency in Hz if t is fractional seconds
// p is a power factor (the "slope" of the main upswing of the wave)
// d is an "offset" that shifts the peak and trough heights
// h is an overall height factor
//
@stash
stash / branchless-template.hlsl
Last active March 6, 2020 03:39
Branchless logic functions for HLSL
/// NOTE: Apparently this whole "branchless" thing a Generally Bad Idea; it makes the code slower and complex in a lot of cases!
/// Conditional-move is a thing on GPUs too, and can make using these sort of gymnastics obsolete.
/// See this epic twitter thread: https://twitter.com/bgolus/status/1235254923819802626
// from http://theorangeduck.com/page/avoiding-shader-conditionals
// TYPE needs to be defined before including this file
TYPE when_eq(TYPE x, TYPE y) {
return 1.0 - abs(sign(x - y));
}
@stash
stash / README.md
Last active August 19, 2018 01:51
Routing around Cortana and Edge on Windows 10

I really enjoy being able to use the windows key to open applications and control panels in Windows 8.1. These settings bring it back to about the same sort of behaviour.

This is an open work-in-progress and might mess up your install!

The below is valid for Windows 10 v1803, roughly August 2018.

Create a system restore point before doing this, just in case. ;)

1. Configure Cortana in Settings

@stash
stash / adobe-pan.lua
Created May 16, 2018 18:19
Logitech gsuite script for middle-mouse button panning in illustrator and photoshop
-- The following code is in the public domain
--
-- Logitech g-suite script that binds middle mouse button to "SHIFT + LMB"
--
-- Holding spacebar in Illustrator or Photoshop (CC 2018-ish) allows you to pan the screen around with a left mouse drag
--
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
-- 57 == 0x39 == "spacebar"
PressKey(57);
@stash
stash / AutoLoadGlobalScene.cs
Created April 1, 2018 23:57
AutoLoadGlobalScene - automatically and additively load a global scene in the Unity editor
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;
using System;
// Automatically load additively a "global" scene when the user opens a scene in the Editor
// Just put this file in your project and EDIT the two settings below!
[InitializeOnLoad]
public class AutoLoadGlobalScene {
@stash
stash / GlobalObject.cs
Created March 30, 2018 22:18
GlobalObject.cs
using UnityEngine;
/**
* Singleton-esque inter-Scene GameObject loader.
*
* Ever wanted a singleton or global sort of GameObject that still allowed for editing properties in the Unity Editor?
* I sure did, for things like background music, a game controller, etc. So, I made this simple system of creating a global or "inter-scene" GameObject. It's not a true singleton, but it does a good job at ensuring there's only GameObject with this script attached. I don't like the approach of creating a persistent, additively-loaded scene -- not to mention the other approaches to making true Singleton objects -- so I've opted for a pre-fabbable GameObject approach.
*
* HowTo, in the Unity Editor (tested with 2017.3.1f1):
* 1. Attach this script to an empty GameObject in the current scene.
using UnityEngine;
public class AudioLoopWithIntro : MonoBehaviour {
public AudioSource introSource;
public AudioSource loopSource;
private void Start() {
// start the intro clip immediately
introSource.Play();
@stash
stash / toss.js
Last active January 16, 2018 19:35
(╯°□°)╯︵ ┻━sſ̣˙ssoʇ ‘ʎɔuǝɓɹǝɯǝ ɟo ǝsɐɔ uı̣━┻
#!/usr/bin/env node
/*
* (╯°□°)╯︵ ┻━sſ̣˙ssoʇ ‘ʎɔuǝɓɹǝɯǝ ɟo ǝsɐɔ uı̣━┻
*/
var startToss = "(╯°□°)╯︵ ┻━";
var endToss = "━┻";
var flipTable = {
" ":" ",