Skip to content

Instantly share code, notes, and snippets.

View DanCouper's full-sized avatar

Dan Couper DanCouper

  • Strive Gaming
  • Newcastle, UK
  • 11:36 (UTC +01:00)
  • X @DanCouper
View GitHub Profile
@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 =
/**
* 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 / 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--;
@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 / machine.js
Created January 16, 2020 16:33
Generated by XState Viz: https://xstate.js.org/viz
const TheoUserSecurityPreference = {
PIN: "PIN",
BIOMETRIC: "BIOMETRIC",
NONE: "NONE"
};
// services
async function cacheStaticImages() {
console.log("Images cached")
return;
@DanCouper
DanCouper / CodeInput.jsx
Created January 23, 2020 12:00
Rough draft of a generic code input component
import React from "react";
import { StyleSheet, Text, TextInput, View } from "react-native";
/* --------------------------------------- *\
* Local versions of imported modules,
* just for isolated testing.
\* --------------------------------------- */
const s = StyleSheet.create({
white: { color: "#ffffff" },
bg_mid: { backgroundColor: "#1A5163" },
@DanCouper
DanCouper / machine.js
Last active March 23, 2020 16:08
Generated by XState Viz: https://xstate.js.org/viz
const authMachine = Machine({
id: 'auth',
initial: 'idle',
context: {
error: null,
isAuthorised: false,
retries: 3,
},
states: {
idle: {
@DanCouper
DanCouper / artist.ex
Last active May 10, 2020 13:40
collection schemas
defmodule Collection.Artist do
use Ecto.Schema
schema "artists" do
field(:name, :string)
end
def changeset(struct, params) do
struct
|> Ecto.Changeset.cast(params, [:name])
@DanCouper
DanCouper / machine.js
Last active November 3, 2020 14:50
Generated by XState Viz: https://xstate.js.org/viz
const timermachine = Machine({
id: "timer",
initial: "inactive",
context: {
breakLength: 10,
breakRemaining: 0,
sessionLength: 10,
sessionRemaining: 0,
cooldownLength: 1,
cooldownRemaining: 0,
@DanCouper
DanCouper / zx_example_1.md
Created June 3, 2021 11:35
Examples of executable (via `zx`, using v1.14.1) markdown scripts. First one works, next two do not for described reasons

Expected Behavior

Only code I want to execute should execute.

Actual Behavior

Anything in either a fenced block or indented by 4 spaces/tab blindly executes.

Steps to Reproduce the Problem