Skip to main content

Command Palette

Search for a command to run...

A quick method to verify duplicate entries using hash

Published
β€’1 min read

I kept coming back to creating methods that checked if a combination of fields is unique, and ended up creating a simple method, and wanted record it here.

This is for TypeScript. I am a newbie in coding world, so if there is a suggestion or something better, I'd love to hear!

import { createHash } from 'crypto';

function getHash(input: string[]) {
    const _now = new Date().toString();
    const _hashString = input.join(' ') + _now;
    const hash = createHash('sha256');
    hash.update(_hashString);
    return hash.digest('hex').toString();
  }

You can pass an array of strings to the method to create a unique hash.

getHash([item.serialNumber, item.deviceModel])

Just a nice code snippet.

Happy Coding!

More from this blog

πŸš€ νŠœν† λ¦¬μ–Ό: 5λΆ„ λ§Œμ— 빈 ν™”λ©΄μ—μ„œ μ•± λ°°ν¬κΉŒμ§€ (ai μ—μ΄μ „νŠΈ μŠ€νƒ)

GitHub Codespaces λ₯Ό μ‚¬μš©ν•˜λ©΄ 둜컬 λ¨Έμ‹ μ—μ„œ μ•„λ¬΄λŸ° μ„€μΉ˜λ₯Ό ν•˜μ§€ μ•Šκ³ λ„ κ°œλ°œμ„ ν•  수 μžˆλ‹€λŠ” 것을 μ΅œκ·Όμ— μ•Œκ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 또, claude code λ₯Ό μ“°λ©΄ μ½”λ”© μ—μ΄μ „νŠΈκ°€ ν”„λ‘¬ν”„νŠΈμ— λ§žμΆ”μ–΄μ„œ νŒŒμΌμ„ 직접 생성/μˆ˜μ •ν•˜κ³  코딩을 ν•΄ μ€€λ‹€λŠ” 것을 μ•Œκ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ§Œμ•½ 이 두가지λ₯Ό κ²°ν•©ν•˜λ©΄ μ–΄λ–¨κΉŒ ν•˜λŠ” 생각이 λ“€μ–΄μ„œ 이 μŠ€νƒμ΄ μž‘λ™ν• μ§€ ν…ŒμŠ€νŠΈλ₯Ό ν•΄ λ³΄μ•˜μŠ΅λ‹ˆλ‹€. 개발자 κ²½ν—˜μ΄ λ„ˆλ¬΄ ν›Œλ₯­ν•˜κΈ° λ•Œλ¬Έμ—, ν•΄λ‹Ή 과정을 μ•„λž˜μ™€ 같이 μ •λ¦¬ν–ˆμŠ΅λ‹ˆ...

Jan 8, 20262 min read

κ³ μ • IP 둜 인터넷에 μ—°κ²°λœ ν™˜κ²½μ—μ„œ VMWare - Ubuntu 20.04 μ»¨ν…Œμ΄λ„ˆλ₯Ό 인터넷에 μ—°κ²°μ‹œν‚€

μ‚¬μš© ν™˜κ²½ : VMWare Fusion 12.2.4 ν˜„μž¬ κ³ μ • IP λ₯Ό 톡해 μ™ΈλΆ€λ‘œ 인터넷을 μ ‘μ†ν•˜λŠ” λ„€νŠΈμ›Œν¬ ν™˜κ²½μž…λ‹ˆλ‹€. 이 λ•Œμ— VMWare 둜 Ubuntu 20.04 이미지λ₯Ό μ„€μΉ˜ν•˜λ‹ˆ λ°”λ‘œ 인터넷 연결이 λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. 이럴 λ•Œμ— 인터넷 연결을 ν•˜λŠ” λ°©λ²•μž…λ‹ˆλ‹€. (Credit: https://www.youtube.com/watch?v=69jZUccRbik) VM instance 의 Network Adaptor λ₯Ό NAT 둜 μ„€μ •ν•©λ‹ˆλ‹€....

Nov 4, 20222 min read

Andrew Kim's Blog

18 posts