Skip to content

Instantly share code, notes, and snippets.

@gintenlabo
gintenlabo / quote_each_args.bash
Last active December 20, 2023 10:30
与えられた各引数をエスケープした上でスペース区切りで出力する関数
#!/usr/bin/env bash
set -ueo pipefail
SEPARATOR=${SEPARATOR:- }
TRAILING_SEPARATOR=${TRAILING_SEPARATOR:-}
quote_each_args() {
for i in $(seq 1 $#); do
printf '%q' "${!i}"
if [[ $i -lt $# ]]; then
@gintenlabo
gintenlabo / install-oh-my-zsh-and-asdf-to-wsl-ubuntu-using-git.md
Last active December 14, 2023 11:11
WSL Ubuntu に Oh my zsh と asdf をインストールしつつ、 .zshrc とかを git で管理するようにする

WSL Ubuntu に Oh my zsh と asdf をインストールしつつ、 .zshrc とかを git で管理するようにする

新PC移行でWSL環境をセットアップしたので、備忘録的に書いておきます。

zsh のインストール

zsh をインストールしてない場合はまずインストールします。

# WSLを導入したての場合はまずパッケージを更新する
@gintenlabo
gintenlabo / plague.cc
Created March 25, 2015 09:07
plague inc. で どの症状から取るべきか
#include <string>
#include <unordered_set>
#include <vector>
#include <memory>
#include <limits>
struct symptom;
using symptom_t = std::shared_ptr<symptom const>;
using symptom_list = std::vector<symptom_t>;
@gintenlabo
gintenlabo / gist:f9e624ce4518887c28ca
Last active August 29, 2015 14:13
DTK環境のジェスカイ
ジェスカイ・バーン
24 lands
4 神秘の僧院
4 凱旋の神殿
3 シヴの浅瀬
3 戦場の鍛冶場
4 溢れかえる岸辺
2 島
2 山
@gintenlabo
gintenlabo / random.cc
Last active August 29, 2015 14:04
Random Number Generation for C++11, thanks to http://cpplover.blogspot.jp/2009/11/c0xrandom.html
#include <random>
#include <iterator>
template<class RandomGen>
auto make_random_values(RandomGen&& gen, std::size_t n)
-> std::vector<typename RandomGen::result_type> {
std::vector<typename RandomGen::result_type> result;
result.reserve(n);
for (std::size_t i = 0; i < n; ++i) {
result.push_back(gen());
import Data.Array (Ix, Array, elems)
import Data.Array.ST (STArray, newArray, readArray, writeArray, runSTArray)
import Control.Monad.ST (ST, runST)
import Control.Monad (forM, forM_)
-- helper function to make STArray (When I use newArray simply, GHC says it is ambiguous)
newSTArray :: Ix i => (i, i) -> e -> ST s (STArray s i e)
newSTArray = newArray
@gintenlabo
gintenlabo / increasing_arduousness
Last active August 29, 2015 14:03
ぼくのかんがえたさいきょうのM:tGカード
高まるつらみ (黒)
インスタント
クリーチャー1体を対象とする。それはターン終了時まで-1/-1の修整を受ける。高まるつらみがあなたの墓地から唱えられた場合、代わりにそのクリーチャーは-2/-2の修整を受ける。
フラッシュバック(2)(黒)(黒)(あなたはあなたの墓地にあるこのカードを、そのフラッシュバック・コストで唱えてもよい。その後それを追放する。)
@gintenlabo
gintenlabo / OK.cc
Created October 30, 2013 09:50
Boost version: 1.54.0
#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main() {
auto word = qi::raw[+qi::graph];
auto rule = qi::omit[*qi::space] >> word >> qi::omit[+qi::space];
std::string s = " hoge fuga";
@gintenlabo
gintenlabo / fix.cc
Created September 3, 2013 09:46
C++11 で不動点コンビネータ( GCC-4.8 だと std::function<int(int)> の SFINAE に引っかかって動かない)
#include <functional>
namespace etude {
template<class F>
struct fixed {
template<class F_,
class = typename std::enable_if<std::is_convertible<F_, F>{}>::type>
explicit fixed(F_ && f)
: f_(std::forward<F_>(f)) {
@gintenlabo
gintenlabo / make_overloaded.cc
Created August 28, 2013 08:06
compose overloaded function in C++11
#include <type_traits>
#include <utility>
namespace etude {
template<class... Fs>
struct overloaded_function_impl_;
template<>
struct overloaded_function_impl_<> {
template<class... Args,