Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / jack-o-lantern-face-bits.scad
Last active October 26, 2025 15:56
more work, with a vibed spiral function to save my brain
// Set a high fidelity for smooth curves (default is 32)
$fn = 64;
// Global radius for the face structure
radius = 50;
module spiral_2d(radius_max = 20, turns = 4, line_width = 2) {
// We sample points densely for a smooth hull
num_segments = turns * $fn;
radius_step = radius_max / num_segments;
@davidsharp
davidsharp / jack-o-lantern-mouth-happy-accident.scad
Last active October 26, 2025 13:35
Trying to update my last script, and this generates an interesting mouth, but doesn't actually do what I want, lol
radius = 50;
module smile(){
difference(){
translate([0, 0, 0])
circle(radius);
translate([0, 40, 0])
circle(radius+15);
}
}
@davidsharp
davidsharp / jack-o-lantern-mouth.scad
Last active October 25, 2025 15:07
A rough little thing for generating rough little jack-o-lantern mouths in openscad
radius = 50;
module smile(){
difference(){
translate([0, 0, 0])
circle(radius);
translate([0, 40, 0])
circle(radius+15);
}
}
@davidsharp
davidsharp / is-this-something.css
Created May 14, 2025 11:26
simple dark/light mode styles?
body, img, video {filter: invert(100%) hue-rotate(180deg);}
@davidsharp
davidsharp / shader-progress.html
Created May 8, 2024 13:55
pinched a webgl shader example and playing with shaders for use as a progress bar
<body bgcolor=black>
<canvas id='canvas1' width='1024' height='720'>
</canvas>
<button onclick="progress=Math.max(0.0,progress-0.1)">&lt;</button>
<button onclick="progress=Math.min(1.0,progress+0.1)">&gt;</button>
</body>
<script id="vs" type="x-shader/x-vertex">
attribute vec3 aPosition;
varying vec3 vPosition;
{ // must be inside our own scope here so that when we are unloaded everything disappears
// we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
let drawTimeout;
// Actually draw the watch face
let draw = function() {
var x = g.getWidth() / 2;
var y = g.getHeight() / 2;
g.reset().clearRect(Bangle.appRect); // clear whole background (w/o widgets)
g.setColor(0.2,0.2,1);
@davidsharp
davidsharp / leibniz.js
Created December 31, 2023 15:41
pi approximation in JS
const approximate_pi = n => {
let pi = 0
let denom = 1
for(let i = 0;i<n;i++){
pi += (i%2?-4:4)/denom
denom += 2
}
return pi
}
@davidsharp
davidsharp / circDepReplacer.js
Created November 22, 2023 09:58
A quick little little circular dependancy remover for JSON.stringify
function circDepReplacer(k,v){return k&&v==this?null:v}
// used like JSON.stringify(obj,circDepReplacer)
// only replaces references to main object, not sub-objects
@davidsharp
davidsharp / bluetooth.10s.sh
Last active November 12, 2024 17:36 — forked from ieatfood/Connect Airpods.applescript
A xbar/bitbar wrapper around an Applescript to connect bluetooth devices, such as Airpods.
#!/bin/bash
function pair(){
osascript <<'END'
use framework "IOBluetooth"
use scripting additions
set blueToothDevice to "Buds Pro"
on getFirstMatchingDevice(deviceName)
@davidsharp
davidsharp / getBytes.js
Created April 6, 2023 10:36
turns a byte count into an object which can be used to compose KB/MB/GB/TB/PB values
const getBytes = (bytes,{unit=null,binary=false,toFixed=1} = {}) => {
const divisor = binary?1024:1000;
let value = bytes;
let sizeLevel=-1;
const sizeArray=['KB','MB','GB','TB','PB'];
if(unit){
sizeLevel=sizeArray.indexOf(unit);
value=(bytes/Math.pow(divisor,sizeLevel+1)).toFixed(toFixed)
}
else while(value>=divisor){