Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
_cd_history_show() {
local i=0 dir list=()
for ((i=0; ; i++)); do
dir=$(dirs "$@" +$i 2>/dev/null) || break
list+=("$dir")
done
printf '%s\0' "${list[@]}"
}
#!/bin/bash
# USAGE: _alias_complete_reuse REF CMD
# use the same completion function as REF for CMD
_alias_complete_reuse() {
(($# == 2)) || return
complete -p "$1" &>/dev/null || __load_completion "$1"
$(complete -p "$1" 2>/dev/null || echo false) "$2"
}
#ifndef INCLUDE_GUARD_AB644267_F64D_4246_AF44_EA40B259E804
#define INCLUDE_GUARD_AB644267_F64D_4246_AF44_EA40B259E804
#include <functional>
#include <utility>
#include <variant>
namespace hatsusato {
namespace detail {
namespace tag {
@hatsusato
hatsusato / is_prime.cpp
Last active April 22, 2018 03:58
constexpr is_prime using Miller test
#include <cstdint>
using u64 = std::uint64_t;
// a + b
constexpr u64 mod_add(u64 a, u64 b, u64 m) {
if (~a < b) {
return (a + b) % m + ~m + 1;
} else {
return a + b;
@hatsusato
hatsusato / kmc-advent-2017.md
Last active November 25, 2023 05:46
gpg のはなし

gpg のはなし

この記事は [KMC Advent Calendar 2017][advent] の 10 日目の記事です。 昨日の記事は tron 君 ([id:tron_kmc][tron-id]) の[今年の活動を振り返る - tron-Factory 業務日誌][tron]でした。 はたち:tada:めでたい:congratulations:

はじめに

KMC 6 回生の hatsusato です。 修士 2 回生ともなると研究にかまけて KMC 活動がおろそかになっているので、この場を借りて申し訳程度に KMC 活動をしようと思います。

template <typename T>
struct Unmovable {
protected:
Unmovable() = default;
~Unmovable() = default;
Unmovable(const Unmovable&) = default;
Unmovable& operator=(const Unmovable&) = default;
Unmovable(Unmovable&&) = delete;
Unmovable& operator=(Unmovable&&) = delete;
};
template <typename T>
struct Uncopyable {
protected:
Uncopyable() = default;
~Uncopyable() = default;
Uncopyable(const Uncopyable&) = delete;
Uncopyable& operator=(const Uncopyable&) = delete;
Uncopyable(Uncopyable&&) = default;
Uncopyable& operator=(Uncopyable&&) = default;
};
@hatsusato
hatsusato / type_index.cpp
Last active November 30, 2016 12:23
Show exact type infomation.
#include <boost/type_index.hpp>
#include <iostream>
#define SHOW_TYPE(x) boost::typeindex::type_id_with_cvr<decltype(x)>().pretty_name()
int main() {
std::cout << SHOW_TYPE(main) << std::endl;
}