This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT 'localhost:9200/medium/blog/1' -d '{ | |
"title": "Elasticsearch 特徴まとめ", | |
"description": "Elasticsearch Features — 主にシステムを中心とした特徴まとめ", | |
"creator": "Kunihiko Kido", | |
"link": "https://medium.com/hello-elasticsearch/elasticsearch-500996e47c70", | |
"tags": ["Elasticsearch"], | |
"pubDate": "2014-03-12T11:09" | |
}' | |
curl -XPUT 'localhost:9200/medium/blog/2' -d '{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"japanese_template": { | |
"template": "*ja", | |
"settings": { | |
"analysis": { | |
"filter": { | |
"romaji": { | |
"type": "kuromoji_readingform", | |
"use_romaji": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add the following lines to theme's html code right before </head> --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> | |
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script> | |
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script> | |
<!-- | |
Usage: just add <div class="gist">[gist URL]</div> | |
Example: <div class="gist">https://gist.github.com/1395926</div> | |
--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dictsorted(dic, valuesort=False): | |
if valuesort: | |
return [(k, v) for k, v in sorted(d.items(), key=lambda x:x[1])] | |
return [(k, v) for k, v in sorted(d.items())] | |
if __name__ == '__main__': | |
d = {'A':500, 'C':300, 'D':100, 'E':400, 'B':200} | |
print dictsorted(d, False) | |
print dictsorted(d, True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dictsorted(dic, valuesort=False): | |
if valuesort: | |
return [(k, v) for k, v in sorted(d.items(), key=lambda x:x[1])] | |
return [(k, v) for k, v in sorted(d.items())] | |
if __name__ == '__main__': | |
d = {'A':500, 'C':300, 'D':100, 'E':400, 'B':200} | |
print dictsorted(d, False) | |
print dictsorted(d, True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from os.path import abspath, dirname, join | |
PROJECT_PATH = abspath(dirname(__file__)) | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. | |
'NAME': join(PROJECT_PATH, 'django.db'), # Or path to database file if using sqlite3. | |
# The following settings are not used with sqlite3: | |
'USER': '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i, v in enumerate(['a', 'b', 'c']): | |
print i, v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import hashlib | |
try: | |
import cPickle as pickle | |
except ImportError: | |
import pickle | |
class PythonObjectCache(object): | |
@classmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import hashlib | |
def make_hash_key(key, key_prefix, version): | |
""" | |
cache.set('key', 'value') デフォルトの make_key では、keyの値がそのまま使用されるため、 | |
場合によっては、オーバーフローを引き起こす。hash化して、固定長にするための関数です。 | |
CACHES の KEY_FUNCTION にこの関数を設定して使用します。 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import urllib2 | |
def get_public_ipv4(ec2instance=False): | |
url = 'http://ip.42.pl/raw' | |
if ec2instance: | |
url = 'http://169.254.169.254/latest/meta-data/public-ipv4' | |
return '%s' % urllib2.urlopen(url).read() |