Skip to content

Instantly share code, notes, and snippets.

View dunz's full-sized avatar
🎯
Focusing

dunz dunz

🎯
Focusing
  • Woowahan Bros
  • Seoul
View GitHub Profile
@dunz
dunz / gist:afef46f8fdaf81fc64985dae22a4f9ab
Last active March 28, 2025 14:31
.zshrc μ„€μ •νŒŒμΌ ( feat. alias )
# Fig pre block. Keep at the top of this file.
[[ -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && . "$HOME/.fig/shell/zshrc.pre.zsh"
# -------------------------------------------------------------------
# PATH
# -------------------------------------------------------------------
# oh-my-zs #
export ZSH=$HOME/.oh-my-zsh
# MongoDB #
@dunz
dunz / array.js
Last active January 26, 2022 08:10
Array Utilities from 1loc.dev
// λͺ¨λ“  λ°°μ—΄ μš”μ†Œκ°€ μ£Όμ–΄μ§„ κ°’κ³Ό 같은지 확인
const isEqual = (arr, value) => arr.every(item => item === value);
// λ°°μ—΄μ˜ λͺ¨λ“  ν•­λͺ©μ΄ 같은지 확인
const areEqual = arr => arr.every(item => item === arr[0]);
const areEqual = arr => new Set(arr).size === 1;
// 배열에 일뢀 κΈ°μ€€κ³Ό μΌμΉ˜ν•˜λŠ” 값이 ν¬ν•¨λ˜μ–΄ μžˆλŠ”μ§€ 확인
const contains = (arr, predicate) => !!arr.find(predicate);
const contains = (arr, predicate) => arr.some(criteria);
@dunz
dunz / object.js
Last active June 7, 2021 12:52
Object Utilities from 1loc.dev
// 값이 일반 객체인지 확인
const isPlainObject = v => !!v && typeof v === 'object' && (v.__proto__ === null || v.__proto__ === Object.prototype);
const isPlainObject = obj => !!obj && obj.constructor === Object
// 값이 객체인지 확인
const isObject = v => !!v && typeof v === 'object';
// 객체가 λΉ„μ–΄ μžˆλŠ”μ§€ 확인
const isEmpty = obj => !!obj && obj.constructor === Object && Reflect.ownKeys(obj).length === 0;
const isEmpty = obj => JSON.stringify(obj) === '{}';
@dunz
dunz / date.js
Last active June 7, 2020 05:43
Date Utilities from 1loc.dev
// 두 λ‚ μ§œ μ‚¬μ΄μ˜ 차이 일 수 계산
const diffDays = (d1, d2) => Math.ceil(Math.abs(d1 - d2) / (60*60*24*1000));
// 두 λ‚ μ§œ 비ꡐ
const compare = (a, b) => a.getTime() > b.getTime();
// λ‚ μ§œλ₯Ό yyyy mm dd ν˜•μ‹μœΌλ‘œ λ³€ν™˜
const formatYmd = date => date.toISOString().slice(0, 10);
// 초λ₯Ό hh mm ss ν˜•μ‹μœΌλ‘œ λ³€ν™˜
@dunz
dunz / dom.js
Last active June 7, 2020 07:51
Dom Utilities from 1loc.dev
// μš”μ†Œκ°€ μžμ†μΈμ§€ 확인
const isDescendant = (child, parent) => parent.contains(child);
const div = document.createElement('div')
const h1 = document.createElement('h1')
div.append(h1)
isDescendant(h1, div)
// μš”μ†Œκ°€ ν™œμ„±ν™”λ˜μ–΄ μžˆλŠ”μ§€ 확인
const hasFocus = ele => (ele === document.activeElement);
@dunz
dunz / function.js
Last active November 23, 2024 11:01
Function Utilities from 1loc.dev
// 값이 ν•¨μˆ˜μΈμ§€ 확인
const isFunction = v => [
'[object Function]',
'[object GeneratorFunction]',
'[object AsyncFunction]',
'[object Promise]'
].includes(Object.prototype.toString.call(v));
// 값이 μ œλ„ˆλ ˆμ΄ν„° ν•¨μˆ˜μΈμ§€ 확인
const isGeneratorFunction = v => Object.prototype.toString.call(v) === '[object GeneratorFunction]';
@dunz
dunz / misc.js
Last active June 14, 2020 04:39
Misc Utilities from 1loc.dev
// μ½”λ“œκ°€ nodeν™˜κ²½μ—μ„œ 싀행쀑인지 확인
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
// λΈŒλΌμš°μ €μ—μ„œ μ½”λ“œκ°€ μ‹€ν–‰ 쀑인지 확인
const isBrowser = typeof window === 'object' && typeof document === 'object';
// 섭씨λ₯Ό ν™”μ”¨λ‘œ λ³€ν™˜
const celsiusToFahrenheit = celsius => celsius * 9/5 + 32;
// 화씨λ₯Ό μ„­μ”¨λ‘œ λ³€ν™˜
@dunz
dunz / number.js
Last active October 8, 2020 05:05
Number Utilities from 1loc.dev
// μˆ«μžμ— μ„œμˆ˜ 접미사 μΆ”κ°€
const addOrdinal = n => `${n}${['st', 'nd', 'rd'][((n + 90) % 100 - 10) % 10 - 1] || 'th'}`;
const addOrdinal = n => `${n}${[, 'st', 'nd', 'rd'][/1?.$/.exec(n)] || 'th'}`;
const addOrdinal = n => `${n}${[, 'st', 'nd', 'rd'][n % 100 >> 3^1 && n % 10] || 'th'}`;
const addOrdinal = n => `${n}${{one: 'st', two: 'nd', few: 'rd', other: 'th'}[new Intl.PluralRules('en', { type: 'ordinal' }).select(n)]}`;
// Examples
addOrdinal(1); // '1st'
addOrdinal(2); // '2nd'
addOrdinal(3); // '3rd'
@dunz
dunz / random.js
Created June 13, 2020 08:19
Random Utilities from 1loc.dev
// μž„μ˜μ˜ λΆ€μšΈ 생성
const randomBoolean = () => Math.random() >= 0.5;
// μ£Όμ–΄μ§„ λ²”μœ„μ—μ„œ μž„μ˜μ˜ 뢀동 μ†Œμˆ˜μ  수λ₯Ό 생성
const randomFloat = (min, max) => Math.random() * (max - min) + min;
// μž„μ˜μ˜ 16 μ§„μˆ˜ 색상 생성
const randomColor = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
// μ£Όμ–΄μ§„ λ²”μœ„μ—μ„œ μž„μ˜μ˜ μ •μˆ˜λ₯Ό 생성
@dunz
dunz / string.js
Last active January 26, 2022 08:08
String Utilities from 1loc.dev
// λ¬Έμžμ—΄μ„ λŒ€λ¬Έμžλ‘œ
const toUpper = string => string.toUpperCase();
// λ¬Έμžμ—΄μ˜ 첫문자λ₯Ό λŒ€λ¬Έμžλ‘œ
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
// κ²½λ‘œκ°€ μƒλŒ€μ μΈμ§€ 확인
const isRelative = path => !/^([a-z]+:)?[\\/]/i.test(path);
// Examples