Skip to content

Instantly share code, notes, and snippets.

@Clarencef
Clarencef / ng-update-v6.js
Last active December 21, 2021 00:05 — forked from leo6104/ng-update-v6.js
Convert .angular-cli.json to angular.json (for Angular 6 Migration from Angular 2/4/5)
/**
* Created by leo6104 (github.com/leo6104)
* You can use this nodejs script on angular v5/v4/v2 project.
* 1. Place this gist file `ng-update-v6.js` to angular project's root path
* 2. use command `node ng-update-v6.js .angular-cli.json`
* 3. check angular.json file (created by ng-update-v6.js)
**/
const fs = require('fs');
const path = require('path');
@Clarencef
Clarencef / useStore.js
Created December 27, 2020 12:31 — forked from chengsokdara/useStore.js
React global state in 15 line of codes.
// Author: Mr. Cheng Sokdara
import React, { createContext, useContext, useReducer } from "react";
import initialState from "./initialState"; // object of initial states
import reducer from "./reducer"; // https://reactjs.org/docs/hooks-reference.html#usereducer
const Store = createContext({
dispatch: () => null,
state: initialState,
});
const StoreProvider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const EVENT = {
SET_GAME_UI_INFO: 'SET_GAME_UI_INFO',
SET_VIEWED_INTRO_VIDEO: 'SET_VIEWED_INTRO_VIDEO',
VIDEO_ENDED:'VIDEO_ENDED',
SHOW_FINISH_INTRO_PAGE: 'SHOW_FINISH_INTRO_PAGE',
FINISH_INTRO_FLOW:'FINISH_INTRO_FLOW',
SHOW_MISSION_DETAI: 'SHOW_MISSION_DETAIL',
HIDE_MISSION_DETAIL:'HIDE_MISSION_DETAIL',
NEXT_STEP:'NEXT_STEP',
COMPLETE_MISSION: 'COMPLETE_MISSION',
@Clarencef
Clarencef / machine.js
Last active April 9, 2020 06:09
Generated by XState Viz: https://xstate.js.org/viz
const EVENT = {
OBSERVE_UPDATE: 'OBSERVE_UPDATE',
TOGGLE: 'TOGGLE',
};
const settingsMachine = Machine(
{
id: 'settings',
initial: 'readyForUpdate',
context: {
@Clarencef
Clarencef / machine.js
Last active March 27, 2020 10:24
Generated by XState Viz: https://xstate.js.org/viz
const isStandaloneApp = false;
const EVENT = {
FOLDED: 'FOLDED',
ORIGIN: 'ORIGIN',
FULL_SCREEN: 'FULL_SCREEN',
EDIT: 'EDIT',
UPDATE_LIST: 'UPDATE_LIST',
APP_INITIALIZE: 'APP_INITIALIZE',
IFRAME_INITIALIZE: 'IFRAME_INITIALIZE',
SET_CLOCK_POS_INFO: 'SET_CLOCK_POS_INFO',
@Clarencef
Clarencef / babel-webpack.md
Created November 1, 2019 06:14 — forked from ncochard/babel-webpack.md
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@Clarencef
Clarencef / is-private-mode.js
Created February 11, 2019 03:49 — forked from jherax/is-private-mode.js
Detect if the browser is running in Private mode
/**
* Detect if the browser is running in Private mode
*
* @returns {Promise}
*/
function isPrivateMode() {
return new Promise((resolve) => {
const on = () => resolve(true); // is in private mode
const off = () => resolve(false); // not private mode
const testLocalStorage = () => {
@Clarencef
Clarencef / event-loop.md
Created October 24, 2018 15:35 — forked from jesstelford/event-loop.md
What is the JS Event Loop and Call Stack?

Regular Event Loop

This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)


Given the code

@Clarencef
Clarencef / dataURItoBlob.js
Created October 9, 2018 03:25 — forked from davoclavo/dataURItoBlob.js
Convert dataURI to Blob so large images do not crash the browser. Based on: http://stackoverflow.com/questions/10412299 and http://stackoverflow.com/questions/6850276
/*
The MIT License (MIT)
Copyright (c) 2016 David Gomez-Urquiza
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION