Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / recursive-promise.js
Last active July 14, 2017 13:58
A (probably stupid) recursive promise example, certainly not a drop-in function
//I've not tested this yet, it's an idea, that might become a proof of concept
//It could definitely do with a clean, and eventually a nice re-usable function call
__granularChangePush(changes){
if(changes.length>0 && typeof this.__api == 'function'){
return recursivePromise(this.__api.bind(this),changes,0)
}
function recursivePromise(_list,index){
return new Promise((resolve,reject)=>{
createRecursivePromise([_list,index],(list)=>{(list.length>0?resolve:reject)(l)},doStuff)
@davidsharp
davidsharp / .dump.bash
Last active November 23, 2024 16:13
dot file dump functions and aliases for bash
# below is my prompt-y bit of choice: `current-dir ~ `
#export PS1="\[\e[33m\]\W \[\e[35m\]~ \[\e[m\]"
#export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
# or something a little fancier: `current-dir <random fruit>`
#FRUITS=(🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🍒 🍑 🍍 🥝)
#export PS1="\[\e[33m\]\W \[\e[35m\]${FRUITS[$(echo $RANDOM%12 | bc)]} \[\e[m\]"
# for a new fruit on each line, rather than one per session
# export PROMPT_COMMAND='echo -ne "${FRUITS[$(echo $RANDOM%12 | bc)]} "'
alias zed="open -a /Applications/zed.app"
@davidsharp
davidsharp / get-rekt.js
Created August 30, 2017 14:10
Quick PNG transparent (rounded) rectangle-ify-er
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const cmdr = require('commander');
//this requires Cairo: https://www.npmjs.com/package/canvas
// brew install pkg-config cairo libpng jpeg giflib
const Canvas = require('canvas');
const Image = Canvas.Image;
@davidsharp
davidsharp / canvas-arrow.js
Last active September 5, 2017 09:38
Quick + dirty arrow drawing function (currently only left->right)
// use like:
// ctx.fillStyle='rgba(256,256,256,1)';
// arrow(ctx, img.width/2, img.height/2, 90, 60);
function arrow(ctx, x, y, width, height) {
// x and y are the center
//TODO: take a direction, currently l->r
ctx.beginPath();
ctx.moveTo(x - (width/2), y-(height/2)+(height/3));
// down
ctx.lineTo(x - (width/2), y-(height/2)+(height/3*2));
@davidsharp
davidsharp / 2d-join.js
Created September 19, 2017 10:44
Join 2 dimensional string arrays
// Say we have `names=[['johnny','rotten'],['gene','simmons']]` and want `johnny rotten and gene simmons`
// `join2D(names,' ',' and ')`
const join2D = (names, sep1, sep2) => (names.map(n=>n.join(sep1)).join(sep2))
@davidsharp
davidsharp / sorted-img.js
Last active September 22, 2017 16:03
A quick dump of circle-clip.js, but with butter.js inline, pixel-sorting the circle contents
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const cmdr = require('commander');
//this requires Cairo: https://www.npmjs.com/package/canvas
// brew install pkg-config cairo libpng jpeg giflib
const Canvas = require('canvas');
cmdr
@davidsharp
davidsharp / my-first-graphql-request
Created October 18, 2017 11:26
Goofing around with GitHub's GraphQL API, grabs the path and description of gists of the viewer – https://developer.github.com/v4/explorer/
query {
viewer {
#user(login:"davidsharp"){
login
gists(last:50){
nodes{
path: name
description
isPublic
}
@davidsharp
davidsharp / kringle.js
Last active October 23, 2018 14:27
a lousy half-baked toy secret santa sorter that might one day work
/*
EXAMPLE:
const kringle = new Kringle([
{name: 'foo bar', email: 'foobar@baz.com', group:1},
{name: 'bar baz', email: 'barbaz@foo.com', group:1},
{name: 'baz foo', email: 'bazfoo@bar.com', group:2},
{name: 'foo baz', email: 'foobaz@bar.com', group:3},
])
kringle.run()
kringle.list.forEach((c,i)=>(
@davidsharp
davidsharp / list-to-json-array.js
Created November 7, 2017 16:19
Turn a big text list into a sorted array, minus all the duplicates
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs');
const cmdr = {path:process.argv[process.argv.length-1]}
console.log('Manipulating : '+cmdr.path);
if(!cmdr.path){console.log('No path given');process.exit();}
@davidsharp
davidsharp / flippin-tile.js
Last active November 13, 2017 13:25
Naive image tiler, which does some flipping at the edges for pretty patterns
#!/usr/bin/env node
'use strict';
// > npm i -g commander; npm i -g canvas;
// this also requires Cairo: https://www.npmjs.com/package/canvas
// > brew install pkg-config cairo libpng jpeg giflib
const path = require('path');
const fs = require('fs');
const cmdr = {path:process.argv[process.argv.length-1]}