Skip to content

Instantly share code, notes, and snippets.

View akiradeveloper's full-sized avatar

Akira Hayakawa akiradeveloper

  • Yokohama
View GitHub Profile
@akiradeveloper
akiradeveloper / gist:5019620
Created February 23, 2013 12:43
現在のLCが提供するsysfsです. それっぽいでしょ.
root@Paptimus:/sys/module/dm_lc# tree caches/ devices/
caches/
└── 1
├── allow_migrate
├── commit_super_block
├── commit_super_block_interval
├── device -> ../../../../devices/virtual/block/dm-1
├── flush_current_buffer
├── force_migrate
└── update_interval
@akiradeveloper
akiradeveloper / gist:5089912
Created March 5, 2013 12:11
なぜPATHが引き継がれない?
[1] akira@Kamille> echo $PATH ~
/home/akira/.pythonbrew/bin:/home/akira/.pythonbrew/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/akira/.rbenv/shims:/home/akira/Dotfiles/bin:/home/akira/bin:/home/akira/ruby-build/bin:/home/akira/ruby-1.9.3-p362/bin:/home/akira/help/bin:/home/akira/dotfiles/bin:/home/akira/aliases/bin:/home/akira/alias/bin:/home/akira/Dotfiles/bin:/home/akira/.rbenv/bin:/usr/local/vim/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/akira/.rbenv/shims:/home/akira/Dotfiles/bin:/home/akira/bin:/home/akira/ruby-build/bin:/home/akira/ruby-1.9.3-p362/bin:/home/akira/.rbenv/bin:/home/akira/help/bin:/home/akira/Dotfiles/bin:/home/akira/dotfiles/bin:/home/akira/aliases/bin:/home/akira/alias/bin:/usr/local/vim/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
akira@Kamille> su ~
Password:
root@Kamille:/home/akira# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr
@akiradeveloper
akiradeveloper / gist:5123859
Created March 9, 2013 11:10
dm-lcの管理スクリプト一部(開発中). remove_command(L27)の出力が, %sと0の間で改行してしまっており, dmsetup messageへの入力として無効で無視されてる. なぜ改行されるかが良く分からない. dmsetup loadの方(command(L24)という変数) は改行されていない.
import sys
from argparse import ArgumentParser
import lc_admin.tools as tools
parser = ArgumentParser()
#parser.add_argument("--nobarrier", action="store_true", default=False)
parser.add_argument('device_id', type=int)
parser.add_argument('cache_id', type=int)
@akiradeveloper
akiradeveloper / gist:5123935
Created March 9, 2013 11:45
Does os.system actually wait for the completion of the script? It doesn't seem so.
```
os.system(remove_command)
os.system(command)
#time.sleep(1)
os.system("dmsetup message %s 0 add_sysfs" % (device.dm_name()))
```
```
[ 227.812590] device-mapper: lc DEBUG: lc_ctr
[ 227.812590] device-mapper: lc DEBUG: lc_ctr end
@akiradeveloper
akiradeveloper / gist:5221081
Created March 22, 2013 13:03
何が悪いのか分かる人がいたら教えてくださいという丸投げ.
-module(scorecount).
-export( [main/1] ).
%% [X, X+1, X+2, ...]
create_list(_, 0, L) ->
L;
create_list(X, N, L) ->
create_list(X+1, N-1, [X | L]).
%% [Int]
Lyle% ls
Desktop Public linux-3.0.58.tar.bz2 linux-3.7.5.tar.bz2
Documents Templates linux-3.2.36.tar.bz2 linux-3.8.5
Dotfiles Videos linux-3.4.25.tar.bz2 linux-3.8.5.tar.xz
Downloads dotfiles linux-3.5.7.tar.bz2 src
Music linux-2.6.30.1.tar.bz2 linux-3.6.9.tar.bz2
Pictures linux-2.6.32.60.tar.bz2 linux-3.7.2.tar.bz2
Vimfilerの様子.
https://plus.google.com/110495541908947151568/posts/XoyuVLYonWn
@akiradeveloper
akiradeveloper / gist:5562277
Created May 12, 2013 03:10
rtmpdump並列実行時の様子(top)
2930 akira 20 0 19072 1376 1024 S 3 0.1 0:40.29 top
2177 akira 20 0 31132 2512 1072 S 1 0.1 0:39.24 tmux
3097 akira 20 0 240m 4440 1892 S 1 0.2 0:00.24 rtmpdump
10 root 20 0 0 0 0 S 1 0.0 0:02.80 events/1
2141 akira 20 0 85184 1664 892 S 1 0.1 0:07.24 sshd
2954 akira 20 0 19072 1364 1012 S 1 0.1 0:04.05 top
3082 akira 20 0 330m 9040 1892 S 1 0.4 0:00.28 rtmpdump
3104 akira 20 0 296m 2776 1892 S 1 0.1 0:00.23 rtmpdump
3106 akira 20 0 245m 3052 1892 S 1 0.1 0:00.19 rtmpdump
@akiradeveloper
akiradeveloper / gist:5689863
Created June 1, 2013 09:52
豹本p223の問題. 解答の方針は簡単なのだが, コードが良くない. ポイントは, numRedとnumBlueのうち少ない方を基準にしてループすること(多い方を選択すると, 逆の色のボックスに収まらなくてバグる). この選択に, おれはコードの冒頭で赤青というのを抽象化してAとB, 個数はN, Mと置き換えてるけど, 模範解答は, 「まず始めに赤と青を自分のボックスに入れてしまい, そこから1つずつ交換する. 交換する数は最大で, 赤青のうち少ない方だよね」という発想にしている. あと細かいことを言えば配列を確保するのも冗長(まぁこれは別に良いでしょうけど)
#include <iostream>
using namespace std;
class ColorfulBoxesAndBalls {
public:
int getMaximum(int numRed, int numBlue, int onlyRed, int onlyBlue, int bothColors)
{
int scoreA, scoreB, N, M;
if(numRed < numBlue){
scoreA = onlyRed;
@akiradeveloper
akiradeveloper / gist:5690417
Created June 1, 2013 13:39
プログラムがうまく書けなくて苦戦した. 最後のループ部分がインデックスズレとか, ループ内の副作用の関係で死亡とかひどかった. 合計2Hくらいかかった. 模範解答は, 「いつ買うか」をbuy[]という配列で保存している. そして, あとはただループするだけ. こっちの方が良かったわ・・・. あと, inMoneyとか別の値を持たずに単純に, 儲かり率だけで計算している(1引いてる). 確かにその方がバグりにくいわ. 何を計算するのか, そのためには何をすればいいのか, どうすればまぎれないのか, 純粋な部分はどこなのか切り分けよう. Hardレベルになるとコードも若干難しくなるな・・・.
class StockHistory {
public:
int maximumEarnings(
int initialInvestment,
int monthlyContribution,
vector<string> stockPrices)
{
vector<string> s = split(stockPrices[0], " ");
P("split");
int M = s.size();
@akiradeveloper
akiradeveloper / gist:5692536
Created June 2, 2013 03:30
バッチシステム. 合計時間の短いやつから実行していけば良いというのはすぐ分かる. しかし実装が難しい. C++のリファレンスなんかいちいち覚えてられないので, 使いやすいものを作った. 模範解答はsort関数を使ってない・・?どういうことだ・・・. 解法がすぐ分かっても, PythonやHaskellなら一瞬で実装出来るなのになーってなる辛みやばいので, これからもユーティリティは作っていく. 1000行くらいあっても別に何の問題もねーわ.
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <memory>
#include <cstring>
#include <stack>