Skip to content

Instantly share code, notes, and snippets.

View theory-of-soul's full-sized avatar

Tatiana theory-of-soul

View GitHub Profile
@theory-of-soul
theory-of-soul / keysMatchingType.ts
Created December 14, 2022 08:24
KeysMatchingType
export type KeysMatchingType<T, V> = { [K in keyof T]-?: T[K] extends V ? K : never }[keyof T];
type PropsType<T> = {
prop: T
};
type memoWithGeneric = <T>(props: PropsType<T>) => JSX.Element;
const Component = <T,>(props: PropsType<T>) => { ... }
export const MyComponent = React.memo(Component) as memoWithGeneric;
@theory-of-soul
theory-of-soul / firebase-messaging-sw.js
Created December 6, 2021 01:57
manage click on web push message
if (firebase && firebase.messaging.isSupported()) {
const messaging = firebase.messaging();
/* eslint-disable */
messaging.onBackgroundMessage(function (payload) {
const clickUrl = payload.data["gcm.notification.url"];
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
@theory-of-soul
theory-of-soul / webpack.config.js
Last active June 18, 2020 03:17
Selectize.js + Angularjs settings for webpack
// install separate:
// yarn add sifter
// yarn add microplugin
// and add this in config =>
module.export = {
...
plugins: [
@theory-of-soul
theory-of-soul / react-select.jsx
Created May 18, 2020 09:45
How to keep options state after losing focus on async-select?
// For keeping optins need to use inner function handleInputChange
<AsyncSelect
ref={selectRef}
onInputChange={(value: string, {action}: InputActionMeta) => {
if (action === 'input-change') setInputValue(value);
}}
inputValue={inputValue}
onFocus={() => {
if (selectRef.current) {
@theory-of-soul
theory-of-soul / actions.ts
Created May 12, 2020 08:27
good typings for redux
import { AnyAction } from "redux";
export type Wizard = {
name: string;
parentsAlive: boolean;
spells: string[];
};
export const enum WizardActionTypes {
LearnSpell = "WIZARD/LEARN_SPELL",
KillParents = "WIZARD/KILL_PARENTS"
@theory-of-soul
theory-of-soul / fix_problem.md
Last active May 11, 2020 01:05
Error: EACCES: permission denied, mkdir '/Users/name/.npm/_npx'

npx create-react-app any-name

if the command has en error:

Error: EACCES: permission denied, mkdir '/Users/user/.npm/_npx'
TypeError: Cannot read property 'get' of undefined

Fix for it:

@theory-of-soul
theory-of-soul / country2emoji.js
Created July 4, 2019 11:55
Javascript : convert country code to emoji flag by Stan Larroque
// Assume the country_code is a ISO 3166-1 alpha-2 string (eg: "US")
function country2emoji(country_code) {
var OFFSET = 127397;
var cc = country_code.toUpperCase();
function _toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
@theory-of-soul
theory-of-soul / gist:081084067f0cc6b8ed94299a4d7be02e
Last active April 16, 2019 10:10
Typed immutable map for redux state
type StateType = {
router: RouterState;
someReducer: Immutable.Map<keyof SomeReducerType, SomeReducerType[keyof SomeReducerType]>;
}
export interface AppStateInterface extends Immutable.Map<string, any> {
toJS(): StateType;
get<K extends keyof StateType>(key: K, notSetValue?: StateType[K]): StateType[K];
set<K extends keyof StateType>(key: K, value: StateType[K]): this;
has(key: string): key is keyof StateType;