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 / 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
@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;

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:

const splitArray = (array, callback) => {
return [array.filter(i => callback(i)), array.filter(i => !callback(i))]
}
@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}')
@mcky
mcky / main.scss
Created December 17, 2015 11:27
Specificity override function/mixin
#{specificity('.one', 5)} {
background: purple;
}
@include specificity('.two', 5) {
background: red;
}
/*
* Outputs
@mcky
mcky / ToggleBtn.js
Last active December 3, 2015 13:01 — forked from sanjaypoyzer/ToggleBtn.js
Toggle this.state.thing
toggleThing: function(thing){
this.setState({
[thing]: !this.state[thing]
})
}