Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / sway.css
Last active October 21, 2021 23:37
A short and sweet CSS snippet for slightly spooky swaying text and more
.sway {
display: inline-block;
animation-duration: 2s;
animation-name: sway;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
}
@keyframes sway {
from {
@davidsharp
davidsharp / local-storage-proxy.js
Created August 17, 2021 13:08
Example of using JS proxies as a wrapper for localStorage
// localStorageProxy.foo = 'bar'
// -> localStorage.getItem('foo') = 'bar'
localStorageProxy = new Proxy(localStorage, {
get: (r,n)=>r.getItem(n),
set: (r,n,v)=>r.setItem(n,v),
deleteProperty: (r,n)=>r.removeItem(name)
})
// reverses the vowels of a (lowercase) word
(
s=>(r=/[aeiou]/g,x=s.match(r),c=x.length,s.replace(r,_=>x[--c]))
)('geographically') // -> gaigraphocelly
// sorts the vowels in a (lowercase) word
(
s=>(r=/[aeiou]/g,x=s.match(r).sort(),c=0,s.replace(r,_=>x[c++]))
)('crocodile') // -> crecidolo
@davidsharp
davidsharp / autorun-retropie.js
Created May 1, 2021 19:30
(untested) interruptable node.js script for autorunning retropie on a raspberry pi
const child_process = require('child_process')
const readline = require('readline');
let bootRP = true;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
@davidsharp
davidsharp / deno-bitbar-template.js
Created February 5, 2021 10:16
Template for a(n uncompiled) deno bitbar plugin
#!/usr/bin/env -S /usr/local/bin/deno run
import bitbar from 'https://esm.sh/bitbar';
bitbar([
{text: `Yo!`}
])
@davidsharp
davidsharp / asar-rn.js
Created January 20, 2021 12:16
Read asar headers and naively unpack them
import {read,writeFile,mkdir} from 'react-native-fs';
var Buffer = require('buffer/').Buffer;
import pickle from 'chromium-pickle-js';
// read an asar and return its header data
// expects to take a valid asar path
// returns an object with the file structure, header size and asar path (for later reference)
const readAsarHeader = async archive => {
let size;
let headerBuf;
@davidsharp
davidsharp / covid-diseasesh.30m.js
Last active May 24, 2021 15:25
bitbar plugin that grabs some localised COVID-19 stats from https://disease.sh
#!/usr/bin/env /usr/local/bin/node
const bitbar = require('bitbar');
const http = require('https');
const fetch = require('node-fetch')
var emojiFlags = require('emoji-flags');
// change me for your country
const region = 'UK'
http.get(`https://disease.sh/v3/covid-19/countries/${region}`, async (res) => {
@davidsharp
davidsharp / circular-array-index.js
Created December 23, 2020 11:38
Quick little function for getting indexes in arrays cyclically (-1 = last element, length+1 = first element)
const getIndex = (array,index) => array[(array.length+index)%array.length]
@davidsharp
davidsharp / reorder.js
Created November 13, 2020 16:19
move an item in an array up or down by an amount
const reorder = (array, index, moveBy) => {
let temp = array.map((c,i)=>([c,i]))
temp[index][1]=temp[index][1]+moveBy+(moveBy>0?.5:-.5)
return temp.sort((a,b)=>a[1]-b[1]).map(c=>c[0])
}