Skip to content

Instantly share code, notes, and snippets.

@mcky
mcky / machine.js
Created March 17, 2021 11:50
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@mcky
mcky / handler.js
Last active February 14, 2021 01:30
Sanity.io + Serverless + Algolia
const algoliasearch = require('algoliasearch');
const request = require('request');
const ndjson = require('ndjson');
const {bindNodeCallback} = require('rxjs');
const {streamToRx} = require('rxjs-stream');
const {bufferCount, map, mergeMap, toArray, tap} = require('rxjs/operators');
// Algolia configuration
const algoliaApp = process.env.ALGOLIA_APP_ID;
@mcky
mcky / groq.ts
Created November 16, 2020 14:33
typed groq queries
// Copied from https://twitter.com/MikeRyanDev/status/1308472279010025477
// Don't need most of the token parsing, but leaving it in until the POC is complete because I'll probably
// break it all trying to remove it
type Split<S extends string, D extends string> = S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
type TakeLast<V> = V extends [] ? never : V extends [string] ? V[0] : V extends [string, ...infer R] ? TakeLast<R> : never;
type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V;
type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V;
type Trim<V extends string> = TrimLeft<TrimRight<V>>;
type StripModifier<V extends string, M extends string> = V extends `${infer L}${M}${infer A}` ? L : V;
type StripModifiers<V extends string> = StripModifier<StripModifier<StripModifier<StripModifier<V, '.'>, '#'>, '['>, ':'>;
@mcky
mcky / machine.js
Last active October 27, 2020 16:34
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions

Keybase proof

I hereby claim:

  • I am mcky on github.
  • I am mcky (https://keybase.io/mcky) on keybase.
  • I have a public key ASC5egnAvqyxg8PXq4SuM0Gyt9BHCgUwoN7EvUM7F3kGXQo

To claim this, I am signing this object:

@mcky
mcky / mondo.30m.sh
Created February 1, 2016 05:55
mondo bitbar
#!/bin/bash
# Requires:
# - mondo-bank (`npm install mondo-bank -g`)
# - jq (`brew install jq`)
export PATH="/usr/local/bin:/usr/bin/:$PATH";
JSON=$(mondo balance --account_id=YOURID)
BALANCE=$(echo $JSON | jq '.balance' | awk '{print "£"$1/100}')
SPENT=$(echo $JSON | jq '.spend_today' | awk '{print "£"$1/100}')
const splitArray = (array, callback) => {
return [array.filter(i => callback(i)), array.filter(i => !callback(i))]
}
@mcky
mcky / index.html
Created December 11, 2013 03:53
Scroll progress
<div class="bar"></div>​
@mcky
mcky / New Project
Last active December 23, 2015 02:48
Creates a new github project
newproject() {
# $1 = Directory name
# $2 = Repo Name
# $3 = Readme contents
# $4 = Commit message
if [ -z "$*" ]; then
echo 'No arguments'
else
mkdir /Projects/$1;