牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

2016-01-01から1年間の記事一覧

Django で Rails の flash みたいなやつメモ

Rails Rails のユーザに簡易メッセージを表示するやつ。Controller で値を入れて View で表示。 ActionDispatch::Flash Django Django の場合は messages framework settings.py MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' …

Python でファイル作成する時に指定したディレクトリが無ければ作るメモ

(python2.7.11) ディレクトリが無いとこで open して write するとエラーになるので mkdir する # coding=utf-8 import os def write(filename, text): file_path = os.path.dirname(filename) if not os.path.exists(file_path): os.makedirs(file_path) wi…

Python のメソッドを文字列で呼び出すメモ

(python2.7.11) # coding=utf-8 class Hoge: @property def fuga(self): return 'fugafuga' h = Hoge() print h.fuga print getattr(h, 'fuga') # print getattr(h, 'fu') # AttributeError print getattr(h, 'fu', 'Nothing!') # -> fugafuga # -> fugafuga…

postfix のログ /var/log/mail.log を削除したらログが書き込まれなくなった場合のメモ

ubuntu 14.04 service rsyslog restart

ES6のデフォルト引数の使い方を勘違いしていたメモ

ES6 function hoge(a='hoge', b='fuga') { console.log(a + b); } hoge(); //-> hogefuga hoge('foo', 'bar'); //-> foobar hoge('foo', b='bar'); //-> SyntaxError 実行時に b= とか書くとエラーになる ちなみに Python def hoge(a='hoge', b='fuga'): pri…

Python3.5 の async を使って非同期でwebサイトにアクセスしてステータスコードを取得するメモ

(python3.5.1) Web DB Press Vol.82 の Go特集でやってたやつを python で書いてみる hoge.py import asyncio from urllib import request urls = [ 'http://example.com', 'http://example.net', 'http://example.org', ] async def display_status(url): r…

Python でとある日付から今日まで何日か取得するメモ

(python2.7.11) In [10]: import datetime In [11]: date = datetime.datetime.strptime('2016-01-01', '%Y-%m-%d') In [12]: date.today() Out[12]: datetime.datetime(2016, 3, 8, 16, 7, 57, 767309) In [13]: d = date.today() - date In [14]: d.days O…

Mac の Google chrome で 403 Forbidden nginx on developer.apple.com でアクセスできなくなる件のメモ

(MacOSX 10.10.5) 症状 developer.apple.com にアクセスすると 403 ちなみに久しくサイトにアクセスしてなかった。1年以上前かもしれない... Mac の Google Chrome でアクセスできないが、他のブラウザ(Firefox)でアクセスしたら表示でる。 アクセスできる…

Emacs の Go の環境を整えるメモ

(Emacs24.5) インストール go-mode M-x package-install go-mode gocode + go-autocomplete で補完 https://github.com/nsf/gocode $ go get -u github.com/nsf/gocode M-x package go-autocomplete godif でコードジャンプ https://github.com/buaazp/Godef…

go でツイートを search/tweets api で取ってみるメモ

(go version go1.5.1 darwin/amd64) ライブラリ anaconda A Go client library for the Twitter 1.1 API $ go get github.com/ChimeraCoder/anaconda コード package main import ( "fmt" "github.com/ChimeraCoder/anaconda" "net/url" ) const ( consumerK…

Go のスライスのメモ

package main import ( "fmt" ) func f1(slice []int) []int { slice[0] = 10 return slice } func f2(slice []int) []int { slice = append(slice, 4) slice[0] = 10 return slice } func f3(slice []int) []int { s := make([]int, len(slice)) copy(s, sl…

Python で今日から30日後の日付はいつなのか取るメモ

(python2.7) 忘れるんでメモ 標準ライブラリのみで In [16]: import datetime In [17]: today = datetime.datetime.today() In [18]: today.strftime('%Y-%m-%d') Out[18]: '2016-02-12' In [19]: d = today + datetime.timedelta(days=30) In [21]: d.strft…

Javascript で配列や連想配列を何で回すのがいいのか混乱するので for, for...in, forEach, for...of などいじってみるメモ

(node v4.2.4) その1 'use strict'; let arr = [{id: 1}, {id: 2}, {id: 3}]; for (let x in arr) { console.log(x); } console.log('----'); arr.foo = "hello"; console.log(arr); console.log('----'); for (let x in arr) { console.log(x); } console.…

Emacs で Javascript の賢い補完するメモ

(emacs24.4) 使うパッケージ M-x package-install などで下記をインストール js2-mode auto-complete tern tern-auto-complete npm 下記もインストール $ npm install -g tern 設定 tern サーバーを利用すると .term-port ファイルが作られてしまうので、作…

Javascript の連想配列で key に数値を入れると文字列になるメモ

$ node > var a = {1: 'a', 2: 'b', 3: 'c'} undefined > a { '1': 'a', '2': 'b', '3': 'c' } > Object.keys(a)[0] '1' > typeof Object.keys(a)[0] 'string' ちなみに Python だと数値のまま $ ipython In [1]: a = {1: 'a', 2: 'b', 3: 'c'} In [2]: a Ou…

Javascript で filter の書き方のメモ

ES6 'use strict'; var family = [ {'name':'Namihei', 'age': 54}, {'name':'Masuo', 'age': 28}, {'name':'Katsuo', 'age': 11}, {'name':'Tarao', 'age': 3} ]; var family1 = family.filter(function(person) { return person.age < 30; }); var family2…

Javascript で配列を逆順にするメモ

> var a = [1, 2, 3] undefined > a [1, 2, 3] > a.reverse(); [3, 2, 1] > a [3, 2, 1] > a.slice().reverse(); [1, 2, 3] > a [3, 2, 1] a.reverse() で破壊的 a.slice().reverse() で非破壊的 参考 Reverse array in Javascript without altering the ori…

pip で前のバージョンの最新をインストールしたいメモ

例えば Django の最新バージョンは 1.9.1。だけど 1.8.x 系の最新をインストールしたい場合。 $ pip install 'Django<1.9' Collecting Django<1.9 Using cached Django-1.8.8-py2.py3-none-any.whl Installing collected packages: Django 参考 pipの使い方 …

CSS の nth-child で特定の要素を指定するメモ

例:先頭から2番目以降すべての ul で、先頭から3番目までの li 要素 <html lang="ja"> <head> <meta charset="utf-8"> <title>TITLE</title> <style type="text/css"> ul:nth-child(n+2) li:nth-child(-n+3) { background: green; } </style> </head> <body> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <ul>…</ul></body></html>

関数呼び出しタイミングのメモ

いちおう想定通りの結果になるか確認してみた javascript (es2015) 'use strict'; function foo(func) { console.log('foo!'); func(); console.log('end foo!'); } foo(() => {console.log('bar!');}); //=> foo! //=> bar! //=> end foo! python 2.7.x #!/…

Emacs と ctags のタグジャンプを ES2015 syntax に対応させるメモ

設定 参考リンクから必要そうなとこを抜き出してコピペ ~/.ctags --exclude=.git --exclude=.hg --exclude=log --exclude=tmp --languages=-javascript --langdef=js --langmap=js:.js --langmap=js:+.jsx --regex-js=/[ \t.]([A-Z][A-Z0-9._$]+)[ \t]*[=:][…