べすとえふぉーと

プログラミング等のノート 

nodebrewでNode.js環境構築

curlで取得してセットアップ curl -L git.io/nodebrew | perl - setup.bash_profileに追加 export PATH=$HOME/.nodebrew/current/bin:$PATHバージョン確認 nodebrew ls-remoteバージョンを指定してインストール nodebrew install-binary v7.2.1使用するバー…

mdadmでRAID5

何はともあれmknod sudo mknod /dev/md0 b 9 0ディスクの情報を見てmdadm cat /proc/diskstats sudo mdadm -C /dev/md0 -ayes -l raid5 -n 3 /dev/sda5 /dev/sda6 /dev/sda7 cat /proc/mdstatext4でフォーマット sudo mkfs.ext4 /dev/md0マウント、chownして…

アルゴリズム構築 トップダウン方式

オライリーの[初めてのコンピュータサイエンス]より、メモとして1行に1命令を書き出す #リストLに含まれるもっとも小さな2つの値の添字をタプルで返す def find_two_smallest(L): #Lの最小値の添字を探す #リストからその要素を削除 #リストの新しい最小値の…

公開鍵認証の設定

Ubuntuサーバー側 sudo apt-get install openssh-serverローカル(Mac)で鍵を作成して転送 名称入力時にvps2を入力 ssh-keygen scp -P $PORT vps2.pub $USER@$IP:/Ubuntuサーバー側で鍵設定 chmod 700 .ssh/ cat vps2.pub >> .ssh/authorized_keys chmod 600 …

curlでDropboxにファイルをアップロード

トークンを取得した状態で実行 curl -X PUT -H "Authorization: Bearer $TOKEN" -T file.png https://content.dropboxapi.com/1/files_put/auto/file.png

Ubuntu 14.04でvnc環境構築

インストール # sudo apt-get install xorg gnome-core gnome-system-tools gnome-app-install # sudo apt-get install tightvncserverパスワードの設定 # vncpasswdxstartupの設定 vi ~/.vnc/xstartup #!/bin/sh unset DBUS_SESSION_BUS_ADDRESS export GTK…

Let's encryptをUbuntu14.04に設定

環境: Apache 2.4.7 Ubuntu 14.04 git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt ./letsencrypt-auto certonly --webroot -w /var/www/html -d $domain メールを入力する画面が表示されるので入力してからApacheに設定 ./certbot-a…

bottleのアプリをherokuで公開する

ディレクトリ作成 # mkdir bottletestapp # cd bottletestappapp.pyの中身 import os from bottle import route,run @route("/") def hello_world(): return "hello" run(host="0.0.0.0",port=int(os.environ.get("PORT",5000)))requirements.txt の中身 bot…

Go 使い方メモ ゴルーチン チャネル

go

