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 / dlfcn.hpp
Last active November 10, 2022 00:23
dlopen and C++ classes
#ifndef INCLUDED_DLFCN_HPP_
#define INCLUDED_DLFCN_HPP_
#include <dlfcn.h>
#include <cassert>
#include <stdexcept>
namespace dlfcn {
struct dlfcn_error : std::runtime_error {
@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 / 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,
@gintenlabo
gintenlabo / bracket.cc
Last active December 21, 2015 10:09
bracket on C++11
#include <utility>
namespace etude {
namespace bracket_impl_ {
namespace here = bracket_impl_;
template<class T>
T& as_lvalue(T&& x) {
return x;
@gintenlabo
gintenlabo / get_two_resources.cc
Created August 15, 2013 11:45
get two resources with exceptional safety
template<class T, class D>
auto make_unique_ptr(T* p, D d) noexcept
-> std::unique_ptr<T, D> {
return std::unique_ptr<T, D>(p, std::move(d));
}
auto get_two_resources()
-> std::pair<std::shared_ptr<Res1>, std::shared_ptr<Res2>> {
Res1* res1_ = {};
Res2* res2_ = {};
@gintenlabo
gintenlabo / get_line.cc
Created August 8, 2013 10:12
get line from FILE*
#include <string>
#include <cstring>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <stdexcept>
#include <boost/optional.hpp>
boost::optional<std::string> get_line(std::FILE* fp) {
std::string s;