Skip to content

Instantly share code, notes, and snippets.

Avatar
🚧
Always busy

Sasha Koss kossnocorp

🚧
Always busy
View GitHub Profile
@kossnocorp
kossnocorp / useEvent.ts
Created Mar 24, 2022
Preact event/dispatch hook
View useEvent.ts
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()
View usePromise.ts
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 Oct 19, 2021
Solve Jest/Cypress conflict when using with Testing Library by using these custom wrappers:
View cypress.ts
/**
* 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 Nov 5, 2020
Source code with an example of hoisting usage
View module.ts
import {
defaultNumberingPosition,
defaultNumberingStyle,
NumberingFormatOptions,
NumberingPosition,
NumberingStyle,
} from '#app/core/split/parse'
export function stripNumbering(
text: string,
@kossnocorp
kossnocorp / buildFunctions.ts
Created Oct 28, 2020
My Firebase Functions esbuild setup
View buildFunctions.ts
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()
View 1.js
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 Oct 13, 2019
Demo of the problem for a Stack Overflow questions
View Makefile
SHELL := /bin/bash
PATH := $(shell yarn bin):$(PATH)
test:
which ts-node
${shell yarn bin}/ts-node --version
ts-node --version
View asd.diff
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'. */
View enso.ts
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>