Skip to content

Instantly share code, notes, and snippets.

View dan-cooke's full-sized avatar

Daniel Cooke dan-cooke

View GitHub Profile
@dan-cooke
dan-cooke / useLazyQuery.ts
Created February 9, 2022 18:57
Fully typed useLazyQuery for `react-query`
import { useCallback, useState } from 'react';
import {
QueryFunction,
QueryKey,
useQuery,
UseQueryOptions,
UseQueryResult,
} from 'react-query';
type UseQueryParams = Parameters<typeof useQuery>;
'use strict';
var container = document.getElementById('container');
//create resource locally for testing
var stylesheet = '#container{background: red; width: 100px; height: 100px; display: block;}';
var sBlob = new Blob([stylesheet], { type: 'text/css' });
//get blob as a blob: url
@dan-cooke
dan-cooke / chessKata.js
Last active June 29, 2017 14:58
Chess Kata - WIP
// Returns an array of threats if the arrangement of
// the pieces is a check, otherwise false
var getMoves = function getMoves(p, board) {
var x = p.x;
var y = p.y;
var getPawnMoves = function getPawnMoves(p, x, y) {
if (p.owner == 0) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.js"></script>
abstract class AnimationState {
abstract name : string;
sprite: Sprite;
constructor(context? : Sprite, state? : AnimationState){
if(context)
this.sprite = context;
else if(state){
"use strict";
var Stream = (function () {
function Stream(val) {
this._source = new Rx.BehaviorSubject(val);
this._obs = this._source.asObservable();
return this._obs;
}
return Stream;
}());
//module test
'use strict';
//the namespace that will be exported
var myModule = {};
//wrapper function to export all as one namespace
(function wrapper(exports) {
(function existsModule(exports) {
@dan-cooke
dan-cooke / definePropertyDemo.js
Last active May 23, 2017 09:51
JS defineProperty demo
'use strict';
var t = {
mutableProp: 'helloWorld'
};
//by default Object.defineProperty creates an immutable property that is not enumerable
Object.defineProperty(t, 'immutableProp', {
value: 'worldHello!',
configurable: true