Skip to content

Instantly share code, notes, and snippets.

View FaberVitale's full-sized avatar
🚀

Fabrizio Vitale FaberVitale

🚀
View GitHub Profile
;(function() {
"use strict";
const hashIteration = seq => seq.join(",");
const nextIteration = seq =>
seq.map((num, index, array) =>
Math.abs(num - array[(index + 1) % array.length])
);
function* ducciSequence(initialValue = []) {
@FaberVitale
FaberVitale / color-picker.ahk
Created April 17, 2021 16:32
Color picker - Windows | Autohotkey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Color Picker
; Usage: place mouse pointer over desired color then input "Win key + \ ",
; The picked color will be on the clipboard in rbg format
; https://www.autohotkey.com/docs/KeyList.htm
CoordMode, PixelGetColor, Screen
@FaberVitale
FaberVitale / onActionMiddleware.ts
Created June 17, 2021 14:20
A redux action listener middleware
import { Middleware } from 'redux';
import { isAnyOf, ActionMatchingAnyOf } from '@reduxjs/toolkit';
import { AppMiddlewareApi } from 'store/types';
export interface OnActionListener<T> {
(action: T, middlewareApi: AppMiddlewareApi): void;
}
export interface OnListenerError<T> {
(error: unknown, action?: T): void;
@FaberVitale
FaberVitale / gist:88bc664e3703003b6e2874182e9a1644
Created December 2, 2021 18:31
Action listener middleware take implemented using Job
diff --git a/packages/action-listener-middleware/src/index.ts b/packages/action-listener-middleware/src/index.ts
index 8850cff..5c1fe54 100644
--- a/packages/action-listener-middleware/src/index.ts
+++ b/packages/action-listener-middleware/src/index.ts
@@ -67,51 +67,47 @@ const actualMiddlewarePhases = ['beforeReducer', 'afterReducer'] as const
function createTakePattern<S>(
addListener: AddListenerOverloads<Unsubscribe, S, Dispatch<AnyAction>>,
- parentJob?: Job<any>
+ parentJob: Job<any>
@FaberVitale
FaberVitale / task.ts
Last active December 11, 2021 17:10
Task
export interface Task<T> extends Promise<T> {
/**
* The abort signal of the task
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
*/
signal: AbortSignal
/**
* Cancel a task only if it has not been settled.
* @param reason
*/
@FaberVitale
FaberVitale / counter.listener.ts
Last active March 5, 2022 12:08
Testing listeners (createListenerMiddleware - @reduxjs/toolkit)
import { counterActions } from './slice';
import { AppListenerEffectAPI } from './store';
export async function addOneToIncrementBy(
{ payload }: ReturnType<typeof counterActions.incrementByAmount>,
listenerApi: AppListenerEffectAPI
) {
listenerApi.dispatch(counterActions.increment())
}
@FaberVitale
FaberVitale / fetchBaseQueryMock.ts
Last active April 9, 2022 14:36
Simple rtk-query `fetchBaseQuery` mock using jest
import {
combineReducers,
configureStore,
EnhancedStore,
Middleware,
} from '@reduxjs/toolkit';
import type { BaseQueryFn, FetchArgs } from '@reduxjs/toolkit/query';
export type MockBaseQuery<
Result,
@FaberVitale
FaberVitale / framebuffer.rs
Created June 8, 2022 12:33
Wasm4 framebuffer logic in rust
use wasmer::Memory;
use crate::config::{self, memory::FRAMEBUFFER};
use std::{cell::Cell, cmp};
const SCREEN_WIDTH_I32: i32 = config::WIDTH as i32;
const SCREEN_HEIGHT_I32: i32 = config::HEIGHT as i32;
pub(crate) trait Extract<T> {
fn extract(&self) -> T;
@FaberVitale
FaberVitale / settings.json
Last active August 7, 2022 12:39
Minimal Vscode prettier extension integration
{
"editor.formatOnSave": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"editor.tabSize": 2,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@FaberVitale
FaberVitale / useEventListener.ts
Last active November 26, 2023 11:24
useEventListener | React
/* eslint-disable prefer-spread, consistent-return */
import { useEffect, useLayoutEffect, useRef } from 'react'
type Nullable<T> = T | null
type EventHandler<T, E> = (this: T, evt: E) => any
export type GetAddListenerOptions = {
(eventType: string): AddEventListenerOptions | boolean | undefined
}