Skip to content

Instantly share code, notes, and snippets.

View DanCouper's full-sized avatar

Dan Couper DanCouper

  • Strive Gaming
  • Newcastle, UK
  • 08:34 (UTC +01:00)
  • X @DanCouper
View GitHub Profile
@DanCouper
DanCouper / machine.js
Last active January 16, 2020 14:04
Generated by XState Viz: https://xstate.js.org/viz
const TheoUserSecurityPreference = {
PIN: "PIN",
BIOMETRIC: "BIOMETRIC",
NONE: "NONE"
}
// export const bootMachine = Machine<BootMachineContext, BootMachineEvent, BootMachineSchema>({
const bootMachine = Machine<({
id: "boot",
initial: "fetchingAssets",
@DanCouper
DanCouper / coord-generator.js
Created December 18, 2019 11:33
Generates coordinates
function* coords(width, height) {
while (true) {
yield [Math.floor(Math.random() * width), Math.floor(Math.random() * height)];
}
}
function* take (n, iterable) {
for (const item of iterable) {
if (n <= 0) return;
n--;
/**
* Simple deep equal function. Note that this expects a JSON-like config object;
* it is not designed for anything more complex.
*
* @param {any} a
* @param {any} b
* @returns {boolean}
*/
export function deepEqual(a, b) {
if (Object.is(a, b)) {
@DanCouper
DanCouper / useRestApi.js
Last active July 25, 2019 23:15
useRestAPI
import React from "react";
// ex. API.get(path: string, opts:any = {}):Promise
import API from "./rest-api";
export class MissingPathError extends Error {
message = "Missing path argument.";
}
export class MissingBodyError extends Error {
message =
@DanCouper
DanCouper / reset.css
Last active August 29, 2018 13:32
Getting sick of the copy/paste/minify/copy/paste dance for this
/* Force the correct box-sizing property: */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
/* Remove margins/padding etc from everything: */
html, body, div, span, applet, object, iframe,
[
{
"name": "Instant Queue",
"videos": [
{
"id": 70111470,
"title": "Die Hard",
"boxarts": [
{
"width": 150,
defmodule MapExtras do
def take_strict!(map, keys) do
existing_keys = Map.keys(map)
case Enum.all?(keys, fn(k) -> Enum.member?(existing_keys, k) end) do
true -> Map.take(map, keys)
false -> raise "One or more of the keys passed does not exist in the map"
end
end
@DanCouper
DanCouper / right-margin.md
Created January 24, 2018 16:24
Spacemacs Notes

(referenced from syl20bnr/spacemacs#4856)

SPC t f to show the right margin line. By default this is set at 80 characters.

To activate for modes (for example):

;; Activate column indicator in prog-mode and text-mode
(add-hook 'prog-mode-hook 'turn-on-fci-mode)
(add-hook 'text-mode-hook 'turn-on-fci-mode)
/*
Given two buckets of different size, demonstrate how to measure an exact number of liters by strategically transferring liters of fluid between the buckets.
Since this mathematical problem is fairly subject to interpretation / individual approach, the tests have been written specifically to expect one overarching solution.
To help, the tests provide you with which bucket to fill first. That means, when starting with the larger bucket full, you are NOT allowed at any point to have the smaller bucket full and the larger bucket empty (aka, the opposite starting point); that would defeat the purpose of comparing both approaches!
Your program will take as input:
the size of bucket one, passed as a numeric value
/* ---------------------------
* Helpers
* --------------------------- */
/* `ReasonReact.stringToElement` is a little verbose, so alias it.
* NOTE this particular vagary get annoying quickly. */
let stringToEl = ReasonReact.stringToElement;
/* ReasonReact doesn't play nice with React Devtools. This is a pain
* point; for development, manually printing out the state turns out
* to be helpful: */