2016-01-01から1年間の記事一覧
Rails Rails のユーザに簡易メッセージを表示するやつ。Controller で値を入れて View で表示。 ActionDispatch::Flash Django Django の場合は messages framework settings.py MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' …
(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…
(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…
ubuntu 14.04 service rsyslog restart
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.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…
(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…
(MacOSX 10.10.5) 症状 developer.apple.com にアクセスすると 403 ちなみに久しくサイトにアクセスしてなかった。1年以上前かもしれない... Mac の Google Chrome でアクセスできないが、他のブラウザ(Firefox)でアクセスしたら表示でる。 アクセスできる…
(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 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…
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…
(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…
(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.…
(emacs24.4) 使うパッケージ M-x package-install などで下記をインストール js2-mode auto-complete tern tern-auto-complete npm 下記もインストール $ npm install -g tern 設定 tern サーバーを利用すると .term-port ファイルが作られてしまうので、作…
$ 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…
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…
> 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…
例えば 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の使い方 …
例:先頭から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 #!/…
設定 参考リンクから必要そうなとこを抜き出してコピペ ~/.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]*[=:][…