Skip to content

Instantly share code, notes, and snippets.

View airglow923's full-sized avatar
🪖
National Service

Hyundeok Park airglow923

🪖
National Service
  • South Korea
  • 07:24 (UTC +09:00)
View GitHub Profile
@airglow923
airglow923 / phd_concepts.hpp
Last active May 17, 2023 04:36
User-defined concepts for container and allocator types using C++20 concepts
#include <utility>
#include <memory>
#include <iterator>
#include <type_traits>
#include <concepts>
namespace phd {
template<typename T>
concept copy_assignable = std::is_copy_assignable_v<T>;
@airglow923
airglow923 / entropy.cpp
Last active September 4, 2020 18:11
Calculate entropy using modern C++
#include <cassert>
#include <cmath>
#include <concepts>
namespace phd {
template<typename T>
concept numeric = std::integral<T> || std::floating_point<T>;
template<numeric Arg, std::integral Base>
@airglow923
airglow923 / AnyMap.cpp
Created October 9, 2020 07:39
Map wrapper using class template argument deduction (CTAD).
#include <map>
#include <unordered_map>
template<
template<typename, typename> typename Map,
typename K,
typename V
>
class AnyMap {
public:
@airglow923
airglow923 / convert_each_line_to_hash.sh
Created October 25, 2020 08:30
Convert each line to hash
#!/bin/bash
usage() {
echo "Usage: $0 -i [INPUT] -o [OUTPUT] -a [HASH_ALGORITHM]"
1>&2;
exit 1;
}
input=""
output=""
@airglow923
airglow923 / read_random_line_from_file.py
Created October 25, 2020 08:31
Read random lines from a file
#!/usr/bin/python3
import sys
import getopt
import codecs
import secrets
import hashlib
from typing import List
def usage():
@airglow923
airglow923 / clean-up-latex.sh
Created December 3, 2020 02:22
Clean up the LaTeX related files other than .pdf and .tex.
#!/bin/bash
usage() {
echo "Usage: $0 [FILENAME]"
1>&2;
exit 1;
}
if [ "$#" -ne 1 ]; then
echo "Only a filename is needed."
@airglow923
airglow923 / clang-tidy-readability-identifier-naming-google.yml
Last active October 27, 2024 03:10
clang-tidy readability-identifier-naming for Google's naming convention
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ConstexprVariableCase
value: CamelCase
- key: readability-identifier-naming.ConstexprVariablePrefix
value: k
- key: readability-identifier-naming.EnumCase
@airglow923
airglow923 / tmux-kill-unattached.sh
Last active December 18, 2020 08:28
Shell commands to kill detached (unattached) tmux sessions
#!/bin/bash
TMUX_UNATTACHED=$(tmux ls | grep -E -v '\(attached\)$')
while read session; do
tmux kill-session -t "${line%%:*}"
done <<< $TMUX_UNATTACHED
@airglow923
airglow923 / constexpr-pow.cpp
Created December 18, 2020 15:07
Exponents at compile time
namespace {
using LL = signed long long int;
template <LL N, LL X>
struct PowerOf {
static constexpr LL value_ = N * PowerOf<N, X - 1>::value_;
};
template <LL N>
@airglow923
airglow923 / constexpr-factorial.cpp
Last active December 19, 2020 07:20
Factorial at compile time
#include <concepts>
using ULL = unsigned long long int;
template <std::integral auto I>
struct Factorial {
static constexpr ULL value = I * Factorial<I - 1>::value;
};
template <>