package main import "fmt" func perm(head []int, rest []int) { if len(rest) == 0 { fmt.Println(head) } else { for i, v := range rest { restx := make([]int, len(rest)) copy(restx, rest) restx = append(restx[:i], restx[i+1:]...) headx := append(head, v) perm(headx, restx) } } } func main() { perm([]int{}, []int{1, 2, 3}) }
GO言語のCSVの読み書き
これをGO言語で作成したいけど難しい
photo_name.csvで保存
,A1,A2,A3,A4,A5 1,あいうえお,かきくけこ,なにぬねの,あいうえお,かきくけこ 2,かきくけこ,たちつてと,,さしすせそ,さしすせそ 3,さしすせそ,,,,たちつてと 4,たちつてと,,,,なにぬねの 5,なにぬねの,,,,
package main import ( "encoding/csv" "log" "os" ) func failOnError(err error) { if err != nil { log.Fatal("Error:", err) } } func main() { // 読み込み fr, err := os.Open("photo_name.csv") failOnError(err) defer fr.Close() r := csv.NewReader(fr) rows, err := r.ReadAll() failOnError(err) // 書き込み fw, err := os.Create("result.csv") failOnError(err) defer fw.Close() writer := csv.NewWriter(fw) header := rows[0][1:] for _, row := range rows[1:] { for i, item := range row[1:] { if item != "" { writer.Write([]string{item, header[i]}) // writer.Write([]string{item, strconv.Itoa(j)}) } } } writer.Flush() }
次はサブコマンドをつける予定 naruto-io.hatenablog.com jtwp470.hatenablog.jp
Ubuntu16.04にGolangをインストール
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt update && sudo apt install ubuntu-make sudo apt install git umake go go-lang # 再起動 # 環境設定確認 go env mkdir go cd go mkdir bin # GOPATH追加 gedit ~/.profile # 最終行に追加 # 1.8からGOPATH不要 # export GOPATH=$HOME/go PATH=$GOPATH/bin:$PATH source ~/.profile
{ "editor.fontFamily": "Source Han Code JP M", "editor.fontSize": 14, "editor.renderWhitespace": "all", "editor.renderIndentGuides": true, "editor.formatOnSave": true, "files.trimTrailingWhitespace": true, }
VSCodeのGOをインストールすると入れてくれる
# VSCodeのデバッグ用 go get github.com/derekparker/delve/cmd/dlv go get -u github.com/alecthomas/gometalinter gometalinter --install
package main import "fmt" func main() { fmt.Println("hello world") }
Ubuntu16.04にasciidoctorをインストール
# Rubyをインストール sudo apt-add-repository ppa:brightbox/ruby-ng sudo apt-get update && sudo apt-get install ruby2.3 ruby2.3-dev # asciidoctorをインストール sudo gem install asciidoctor # HTMLに変換 asciidoctor test.adoc # PDFに変換 sudo gem install --pre asciidoctor-pdf asciidoctor-pdf basic-example.adoc # textlint npm install textlint-plugin-asciidoc-loose # Atomのプラグインをインストール apm install language-asciidoc apm install asciidoc-preview
{ "plugins": [ "asciidoc-loose" ], "filters": {}, "rules": { "common-misspellings": true, "preset-jtf-style": true, "spellcheck-tech-word": true, "preset-ja-technical-writing": true, "joyo-kanji": true, "general-novel-style-ja": true, "date-weekday-mismatch": true, "prh": { "rulePaths" :["./prh.yml"] } } }
Ubuntu16.04にATOMをインストール
ATOMインストール
# sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make # sudo apt-get update && sudo apt-get install ubuntu-make # umake ide atom # umakeでインストールするとapmコマンドが使えないのでPPA経由でインストール sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update && sudo apt-get install atom # textlintのプラグインをインストール apm install linter-textlint apm install japanese-menu apm install file-icons apm install autocomplete-python apm install python-tools apm install atom-beautify apm install markdown-table-formatter apm install script
Dockerインストール・Splashインストール
https://docs.docker.com/engine/installation/linux/ubuntulinux/docs.docker.com
sudo apt-get update sudo apt-get install apt-transport-https ca-certificates sudo apt-key adv \ --keyserver hkp://ha.pool.sks-keyservers.net:80 \ --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual sudo apt-get update sudo apt-get install docker-engine sudo service docker start sudo docker run hello-world sudo usermod -aG docker $USER sudo systemctl enable docker # アップデート sudo apt-get update sudo apt-get upgrade docker-engine
docker pull scrapinghub/splash # IP確認 ifconfig pip install scrapy-splash docker run -p 8050:8050 scrapinghub/splash
Pycharmをインストール
インストール
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update && sudo apt-get install ubuntu-make
umake ide pycharm
アップデート
umake ide pycharm -r && umake ide pycharm
umakeはアップデートないので消してからインストール
フォント
https://github.com/adobe-fonts/source-han-code-jp
初期設定
- Editor
- General
- Appearance
- General
Show line numbers - ON
Show method separators - ON
Show whitespaces - ON
仮想化
プロジェクト作成時に歯車を押して「Create Conda ENV」を選択し、名前を「py35」で作成
source activate py35
conda install anaconda
deactivate