Skip to content

Instantly share code, notes, and snippets.

@Nnwww
Nnwww / zipper.cpp
Last active July 8, 2017 19:04
ちょっと前にpythonのzip関数を真似て作った必要最低限実装、forward_iteratorの可変個引数&非正格評価対応
#pragma once
#include <tuple>
#include <iterator>
#include "tpl_utl.hpp"
namespace m_utl
{
// support only forward_iterator
// e.g.) input {1,2,3}, {"abc","def","ghi"} -> output {{1,"abc"},{2,"def"},{3,"ghi"}}
@Nnwww
Nnwww / tpl_utl.hpp
Created September 10, 2015 10:00
zipper.cppを動かすための諸々 (いろいろなサイトを参考に真似た物も含む
#include <utility>
#include <type_traits>
namespace m_utl
{
template <typename T>
struct identity { using type = T; };
template <std::size_t N, typename T = void>
@Nnwww
Nnwww / fizzbuzz.ml
Created September 27, 2015 16:05
FizzBuzz in OCaml
open List;;
let fizzbuzz min max =
let say cur =
match (cur mod 3, cur mod 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> string_of_int cur
in
@Nnwww
Nnwww / vimperatorrc
Created October 4, 2015 11:39
大量にタブを開くためデフォルトのキーバインドをほとんど反転
"3.10.1
"set ft=vimperator:
" アドオンインストール時の待ち時間カット
set! security.dialog_enable_delay=0
" j,kによる上下スクロールの移動量を5倍に設定
noremap j 5<C-e>
noremap k 5<C-y>
@Nnwww
Nnwww / car.ml
Last active October 25, 2015 03:10
某課題のOCaml実装
open Core.Std;;
type car_query =
| And of car_query * car_query
| Or of car_query * car_query
| Term of string * string
let cons_exn arg =
let cons_term_exn item =
match String.split item '=' with
@Nnwww
Nnwww / deduce_function.hpp
Created November 6, 2015 07:48
ジェネリックラムダ「以外」の(戻り値|引数)を推論して返すメタ関数
#include <type_traits>
namespace m_utl
{
template <typename... Types>
struct type_tuple {};
// 関数の型を受け取り、戻り値を推定するメタ関数
// ジェネリックラムダ以外であればこの中の何れかにオーバーロードされる
namespace result_of_function_impl
@Nnwww
Nnwww / tries.ml
Last active November 23, 2015 21:04
Trie in OCaml (I can't come up with smart implementation)
type trie = Trie of int option * char_to_children
and char_to_children = (char * trie) list
let empty =
Trie (None, [])
let example =
Trie (None,
[('i', Trie (Some 11,
[('n', Trie (Some 5, [('n', Trie (Some 9, []))]))]));
@Nnwww
Nnwww / racer_deoplete.md
Last active February 9, 2016 08:56
messages_racer_deoplete

環境

  • Mac OS X 10.10.5

  • NVIM 0.1.1 (compiled Jan 28 2016 12:13:02)

  • MacVim-KaoriYa 20160205

  • 各種プラグイン更新済み

    • racerの再インストール
    • NeobundleUpdate
      • deoplete, neocomplete, vim-racer, rust.vim
    • Rustのsrcをgit pull
@Nnwww
Nnwww / Dining_philosophers.rs
Created February 11, 2016 15:11
フォークの奪い合いの様子を可視化
// Dining Philosophers
use std::thread;
use std::time::Duration;
use std::sync::{Arc, Mutex};
struct Table {
forks: Vec<Mutex<()>>,
}
struct Philosopher {
@Nnwww
Nnwww / Establish_server_using_Lwt.ml
Last active February 27, 2016 15:44
I picked up this snippet when netsurfing.
let () =
let sockaddr = Unix.ADDR_INET (Unix.inet_addr_of_string "0.0.0.0", 3333) in
let _server =
Lwt_io.establish_server sockaddr (fun (in_, out) ->
Lwt.catch (fun () ->
in_
|> Lwt_io.read_lines
|> Lwt_stream.iter_s (fun line -> Lwt_io.write_line out line)
) (fun _exn -> Lwt.return_unit (* callback shouldn't raise *))
|> Lwt.ignore_result