Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / index.html
Last active May 20, 2024 20:26
React, but in an Electron Fiddle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="hello-example"></div>
@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 15, 2023 15:45 — 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){
@davidsharp
davidsharp / kofi-widget.jsx
Created March 20, 2023 12:27
A Preact component for displaying Ko-fi embed
import {useEffect} from 'preact/hooks';
export default function Kofi({name='davidsharp',text='Tip Me',backgroundColor='#fcbf47',textColor='#323842'}){
const widgetScript = (`console.log('Donate @ ko-fi.com/${name}')
kofiWidgetOverlay.draw('${name}', {
'type': 'floating-chat',
'floating-chat.donateButton.text': '${text}',
'floating-chat.donateButton.background-color': '${backgroundColor}',
'floating-chat.donateButton.text-color': '${textColor}'
});`)
@davidsharp
davidsharp / nvm-symlink.sh
Created July 12, 2022 16:14
symlinking the node binary with whatever nvm has set it as
@davidsharp
davidsharp / autolink.jsx
Created June 24, 2022 09:08
Ever so slightly shorter version of the Autolink component found in 30 Seconds of Knowledge