Skip to content

Instantly share code, notes, and snippets.

@KunihikoKido
KunihikoKido / gist:0a3df0038f7e736c1812
Last active August 29, 2015 14:04
Medium Hello Elasticsearch import data
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 '{
@KunihikoKido
KunihikoKido / japanese_template.json
Last active April 2, 2020 04:12
Elasticsearch - Dynamic Mapping for Japanese
{
"japanese_template": {
"template": "*ja",
"settings": {
"analysis": {
"filter": {
"romaji": {
"type": "kuromoji_readingform",
"use_romaji": true
}
<!-- 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>
-->
@KunihikoKido
KunihikoKido / dictsort.py
Created August 2, 2013 02:55
Python 辞書型のソート
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)
@KunihikoKido
KunihikoKido / dictsort.py
Created August 2, 2013 02:55
Python 辞書型のソート
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)
@KunihikoKido
KunihikoKido / settings.py
Created August 2, 2013 02:44
django settings.py の主な変更箇所
# -*- 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': '',
@KunihikoKido
KunihikoKido / enumerate.py
Created August 1, 2013 13:44
python for enumerate example
for i, v in enumerate(['a', 'b', 'c']):
print i, v
@KunihikoKido
KunihikoKido / objectcache.py
Created August 1, 2013 08:10
Django キャッシュサーバーへ、Python オブジェクトをキャッシュ
# -*- coding: utf-8 -*-
import hashlib
try:
import cPickle as pickle
except ImportError:
import pickle
class PythonObjectCache(object):
@classmethod
@KunihikoKido
KunihikoKido / settings.py
Last active December 20, 2015 12:09
Django キャッシュサーバーの hash化 キー 生成
# -*- coding: utf-8 -*-
import hashlib
def make_hash_key(key, key_prefix, version):
"""
cache.set('key', 'value') デフォルトの make_key では、keyの値がそのまま使用されるため、
場合によっては、オーバーフローを引き起こす。hash化して、固定長にするための関数です。
CACHES の KEY_FUNCTION にこの関数を設定して使用します。
"""
@KunihikoKido
KunihikoKido / publicip.py
Created August 1, 2013 08:03
バブリックIP取得
# -*- 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()