Skip to content

Instantly share code, notes, and snippets.

@f-ricci
f-ricci / useMemorySearch.ts
Created June 11, 2020 07:46
Hook wrapper for fuse.js
import { useState, useEffect } from 'react';
import Fuse from 'fuse.js';
const DEFAULT_OPTIONS: IUseMemorySearch<any> = {
minSearchLength: 3,
transformCallback: results => results.map(({ item }) => item),
searchOptions: {
useExtendedSearch: true,
threshold: 0.3,
keys: ['title'],
$stateInitialDictionary = [
'AB' => 'Alba',
'AR' => 'Arad',
'AG' => 'Arges',
'BC' => 'Bacau',
'BH' => 'Bihor',
'BN' => 'Bistrita-Nasaud',
'BT' => 'Botosani',
'BR' => 'Braila',
'BV' => 'Brasov',
// copy from response here https://stackoverflow.com/a/55189448. ALL CREDITS TO THE ORIGINAL AUTHOR https://stackoverflow.com/users/79247/retsam
// the only reason this gist exists is to not lose the content in case of question / answer deletion from stackoverflow
const useEffectDebugger = (func, inputs, prefix = "useEffect") => {
// Using a ref to hold the inputs from the previous run (or same run for initial run
const oldInputsRef = useRef(inputs);
useEffect(() => {
// Get the old inputs
const oldInputs = oldInputsRef.current;
'use strict';
/** Base class for generic event handling.
* @example
*
* // Don’t forget to call `super()` if defining a constructor.
* class Foo extends Eventable {}
* let foo = new Foo();
*
* foo.on('bar', (data) => console.log(data));
@f-ricci
f-ricci / getWeeksInMonth.js
Created August 31, 2021 16:27 — forked from markthiessen/getWeeksInMonth.js
JavaScript - get weeks in a month as array of start and end days
//note: month is 0 based, just like Dates in js
function getWeeksInMonth(year, month) {
const weeks = [],
firstDate = new Date(year, month, 1),
lastDate = new Date(year, month + 1, 0),
numDays = lastDate.getDate();
let dayOfWeekCounter = firstDate.getDay();
for (let date = 1; date <= numDays; date++) {
@f-ricci
f-ricci / README.md
Created October 1, 2021 15:02 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store