Skip to content

Instantly share code, notes, and snippets.

View kossnocorp's full-sized avatar
Shipping

Sasha Koss kossnocorp

Shipping
View GitHub Profile
"C:\Program Files\VcXsrv\vcxsrv.exe" :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto
@kossnocorp
kossnocorp / useEvent.ts
Created March 24, 2022 12:07
Preact event/dispatch hook
import { useEffect } from 'preact/hooks'
/**
* Generates an event hook / dispatch function pair for the given payload.
*
* @returns the hook and dispatch functions
*/
export function createEventHooks<Payload>() {
const { useEvent, dispatchEvent } = createEventsHooks()
const event = Date.now().toString()
@kossnocorp
kossnocorp / usePromise.ts
Last active April 28, 2022 04:28
Promise hooks
import { useEffect, useMemo, useRef } from 'preact/hooks'
/**
* The {@link usePromise} resolve function.
*/
export type UsePromiseResolve<Type> = (value: Type) => void
/**
* The {@link usePromise} reject function.
*/
@kossnocorp
kossnocorp / cypress.ts
Last active October 19, 2021 09:47
Solve Jest/Cypress conflict when using with Testing Library by using these custom wrappers:
/**
* The code is based on Gleb Bahmutov's [local-cypress](https://github.com/bahmutov/local-cypress).
*/
/// <reference types="cypress" />
/// <reference types="@testing-library/cypress" />
const win = window as unknown as Window & {
assert: Chai.AssertStatic
expect: Chai.ExpectStatic
@kossnocorp
kossnocorp / module.ts
Last active November 5, 2020 07:09
Source code with an example of hoisting usage
import {
defaultNumberingPosition,
defaultNumberingStyle,
NumberingFormatOptions,
NumberingPosition,
NumberingStyle,
} from '#app/core/split/parse'
export function stripNumbering(
text: string,
@kossnocorp
kossnocorp / buildFunctions.ts
Created October 28, 2020 11:46
My Firebase Functions esbuild setup
import { build } from 'estrella'
import fs from 'fs'
import { promisify } from 'util'
import packageJSON from '../package.json'
import listFunctions from './_lib/listFunctions'
const writeFile = promisify(fs.writeFile)
const external = Object.keys(packageJSON.dependencies)
const appEnv = process.env.APP_ENV
const rootPath = process.cwd()
var errorsStash = []
var errorListener = function(e) {
errorsStash.push(e.error)
}
var unhandledRejectionListener = function(e) {
errorsStash.push(e.reason)
}
window.addEventListener('error', errorListener)
window.addEventListener('unhandledrejection', unhandledRejectionListener)
window.__passOnToSentry__ = function() {
@kossnocorp
kossnocorp / Makefile
Last active October 13, 2019 05:44
Demo of the problem for a Stack Overflow questions
SHELL := /bin/bash
PATH := $(shell yarn bin):$(PATH)
test:
which ts-node
${shell yarn bin}/ts-node --version
ts-node --version
diff --git a/tsconfig.json b/tsconfig.json
index 42d6d90..b64255d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,7 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
- "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
+ "target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
export type Setter<State> = (currentState: State) => State
export type Listener<State> = (
newState: State,
prevState: State | undefined
) => void
export default function createState<State>() {
let currentState: State
let listener: Listener<State>