Skip to content

Instantly share code, notes, and snippets.

@sile
sile / resample.lisp
Last active August 29, 2015 14:06
Audio Resample
;; http://www.sony.jp/ic-recorder/sound-compare/pcm/
(defpackage resample
(:use :common-lisp)
(:export load-pcm
save-pcm
lpf
resample))
(in-package :resample)
(defun load-pcm (path &key (signed t) (bits-per-sample 16)
@sile
sile / bench_parallel.erl
Last active August 29, 2015 14:08
ErlangでKVS的なプロセスのRead性能をコア数に対してスケールさせる方法 ref: http://qiita.com/sile/items/f3a2d2bea0135847523d
-module(bench_parallel).
-export([bench/4]).
%% @doc ベンチマーク関数
%%
%% 一秒間に何回読み込み(検索)処理を行えるかを返す
-spec bench(module(), non_neg_integer(), non_neg_integer(), pos_integer()) -> ReadsPerSecond::non_neg_integer().
bench(Module, EntryCount, ReadCount, ClientCount) ->
%% KVSプロセスの起動
@sile
sile / oosc-ch22-1-2.md
Last active August 29, 2015 14:08
オブジェクト指向入門 第2版 方法論・実践 - 第22章

第22章 クラスの見つけ方

  • オブジェクト指向ソフトウェアでは適切なクラスを見つけるのが重要
  • 絶対確実な方法はない
    • 基本的な指針やアイディアを提供することは可能
    • ただし、創造性が要求されるので、最終的には才能と経験と運が必要
  • 方法論を説明することの第一の役割
    • 啓蒙的な先駆者に注目
  • すでに分かっている落とし穴を回避
@sile
sile / bench.erl
Last active August 29, 2015 14:10
HiPE(High Performance Erlang)について ref: http://qiita.com/sile/items/d750019fcab961bbb0a7
%% 一応、gb_trees以外にも使えるようになっている
-module(bench).
-export([do_bench/5]).
%% @doc マップ(的なデータ構造)の構築時間と検索時間を測定する
do_bench(MapInit, StoreFun, FindFun, Input, Keys) ->
erlang:garbage_collect(),
{StoreTime, Map} =
timer:tc(fun () -> store_loop(MapInit, StoreFun, Input) end),
@sile
sile / file0.erl
Last active August 29, 2015 14:11
Erlangで書かれた自作ライブラリ群の紹介 ref: http://qiita.com/sile/items/05e8e1c3bd84dfc01448
%%%
%%% 基本的な使い方
%%%
%% ハッシュリングの作成
> Nodes = lists:map(fun hash_ring_node:make/1, [a,b,c,d,e]).
[{hash_ring_node,a,a,1},
{hash_ring_node,b,b,1},
{hash_ring_node,c,c,1},
{hash_ring_node,d,d,1},
{hash_ring_node,e,e,1}]
@sile
sile / dist_bench.erl
Last active August 29, 2015 14:12
分散Erlang周りの性能測定メモ ref: http://qiita.com/sile/items/1852425f0f70e790ebea
-module(dist_bench).
%%% External API
-export([
%% utility
make_node_specs/2,
setup_nodes/1,
do_bench/3,
%% scale out benchmarks
@sile
sile / oosc-ch23-5-11.md
Last active August 29, 2015 14:12
オブジェクト指向入門 第2版 方法論・実践 - 第23章5節~第24章2節

23.5 選択的エクスポート

情報隠蔽の規則を十分に適用するためには、非公開と公開という2つのエクスポートでは不十分。 選択的エクスポートが必要。

-- 選択的エクスポートの例 (LINKABLEとLINKED_LIST)

class
%% erlang版 (動作未確認)
%%
%% 関数(節)本体を一行で書こうキャンペーン中
-module(cup2).
-export([solve/1, solve_node/1]).
-export([make_node/0, make_node/1]).
-record(node,
{
@sile
sile / oosc-ch24-10.md
Last active August 29, 2015 14:14
オブジェクト指向入門 第2版 方法論・実践 - 第24章10節~第25章

24.10 複数の基準とビュー継承

分類基準が複数存在する際の話。

24.10.1 複数の基準によって分類する

自然科学における伝統的な分類では1つのレベルについて1つの基準が使われている:

  • ex: 脊椎動物or無脊椎動物、葉が毎年新しいものと入れ替わるかどうか
  • 単一継承の階層構造
@sile
sile / bench.cc
Last active August 29, 2015 14:15
『The Art of Multiprocessor Programming』の12章に出てくるBitonic Counting Networkの実装
// g++ -O3 -pthread -std=c++11 -o bench bench.cc
//
// Usage: bench type(0..6) thread_count loop_count
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <thread>
#include <vector>
#include <functional>
#include "counter.hh"