Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@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
@davidsharp
davidsharp / force-xhr-status-with-proxy.js
Created April 22, 2022 10:27
Proxying a XMLHttpRequest to force the status received
XMLHttpRequest = new Proxy(XMLHttpRequest, {
construct:function(t,a){
const req = new t();
return new Proxy(req, {
get:function(o,p){
if(p=='status')return 9001
return typeof o[p] == 'function'?o[p].bind(o):o[p]
},
set: function(target, prop, value) {
Reflect.set(target, prop, value) // or target[prop] = value
@davidsharp
davidsharp / rot13.js
Created February 19, 2022 17:10
Dirty little ROT13 function
const rot13 = str => str.replace(/[a-z]/gi,x=>{
const c=x.charCodeAt(0)
const a=c>=97?97:65
return String.fromCharCode(
a+((c-a+13)%26)
)
})
@davidsharp
davidsharp / triangular-number.js
Created December 17, 2021 10:23
Finds triangular number (or x + x-1 + x-2, etc down to 0)
const fn = x => x + (x * ((x-1)/2))
@davidsharp
davidsharp / remark-star-wipe.css
Last active November 26, 2021 10:20
A neat little star wipe for Remark.js presentations
@-webkit-keyframes wipe {
0% {
-webkit-mask-size: 0% 0%;
}
100% {
-webkit-mask-size: 550% 550%;
}
}
.remark-visible .remark-slide-content {
@davidsharp
davidsharp / animated-sync-icon.jsx
Created October 28, 2021 09:31
An old animated sync icon, for an old version of React Native (0.40.0)
import React, {
PropTypes, Component
} from 'react';
import {
Animated, Easing
} from 'react-native';
// BYO sync icon
const SYNC = require('../images/sync.png')
@davidsharp
davidsharp / townscaper-overlook
Created October 27, 2021 13:29
Overlook, a Townscaper town with small quaint buildings and overbearing towers
HzRBnyQt1d2e-uD5L6T7PJdXrnt7_9Q_0_wNPSvW3Z797p9nAsLydSubwj0r1w273L6hdav9pk3mHpXrnt3v7iebbfm4J5uNPSvW3AAzZ7972F9NGAAAEE0yGAAE0nAuLytdSebCAkkkj0Bggctutw2LKApTLAobMAIJJJJpPBcXi7k82cbHpbL5a9QWSSXUAQ60CAS3YAQfC4l4J5t5RKAzhskk0FFA0pFA0nAidJujEAkDJA9JgbXib7kAAJ5IBA5sBAI5TAAQuEAQOJAQzRCAz1CASQ_UCAgckAgctAgc2Ag8pEAI52AA5IBA5aBA5TJAQSuNAQQOSAQQSO
@davidsharp
davidsharp / jump.css
Last active October 22, 2021 08:17
Lousy alternating jumping styles (good for jumping pumpkins 🎃)
.jump {
display: inline-block;
animation-duration: 1.5s;
animation-name: jump;
animation-iteration-count: infinite;
}
.jump.alt {
animation-delay: .75s;
}
@keyframes jump {