Skip to content

Instantly share code, notes, and snippets.

View adhrinae's full-sized avatar
📚

Dohyung Ahn adhrinae

📚
View GitHub Profile
@adhrinae
adhrinae / finicky.js
Created November 6, 2020 10:58
Finicky setting
module.exports = {
defaultBrowser: "Safari",
options: {
hideIcon: true,
},
handlers: [
{
match: [
/protopie\.atlassian\.net/,
/notion\.so\/protopie\/.*$/,
@adhrinae
adhrinae / useLocalStorage.ts
Created August 13, 2020 03:59
useLocalStorage
import { useCallback, useMemo, useState } from 'react';
import { LOCAL_STORAGE_KEY } from '../constants';
export function useLocalStorage<T extends object>(): {
parsedData: T;
loadLocalStorageData: () => Promise<T>;
setLocalStorageData: (data: T) => void;
clear: () => void;
} {
const [localStorageRawData, setLocalStorageRawData] = useState<string>('{}');
@adhrinae
adhrinae / CONTENT.md
Last active July 6, 2019 10:48
Better error handling with async/await

async / await 과 함께하는 조금 더 깔끔한 에러 핸들링

async function loginController() {
  try {
    const a = await loginService().catch(error => {
      throw new CustomErrorHandler({ code: 101, message: 'a failed', error: error });
    });
    const b = await someUtil().catch(error => {
 throw new CustomErrorHandler({ code: 102, message: 'b failed', error: error });
@adhrinae
adhrinae / safari-css.css
Created August 30, 2018 04:08
My Safari CSS custom
/*
* 아래에 있는 한글 폰트들은 아래 링크에서 받을 수 있습니다
*
* 이롭게 바탕체
* http://font.iropke.com/batang
*
* Source Han Serif
* https://source.typekit.com/source-han-serif/
*/
@adhrinae
adhrinae / Clipboard.ts
Created June 29, 2018 14:38
Copy text to clipboard in browser
/**
* 텍스트를 클립보드로 복사하는 역할을 수행해주는 인스턴스 생성
* window 객체를 직접 주입하여 테스트 가능성 및 역할 명료화(불필요하면 나중에 삭제)
* reference: https://gist.github.com/rproenca/64781c6a1329b48a455b645d361a9aa3
*
* 사용법: new Clipboard(window, document, navigator).copy('text');
*/
export default class Clipboard {
private textArea: HTMLTextAreaElement;
private document: Document;
@adhrinae
adhrinae / getTreeHeight.js
Created June 11, 2018 15:47
Getting Depth of Binary Tree
function Node(value = null, left = null, right = null) {
return {
value,
left,
right
}
}
const isEdgeLeaf = node => !node.left && !node.right
const getHeight = (node, height = 0) => {
@adhrinae
adhrinae / mittTS_RORO.ts
Last active June 4, 2018 11:09
Typescript Friendly Version of Mitt - https://github.com/developit/mitt
// Receive an Object, Return an Object Pattern (RORO)
// Reference: https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd
type EventHandler = ({ type, event }: { type?: string, event?: any }) => void
type EventHandlerList = EventHandler[]
type EventHandlerMap = {
'*'?: EventHandlerList,
[type: string]: EventHandlerList
}
@adhrinae
adhrinae / quickSort.js
Last active May 3, 2018 01:06
Quick Sort in Javascript
function quickSort(arr) {
if (arr.length <= 1) return arr;
const result = [];
const pivot = arr[Math.floor(arr.length / 2)];
const left = arr.filter(el => el < pivot);
const right = arr.filter(el => el > pivot);
return result.concat(quickSort(left), pivot, quickSort(right));
}
@adhrinae
adhrinae / karabiner.json
Created April 1, 2018 06:41
Karabiner-Element Setting (ESC to English Input Source)
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": false,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@adhrinae
adhrinae / commander.ts
Last active March 18, 2018 13:24
Mastering Javascript Design Pattern Chapter 05
interface ICommand {
execute(): void;
}
class ConcreteCommander1 implements ICommand {
constructor(private receiver: Receiver) {}
execute(): void {
console.log("`execute` method of ConcreteCommand1 is being called!");
this.receiver.action();