Skip to content

Instantly share code, notes, and snippets.

View using.ts
/**
* Allocate a callback based resource, safely
*
* Example:
* function connectionResource(url) {
* return { acquire: async () => pg.connect(url), dispose: async conn => conn.dispose() }
* }
* usingPromise(connectionResource(process.env.DATABASE_URL), async conn => {
* await conn.query(...);
* do other things
View promise-dialog.tsx
/**
* Implementation of promise dialogs
*/
import { observable, action } from 'mobx';
import * as React from 'react';
import { AppSingleton } from '@h4bff/core';
import { AppContext } from '../router';
import { observer } from 'mobx-react';
interface Resolver<T> {
View hd58x-pulseeffects.json
{"output":{"equalizer":{"state":"true","num-bands":"6","input-gain":"-2","output-gain":"0","split-channels":"false","left":{"band0":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-7.4","frequency":"222.0","q":"0.230"},"band1":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"4.0","frequency":"30.0","q":"0.470"},"band2":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-2.2","frequency":"1686.0","q":"1.520"},"band3":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"2.0","frequency":"3090.0","q":"2.080"},"band4":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-3.1","frequency":"6888.0","q":"1.000"},"band5":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-1.1","frequency":"10550.0","q":"3.470"}},"right":{"band0":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-7.4","fre
View 01-before.jsx
import React, { useState, useEffect } from 'react';
function useFriendStatus(friendID) {
const [isOnline, setIsOnline] = useState(null);
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}
View exactExposedMethodReturnTypeRule.ts
import * as Lint from 'tslint';
import * as ts from 'typescript';
import { inspect } from 'util';
/**
* This rule will ensure that methods marked with the "@expose" decorator must be declared in at
* least one interface implemented by the class. It will also ensure that the return type of this
* method has no excess properties compared to those specified in the interface
*/
View class-example-ideal-react.js
const friendList = [
{ id: 1, name: 'Phoebe' },
{ id: 2, name: 'Rachel' },
{ id: 3, name: 'Ross' },
];
function useFriendStatus(component, friendID) {
const onlineStatus = component.useState(null);
const handleStatusChange = (status) => onlineStatus.set(status.isOnline);
View dayton.json
[[20, -3, 3], [20, -4, 0.6], [134, 5, 0.35], [618, 5, 0.53], [8000, 3.5, 1.3], [20000, -8, 0.4]]
View make-or-call.js
function make(classOrFn, ...args) {
if (classOrFn.toString().startsWith('class ')) {
// "real" non-compiled ES6+ only
return new classOrFn(...args);
}
let thisArg = Object.create(classOrFn.prototype);
let retVal = classOrFn.apply(thisArg, args)
if (retVal != null) return retVal;
return thisArg; //
}
View 01-validation.purs
module Main where
import Prim
import Control.Alt ((<|>))
import Control.Apply ((<*>))
import Data.Either (Either(..))
import Data.Foldable (intercalate)
import Data.Functor ((<$>), map)
import Data.String.CodePoints (contains)
View gist:4b31ec396c4cbfebede55558f6238891
```
R__________
/ \
a___ b1__
/ \ / \
a2 b3 a3 b2__
/ \ / \ / \ / \ \
e1 e2 e3 e4 e5 e6 e7 e8 e9
```