Skip to content

Instantly share code, notes, and snippets.

@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
}
{
"size": 0,
"query": {
"bool": {
"filter": [{
"range": {
"created_at": {
"gte": "now-3M",
"lte": "now"
}
{
"size": 0,
"query": {
"bool": {
"filter": [{
"range": {
"created_at": {
"gte": "now-1M",
"lte": "now"
}
{"index": {"_index": "userkeyword", "_type": "logs"}}
{"keyword": "銀座", "created": "2015-12-18T12:35:00"}
{"index": {"_index": "userkeyword", "_type": "logs"}}
{"keyword": "銀座", "created": "2015-12-18T12:35:00"}
{"index": {"_index": "userkeyword", "_type": "logs"}}
{"keyword": "銀座", "created": "2015-12-18T12:35:00"}
{"index": {"_index": "userkeyword", "_type": "logs"}}
{"keyword": "銀座", "created": "2015-12-18T12:35:00"}
{"index": {"_index": "userkeyword", "_type": "logs"}}
{"keyword": "銀座三越", "created": "2015-12-18T12:35:00"}
<!-- 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