Skip to content

Instantly share code, notes, and snippets.

View akasrai's full-sized avatar
🍀
Hoping to do something better today.

akasky akasrai

🍀
Hoping to do something better today.
View GitHub Profile
@akasrai
akasrai / unregisterServiceWorkers.js
Created October 22, 2021 13:13 — forked from mrienstra/unregisterServiceWorkers.js
Unregister service workers, verbose
navigator.serviceWorker.getRegistrations().then(function (registrations) {
if (!registrations.length) {
console.log('No serviceWorker registrations found.')
return
}
for(let registration of registrations) {
registration.unregister().then(function (boolean) {
console.log(
(boolean ? 'Successfully unregistered' : 'Failed to unregister'), 'ServiceWorkerRegistration\n' +
(registration.installing ? ' .installing.scriptURL = ' + registration.installing.scriptURL + '\n' : '') +
@akasrai
akasrai / Every possible TypeScript type.md
Created September 25, 2021 02:56 — forked from laughinghan/Every possible TypeScript type.md
Diagram of every possible TypeScript type

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything except never is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
  • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.
@akasrai
akasrai / gist:94aeb2425d5009432ec27c6f8e2b6f3b
Created August 11, 2020 07:53 — forked from kapkaev/gist:4619127
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. Resque
$ redis-cli
> config set stop-writes-on-bgsave-error no
@akasrai
akasrai / local-storage.js
Created December 19, 2019 16:54
simple utils to use local storage in browsers
import { serialize, parse, withData, withError } from 'utils';
const hasLocalStorage = window.localStorage;
export const storage = {
/**
* Get value of provide key.
*
* @param {String} key
* @returns {String}
@akasrai
akasrai / axios-interceptors-refresh-token.js
Created December 19, 2019 16:48
Refresh new token and handle all the pending requests using axios interceptors
const axiosInstance = axios.create({
baseURL: "/baseUrl",
headers: {
'Content-Type': 'application/json'
}
});
axiosInstance.interceptors.request.use(
config => {
return config;
@akasrai
akasrai / slugify.js
Created July 14, 2019 10:04 — forked from codeguy/slugify.js
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@akasrai
akasrai / gist:cdf9bc4b11f19ce2e5222b345d2fe6dc
Created July 4, 2019 18:26 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
import PropTypes from 'prop-types';
import { compose } from 'recompose';
import { connect } from 'react-redux';
import React, { Fragment, Component } from 'react';
import sl from 'components/selector/selector';
import { withTranslation } from 'react-i18next';
import {
@akasrai
akasrai / storeObserver.js
Created June 27, 2019 09:28
Utils to observe selected state change in store and handle change accordingly as suggested by Dan (REDUX JS)
/**
* Observes change in selected key of store
* and handles onchange.
*
*/
function observeStore(store, select, onChange) {
let currentState;
/**
* Handles onchange method while states
@akasrai
akasrai / createReducer.js
Created June 17, 2019 15:15
A little Reducer Factory without ugly switch statement.
function createReducer(defaultState={}) {
const _action_handler_map = new Map();
function reducer(state=defaultState, action) {
const actionHandler = _action_handler_map.get(action.type);
if (!actionHandler) {
return state;
}
return actionHandler(state, action);