package main import "fmt" func main() { //make channel c := make(chan int) //send function go func(send chan<- int) { for i := 0; i < 8; i++ { send <- i } close(send) }(c) //receive roop for { value,ok := <-c if !ok { break } //receive fmt…

Go 使い方メモ ゴルーチン

go

元がゴルーチンのtest()実行後3秒で終わるので、test()は2まで表示して終了する package main import( "fmt" "time" ) func main() { fmt.Println("Start") fmt.Println("normal test") test() fmt.Println("go routine test") go test() time.Sleep(3 * tim…

Go 使い方メモ スライス マップ

go

package main import ( "fmt" ) func doubl(valueary []int) { for i:=0; i< len(valueary); i++ { valueary[i] *= 2 } } func main() { strary := [5]string{"a","b","c","d","e"} var slc1 []string slc1 = strary[:] fmt.Println(slc1) slc2 := strary[1:…

チキンカレーのレシピ

材料(2人前) 玉ねぎ 1個(みじん切り) ピーマン 1個(みじん切り) にんにく 1片(みじん切り) しょうが 1片(みじん切り)カレー粉 大さじ1.5 ヨーグルト 大さじ4 鶏むね肉 200g水 400ml 野菜ジュース トマトベース カレールー 大さじ5〜7(井上スパイス工業の甘口…

Go 使い方メモ インタフェース

go

package main import "fmt" type Calc interface { Calc(x int, y int) int } type Add struct { } func (r Add) Calc(x int, y int) int{ return x + y } type Sub struct { } func (r Sub) Calc(x int, y int) int{ return x - y } func main() { var add …

Go 使い方メモ 2

go

package main import ( "fmt" ) type myType int func for_range(array []int) { for i := range array { if i % 2 == 0 && array[i] % 2 == 0 { fmt.Println(array[i]) } } } func (value myType) printmethod() { fmt.Println(value) } func (value *myTyp…

Go 使い方メモ 1

go

package main import ( "strconv" "fmt" ) type struct_test struct { X int Y int } func add(x int,y int) int { return x + y } func add_minus(x, y int)(string,string) { addval := x + y minusval := x - y return strconv.Itoa(addval),strconv.Itoa…

OpenShiftでmysqlのバックアップ・アップロード

ログインしてmysqldump実行 rhc ssh -a $APPNAME mysqldump -h $HOST -p $HOST -u $USER --password=$PASSWORD $APPNAME > /sandbox/backup.sql exit※$HOSTはphpmyadminで確認ダウンロード rhc scp $APPNAME download /$SAVE_LOCAL_PATH /sandbox/backup.sql…

Gitでbranch

Git

branch作成 git branch test 一覧 git branch ブランチを変更 git checkout test 反映 git add . git commit -m “comment" Push git push -u origin test masterに取り込む git checkout master git merge test

SQLite3 でテーブル一覧取得

SQL

.tables

Ubuntu 14にSconsをインストール

sudo apt-get install python-pip sudo pip install --egg Scons pipが入ってない場合があるのでpipのインスコから あとはSConstructがあるディレクトリに移動してビルド cd toSourceDir scons BuildTarget

Ubuntu 14 Python3.4でvenv

sudo apt-get install python3.4-venv pyvenv-3.4 targetdir cd targetdir source bin/activate sudo apt-get install python3-venvだとnot foundなので python3.4-venv

Python用vimrc

syntax enable set number set ts=4 set autoindent set expandtab set shiftwidth=4 set cursorline set showmatch let python_highlight_all = 1

PythonでJSON読み込み

import urllib2 import json req = urllib2.Request('geturl') response = urllib2.urlopen(req) r = response.read() decode_json_data = json.loads(r) getmail_list = decode_json_data['emails']

ディレクトリ下をgrep

cli

find / -type f -print | xargs grep "hogehoge"

Pythonで実行時間を測る

import time start = time.time() #Do Something elapsed_time = time.time() - start print ("Elapsed:{0}".format(elapsed_time) + "[Sec]")

Pythonでリストを一意のリストへ

TargetList = list(set(TargetList))

User-Agentを指定してURLの内容を取得

2系で確認 import urllib2 geturl = 'http://www.google.com' req = urllib2.Request(geturl, headers={'User-Agent' : "Some Browser"}) response = urllib2.urlopen(req) html = response.read()

GAEで既にデプロイ済みのアプリのソースをダウンロード(Python)

基本的な書式 # appcfg.py download_app -A <your_app_id> -V <your_app_version> <output-dir>認証に失敗する場合は--oauth2をつけて実行 appcfg.py download_app -A appname -V 1 /downloaddir --oauth2</output-dir></your_app_version></your_app_id>

GAEで "Error,failed auth error" が発生した場合のアップデート方法

oauth2 オプションを追加して実行 # appcfg.py --oauth2 update appdir

Ubuntu 32bit環境にAtomをインストール

ターミナルから # sudo add-apt-repository ppa:webupd8team/atom # sudo apt-get update # sudo apt-get install atom

MacにPostgreSQLをソースからインストール

configureでパスを指定してインストール(足りないものがあれば適宜brew) 他のUNIXならだいたい同じかと ./configure --prefix=/Users/user/Desktop/postgresinstall make make install initdbを実行してからpostgresを起動 cd /Users/user/Desktop/postgre…