Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / ruby-tag.js
Last active June 23, 2020 09:23
Quick dumb tagged-template function to spit out ruby tags
const makeRuby=([bottom,top])=>`<ruby>${bottom}<rp>(</rp><rt>${top}</rt><rp>)</rp></ruby>`
const ruby = (text,...rest)=>{let output='';for(let i=0;i<text.length+rest.length;i++){output=output+(i%2==0?text[i/2]:makeRuby(rest[(i/2)-.5]))}return output}
// use like: ruby`今日は${['木曜日','もくようび']}です`
@davidsharp
davidsharp / nquik.js
Last active May 21, 2020 09:50
Quick dumb script for serving a directory through ngrok
#!/usr/bin/env /usr/local/bin/node
// run like: node nquik path/to/directory
const { exec } = require('child_process');
exec('npx simple-server '+process.argv[2]+' 8080')
exec('~/ngrok http 8080')
exec('open http://127.0.0.1:4040')
@davidsharp
davidsharp / deno.1m.js
Last active May 18, 2020 11:32
bitbar deno proof-of-concept (w/ sindresorhus' plugin dumped inline)
#!/usr/bin/env /usr/local/bin/deno run
const separator = Symbol('separator');
const darkMode = true; //process.env.BitBarDarkMode === '1';
bitbar([
{
text: '❤',
//color: bitbar.darkMode ? 'white' : 'red',
dropdown: false
@davidsharp
davidsharp / gcjewel.js
Created May 17, 2020 20:00
thrown together GC jewel design in Maker
var makerjs = require('makerjs');
var o=makerjs.model.combineUnion(
{paths:{circle:new makerjs.paths.Circle([0, 0], 78/2)}},
{models:{
rect:new makerjs.models.RoundRectangle(4,14,1)
},
origin:[-(78/2)-2,-7]
}
);
@davidsharp
davidsharp / prefs
Created April 29, 2020 18:23
my spotify prefs [~/Library/Application Support/Spotify/Users/<username>-user/prefs]
ui.hide_hpto=true
audio.play_bitrate_enumeration=4
audio.episode.speed=150
ui.show_unplayable_tracks=true
app.browser.zoom-level=-100
ui.show_friend_feed=false
audio.sync_bitrate_enumeration=4
@davidsharp
davidsharp / shuffle.6h.sh
Created April 29, 2020 11:09
bitbar plugin that provides a shuffle button for Spotify
#!/bin/bash
function shuffle(){
osascript -l JavaScript<<'END'
const spotify = Application('spotify')
if(spotify.running()){
try{
spotify.shuffling = !spotify.shuffling()
}
catch(e){''}
@davidsharp
davidsharp / animated-sync.jsx
Created April 24, 2020 08:55
snippet of an animated RN syncing 'spinner' I wrote a couple of years back (pulls back and 360s)
class AnimatedSync extends Component {
state={spinValue:new Animated.Value(0)}
constructor(props){
super(props);
console.log('AnimatedSync :::', props, this.state)
this.animate()
}
animate=()=>(
this.state.spinValue.setValue(0),
@davidsharp
davidsharp / use-context-hof-example.js
Last active April 3, 2020 15:17
Using higher-order functions to build context React hooks, based on this Kent C Dodds article: https://kentcdodds.com/blog/how-to-use-react-context-effectively
import React from 'react'
const CountStateContext = React.createContext()
const CountDispatchContext = React.createContext()
function countReducer(state, action) {
switch (action.type) {
case 'increment': {
return {count: state.count + 1}
}
@davidsharp
davidsharp / audio.1m.sh
Last active April 2, 2020 11:51
bitbar plugin that plays audio in the background, good for rain/cafe sounds
#!/bin/bash
echo "a!"
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
audio="$dir/playlist"
# for now just plays first track found in playlist
file=$(find $audio -name "*.wav" | head -n 1)
afplay "$file"
echo "$file"
@davidsharp
davidsharp / pickguard.js
Last active May 5, 2020 09:11
poc for lasercut pickguard in JS (w/ wrong measurements)
var makerjs = require('makerjs');
var points = [
[0,0],
[45,-55],
[80,-220],
[0,-180]
]
var model = new makerjs.models.ConnectTheDots(true, points);