Skip to content

Instantly share code, notes, and snippets.

View akinomyoga's full-sized avatar

Koichi Murase akinomyoga

View GitHub Profile
@akinomyoga
akinomyoga / README.md
Last active February 9, 2023 14:11
Efficient Conway's Game of Life in Bash

Conway's Game of Life in Bash script

I wrote a Bash script using the full capability of Bash features. I was motivated by @ytaki0801 posting a script of Conway's Game of Life in POSIX sh on Twitter. They also have implementations in other languages.

I was afraid that the resulting program would run very slowly, so I chose an implementation by the bit vector representing the states of 64 cells per integer. The Bash implementation turned out to be much faster than I expected, but it should be noted that this good performance owes to the choice of the algorithm but not to the Bash features.

@akinomyoga
akinomyoga / dll.cpp
Last active July 30, 2017 14:41
a simple example of custom allocator beyond DLL boundaries
// compile with /MTd /LD
#include <vector>
#include "my_allocator.hpp"
__declspec(dllexport) void test_in_dll(void (*proc)(std::vector<int, my_allocator<int> >&)) {
std::vector<int, my_allocator<int> > vec {1, 2, 3, 4, 5};
proc(vec);
}
@akinomyoga
akinomyoga / cygbug-duplocale.cpp
Last active March 12, 2017 00:26
Cygwin 2.7.0 std::locale/std::codecvt (cygstdc++-6.dll) の問題と duplocale (cygwin1.dll) の問題 → 解決法 https://github.com/akinomyoga/cyglocale_patcher
#include <stdlib.h>
#include <locale.h>
// Cygwin で duplocale で作ったロケールを uselocale に渡して
// MB_CUR_MAX を参照するとクラッシュする。
//
// Note: MB_CUR_MAX は __locale_mb_cur_max() に展開される。
// Note: newlocale で作成したロケールを直接使った場合は問題ない。
// Note: duplocale の代わりに newlocale(0, "C", loc) を使った場合も問題ない。
@akinomyoga
akinomyoga / msc17bug-class-definition-changes.cpp
Last active March 2, 2017 14:30
msc17 (VIsual Studio 2012 cl.exe) の信じがたいバグ: std::remove_pointer<void (*)()>::type の結果が変化する
#include <cstdio>
#include <type_traits>
struct C {
C() {}
template<typename F> explicit C(const F& f, typename std::remove_pointer<F>::type* = nullptr) {}
template<typename F> void operator=(const F&) {}
};
void f() { return 0; }
@akinomyoga
akinomyoga / sleep.sh
Last active February 20, 2022 01:41
Shell Animation using sleep
# function sleep for bash-4.0+/zsh
##
## 関数 sleep time
## スリープする。
##
## @param[in] time 待ち時間。単位は秒。小数も可能。
##
## 例: $ sleep 0.1
##