Skip to content

Instantly share code, notes, and snippets.

View airglow923's full-sized avatar
🪖
National Service

Hyundeok Park airglow923

🪖
National Service
  • South Korea
  • 18:12 (UTC +09:00)
View GitHub Profile
@airglow923
airglow923 / readExcelFile.js
Last active March 11, 2021 15:00
Parsing Excel file into JSON with JavaScript XLSX library
import XLSX from 'xlsx';
const readExcelFile = async (filename) => {
const workbook = XLSX.readFile(filename);
return workbook.SheetNames.reduce((acc, name) => {
acc[name] = XLSX.utils.sheet_to_json(workbook.Sheets[name]);
return acc;
}, {});
};
@airglow923
airglow923 / rename-object-key.js
Last active March 25, 2021 18:08
Rename JavaScript Object key
const renameObjectKey = (object, oldName, newName) => {
// if newName is already present in object, replace it with oldName
if (
oldName !== newName &&
Object.prototype.hasOwnProperty.call(object, oldName)
) {
object[newName] = object[oldName];
delete object[oldName];
}
@airglow923
airglow923 / make-unique-array.js
Last active March 9, 2021 07:29
Make a unique array with JavaScript
// Time complexity: n(n - 1) => n^2 - n
const toUniqueArray = async (array) =>
array.reduce((acc, cur) => {
if (!acc.find((elem) => elem === cur)) acc.push(cur);
return acc;
}, []);
const toUniqueArrayIndex = async (array) => {
const uniqueIndices = [];
const uniqueElements = [];
@airglow923
airglow923 / separate-number.js
Last active March 26, 2021 03:14
Separate number with JavaScript
/* DISCLAIMER */
// This is all useless. Use Intl.NumberFormat instead.
const insertString = (string, index, newString) => {
return string.substr(0, index) + newString + string.substr(index);
};
const separateNumber = (number, separator = " ") => {
let string = String(number);
@airglow923
airglow923 / valgrind-command
Created March 31, 2021 17:47
Valgrind detailed command
valgrind \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
--log-file=valgrind-out.txt \
./executable
@airglow923
airglow923 / run-clang-tidy.sh
Last active April 17, 2021 14:16
Run clang-tidy given directories and regex pattern.
#!/bin/bash
usage() {
# additional error messages
if [ "$#" -ne 0 ]; then
printf "$@\n" >&2;
fi
printf "Usage: $0 [ -e REGEX_PATTERN ] DIRECTORY [DIRECTORIES...]\n" >&2;
}
@airglow923
airglow923 / sources.list-focal
Last active August 14, 2024 21:08
Ubuntu Mirrors sources.list for Focal (20.04), Hirsute (21.04), Impish (21.10) and Jammy (22.04)
deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
@airglow923
airglow923 / libcxx-forward-list-node-impl.h
Last active October 29, 2021 05:12
Simplified version of LLVM libcxx allocator-aware container node implementation
// This header is redistributed under the Apache License v2.0 with LLVM Exceptions.
// The whole license can be found:
// https://releases.llvm.org/12.0.0/LICENSE.TXT
// The entire implementation of forward_list can be found:
// https://github.com/llvm-mirror/libcxx/blob/master/include/forward_list
#include <memory>
#include <type_traits>
using std::allocator_traits;
@airglow923
airglow923 / clang-tidy-readability-identifier-naming-gcc.yml
Last active November 19, 2024 05:37
clang-tidy readability-identifier-naming for GCC's naming convention
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: lower_case
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ClassMemberPrefix
value: s_
- key: readability-identifier-naming.EnumCase
value: lower_case
- key: readability-identifier-naming.EnumConstantCase
@airglow923
airglow923 / change-from-jfif-to-jpg.bat
Last active May 1, 2021 02:34
A batch script that changes the default extension for jpeg from jfif to jpg
@echo off
REG ADD "HKCR\MIME\Database\Content Type\image/jpeg" /v Extension /t REG_SZ /d .jpg /f