Macのfinderがなんか壊れた時

rm ~/Library/Preferences/com.apple.finder.plist

して、再起動でなんか直った。保証はできかねます( ー`дー´)キリッ

なんだけど、それでもダメなことが多く、結局だめになったらkillしてます。。。

killall Finder

[改訂版]  Mac OS X ターミナルコマンド ポケットリファレンス

[改訂版] Mac OS X ターミナルコマンド ポケットリファレンス

Java8時代のenum逆引きあれこれ

前に同僚と話題になったので。最初HogeAで考えていて、同僚がHogeBがいいよといい。

実行コード

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.collect.Maps;

public class EnumSample {

    public static void main(String[] args) {

        {
            long base = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++) {
                HogeTypeA type = HogeTypeA.getEnum(1);
            }
            long diff = System.currentTimeMillis() - base;
            System.out.println("testA:" + String.valueOf(diff));
        }

        {

            long base = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++) {
                HogeTypeB type = HogeTypeB.getEnum(1);
            }
            long diff = System.currentTimeMillis() - base;
            System.out.println("testB:" + String.valueOf(diff));
        }
        {

            long base = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++) {
                HogeTypeC type = HogeTypeC.getEnum(1);
            }
            long diff = System.currentTimeMillis() - base;
            System.out.println("testC:" + String.valueOf(diff));
        }

    }

}

enum HogeTypeA {

    ON(0),
    OFF(1);

    private int code;

    private HogeTypeA(int code) {
        this.code = code;
    }

    public int code() {
        return this.code;
    }

    public static HogeTypeA getEnum(int code) {
        return toEnum.get(code);
    }

    private static Map<Integer, HogeTypeA> toEnum = new HashMap<Integer, HogeTypeA>() {
        private static final long serialVersionUID = 1L;
        {
            Stream.of(HogeTypeA.values())
                    .forEach(type -> {
                        put(type.code(), type);
                    });
            ;
        }
    };
}

enum HogeTypeB {

    ON(0),
    OFF(1);

    private int code;

    private HogeTypeB(int code) {
        this.code = code;
    }

    public int code() {
        return this.code;
    }

    public static HogeTypeB getEnum(int code) {
        return toEnum.get(code);
    }

    private static final Map<Integer, HogeTypeB> toEnum = Maps.newHashMap();
    static {
        for (HogeTypeB type : values())
            toEnum.put(type.code(), type);
    }
}

enum HogeTypeC {

    ON(0),
    OFF(1);

    private int code;

    private HogeTypeC(int code) {
        this.code = code;
    }

    public int code() {
        return this.code;
    }

    public static HogeTypeC getEnum(int code) {
        return toEnum.get(code);
    }

    private static final Map<Integer, HogeTypeC> toEnum;
    static {
        toEnum = Stream.of(HogeTypeC.values())
                .collect(Collectors.toMap(HogeTypeC::code, type -> type));
    }
}

実行結果

testA:89
testB:48
testC:53

単純な実行だとHogeBが早そう。

Cも悪くなさそうなんだけど、JVMの最適化のせいなのか、Aを抜いて、BとCだけ実行すると下記のようなスコアになるので、Streamは速度いまいちっぽいのよね。

実行結果2

testB:45
testC:118

mongodb3.2チートシート

前提

  • CentOS 6.x
  • シャーディングとくにしない、レプリカセットを組まない

install

vim /etc/yum.repos.d/mongodb-org-2.6.repo

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
sudo yum install -y mongodb-org

operation

start / stop

sudo service mongod start
 
sudo service mongos stop

structure

data structure

  • database
    • collection
      • document

query

db操作

  • db一覧
    • show dbs;
  • db切り替え
    • use [db]
  • db削除
    • db.dropDatabase();

collection操作

  • collection一覧
    • show collections;
  • collection削除
    • db.[collection].drop();

ドキュメント操作

  • document一覧
    • db.[collection].find();

sample

適当にdbつくって、適当にcollection作って、適当にデータぶちこむ

> use batchlog;
switched to db hogelog
> show dbs;
local  0.000GB
>
> db.sample.save( { key : "001", value : "hogehoge" } );
WriteResult({ "nInserted" : 1 })
> show dbs;
hogelog  0.000GB
local     0.000GB

reference

MongoDBイン・アクション

MongoDBイン・アクション

linuxコマンドチートシート

  • ディレクトリ指定して、名前で検索
    • find /xxx -name *.txt
  • 特定プロセスまとめて殺す
    • pgrep -f java |xargs kill -9

Linuxシステム[実践]入門 (Software Design plus)

Linuxシステム[実践]入門 (Software Design plus)

gitチートシート

ブランチ操作

  • ブランチ切替

  • カレントから新しいブランチの作成

    • git branch -b hoge/fugafuga
  • 作ったブランチをremote にpush

    • git push origin hoge/fugafuga
  • リモートブランチ一覧

    • git branch -r
  • リモートブランチとってくる

    • git checkout feat/hogehoge
  • リモートブランチの削除

    • git branch -r -d hoge/fugafuga
  • カレントのブランチ名の変更

    • git branch -m 変更後の名前
  • 既に削除したリモートブランチを一覧から削除

    • git fetch --prune
  • ブランチがどこから分岐してんのか見る(masterから分岐した例)

    • git show-branch --sha1-name master feat/hoge-branch | tail -1
  • 特定ブランチのclose

コミットを書き換える

リポジトリ操作

認証

TIPS

GitHub実践入門 ~Pull Requestによる開発の変革 (WEB+DB PRESS plus)

GitHub実践入門 ~Pull Requestによる開発の変革 (WEB+DB PRESS plus)

nkfのチートシート

macbrewで入れたやつ

とりあえずhelpみる

nkf --help
Usage:  nkf -[flags] [--] [in file] .. [out file for -O flag]
 j/s/e/w  Specify output encoding ISO-2022-JP, Shift_JIS, EUC-JP
          UTF options is -w[8[0],{16,32}[{B,L}[0]]]
 J/S/E/W  Specify input encoding ISO-2022-JP, Shift_JIS, EUC-JP
          UTF option is -W[8,[16,32][B,L]]
 m[BQSN0] MIME decode [B:base64,Q:quoted,S:strict,N:nonstrict,0:no decode]
 M[BQ]    MIME encode [B:base64 Q:quoted]
 f/F      Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl
 Z[0-4]   Default/0: Convert JISX0208 Alphabet to ASCII
          1: Kankaku to one space  2: to two spaces  3: HTML Entity
          4: JISX0208 Katakana to JISX0201 Katakana
 X,x      Convert Halfwidth Katakana to Fullwidth or preserve it
 O        Output to File (DEFAULT 'nkf.out')
 L[uwm]   Line mode u:LF w:CRLF m:CR (DEFAULT noconversion)
 --ic=<encoding>        Specify the input encoding
 --oc=<encoding>        Specify the output encoding
 --hiragana --katakana  Hiragana/Katakana Conversion
 --katakana-hiragana    Converts each other
 --{cap, url}-input     Convert hex after ':' or '%'
 --numchar-input        Convert Unicode Character Reference
 --fb-{skip, html, xml, perl, java, subchar}
                        Specify unassigned character's replacement
 --in-place[=SUF]       Overwrite original files
 --overwrite[=SUF]      Preserve timestamp of original files
 -g --guess             Guess the input code
 -v --version           Print the version
 --help/-V              Print this help / configuration

ポイント

  • '--overwrite'をつけると上書き、つけないと元ファイルは残る

自動判別の結果参照

nkf --guess hoge.txt
Shift_JIS (LF)

sjisで上書き

nkf -s --overwrite hoge.txt

utf-8(BOM無し)で上書き

nkf -w --overwrite hoge.txt

文字コードutf-8に、改行コードをLFに、両方変換

nkf -w -Lu --overwrite *.txt

自動判定の文字コードがおかしい時に、指定の文字コード(sjis)で読み込ませて、指定の文字コード(utf-8)で表示する

nkf -S -w hoge.txt

うぇーい

プログラマのための文字コード技術入門 (WEB+DB PRESS plus) (WEB+DB PRESS plusシリーズ)

プログラマのための文字コード技術入門 (WEB+DB PRESS plus) (WEB+DB PRESS plusシリーズ)

awkでtsvの特定列の合計値を出す

こんなtsvがあったとする

$ cat hoge.tsv
abc     100
efg     200
xyz     300

2列目が、金額だから合計値を出したいときはこんな感じ

awk -F '\t' '{whole = whole + $2} END{print whole}' hoge.tsv
600

うぇーい

AWK実践入門 (Software Design plus)

AWK実践入門 (Software Design plus)