Skip to content

Instantly share code, notes, and snippets.

View ever-dev's full-sized avatar
🏠
Working from home

Ever Dev ever-dev

🏠
Working from home
View GitHub Profile
@ever-dev
ever-dev / React Components with initalValue.md
Last active September 25, 2020 10:37
Regarding the components with initialValue prop

We often face (or sometimes we need to implement) initialValue which sets the value only for the first time when it's rendered. (Fortunately, I had a chance to implement initialValue not so long ago).
A good example is formik.

const [types, setTypes] = useEffect(null);
const getTypes = useCallback(async () => {
  const res = await getTypesAPI();
  setTypes(res);
}, []);
return 
@ever-dev
ever-dev / tab.tsx
Last active September 23, 2020 19:10
React Tab Component using emotion
/** @jsx jsx */
import { jsx, css } from '@emotion/core'
import { FunctionComponent, useState } from 'react'
import { Icon } from '~/components'
import PerfectScrollbar from 'react-perfect-scrollbar'
import 'react-perfect-scrollbar/dist/css/styles.css'
interface Tab {
title: string
Content: FunctionComponent<{}>
@ever-dev
ever-dev / Convert callback to promise.md
Last active September 18, 2020 08:24
The way to make a callback function to Promise.

Use of callback like functions

function someFunction1( callbackFn ) => someFunction1(() => { doSomething(); })
function promiseFunction() {
  return new Promise((resolve) => {
     someFunction1(resolve);
  });
}
@ever-dev
ever-dev / promise-in-arrays.js
Created September 18, 2020 08:20
Promise in Arrays
function promiseFunction(v) {
return new Promise((resolve) => {
setTimeout(() => resolve(v), 1000);
});
}
// f1() will print `all done` first and then print 1,2,3,4 at once after a second.
function f1() {
[1, 2, 3, 4]. forEach(async(i) => {
const v = await promiseFunction(i);
@ever-dev
ever-dev / httpClient.ts
Created August 21, 2020 15:29
Http Client to fetch urls
type THttpMethod = "GET" | "POST" | "PUT" | "DELETE";
export const httpClient = (
url: string,
method: THttpMethod = "GET",
data: any = {}
) => {
const params: { [i: string]: any } = {
method,
headers: {
@ever-dev
ever-dev / useTimer.ts
Last active August 21, 2020 15:28
useTimer Custom Hook
import { useState, useEffect } from "react";
export const useTimer = (delay: number) => {
const [clock, setClock] = useState(false);
useEffect(
() => {
// toggle clock
const handler = setInterval(() => {
setClock((v) => !v);
@ever-dev
ever-dev / useDebounce.ts
Created August 21, 2020 10:21
useDebouce Custom Hook
import { useState, useEffect } from "react";
export const useDebounce = (value: any, delay: number) => {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(
() => {
// Update debounced value after delay
const handler = setTimeout(() => {
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace Web2FA.Services
{
// This class is used by the application to send Email and SMS
// when you turn on two-factor authentication in ASP.NET Identity.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
@ever-dev
ever-dev / gist:e749e4ed746b56818e451f06cb7fffd2
Created January 27, 2020 22:49
Flatten Numerical Array & unit testing
// flatten the array of integers
const flatten = array =>
JSON.stringify(array) // JSON encode the array to make string
.match(/\d+/g) // extract numbers using regex
.map(x => parseInt(x)); // convert string to numbers
// unit testing with Mocha
var assert = require('assert');