Skip to content

Instantly share code, notes, and snippets.

@yamakk
yamakk / matplotlib_jpfont_sample.py
Created September 27, 2011 23:17
matplotlibで日本語フォントを使うサンプル
#coding:utf-8
"""
matplotlibで日本語フォントを使うサンプル
"""
import matplotlib.pyplot
import matplotlib.font_manager
# for Mac
@yamakk
yamakk / nx_pylab.py.patch
Created September 28, 2011 07:40
patch for enables function draw_networkx_edge_labels to set fontproperties.
--- networkx-1.5/networkx/drawing/nx_pylab.py 2011-06-04 09:45:38.000000000 +0900
+++ nx_pylab.py 2011-10-01 01:48:06.000000000 +0900
@@ -21,7 +21,8 @@
# All rights reserved.
# BSD license.
-__all__ = ['draw',
+__all__ = ['set_fontproperties',
+ 'draw',
'draw_networkx',
@yamakk
yamakk / networkx_jp_font.py
Created September 28, 2011 08:58
networkx-1.5(patched)をつかって日本語フォントを使うサンプル
#coding:utf-8
"""
networkx-1.5にて日本語フォントを使う
patch...https://gist.github.com/1247256
$ patch -p1 < nx_pylab.py.patch
"""
import matplotlib.font_manager
import networkx
@yamakk
yamakk / google_weather_api.py
Created September 30, 2011 10:04
Google Weather APIから天候、湿度、風速、風向を取得する
#coding:utf-8
"""
unofficial Google Weather API
http://www.google.com/ig/api?weather=,,,35693692,139700260&hl=ja
レスポンスのエンコーディングは hl=jaの場合Shift-JIS hl=enの場合ASCII
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_information>
@yamakk
yamakk / rotatelog.py
Created October 4, 2011 11:05
よく使うRotateLoggerの設定とtracebackの組み合わせ
#coding:utf-8
import logging
import logging.handlers
import traceback
"""よく使うRotateLoggerの設定とtracebackの設定"""
def getRotateLogger(path, name='', level=logging.DEBUG, **kws):
maxBytes = kws.get('maxBytes', 1024*1024*50)
@yamakk
yamakk / mongodb_scala.scala
Created October 15, 2011 11:45
MongoDBにScalaで接続
import com.novus.casbah.mongodb
val con = mongodb.MongoConnection() // localhost に接続
val db = con("test")
val col = db("scala")
val item = mongodb.MongoDBObject("name"->"testtest", "age"->23)
col += item
println(col.find().toList)
@yamakk
yamakk / mymecab.py
Created October 15, 2011 11:49
mymecab.py MyMeCab().parse()
#coding:utf-8
import datetime
import time
import unicodedata
import MeCab
from HTMLParser import HTMLParser
import re
class MyMeCab(object):
'''
@yamakk
yamakk / multiprocess_mongo.py
Created December 4, 2011 12:47
multiprocessing to mongodb single processと4processの比較
#coding:utf-8
import os
import time
from multiprocessing import Process
import pymongo
def print_tweet(collection):
db = pymongo.Connection().twitter
pid = os.getpid()
@yamakk
yamakk / mecab-java-0.98.Makefile
Created December 5, 2011 13:51
mecab-java-0.98 Makefile for MacOS10.6.8
JAVA_BASE=/System/Library/Frameworks/JavaVM.framework/Versions/1.6
JAVA_HOME=$(JAVA_BASE)/Home
TARGET=MeCab
JAVAC=$(JAVA_HOME)/bin/javac -encoding utf-8
JAVA=$(JAVA_HOME)/bin/java -Dfile.encoding=utf-8
JAR=$(JAVA_HOME)/bin/jar
CXX=g++
INCLUDE=/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
PACKAGE=org/chasen/mecab
@yamakk
yamakk / ignoredecodetest.scala
Created December 6, 2011 08:49
ignoredecodetest.scala utf-8でdecodeできないファイルをscalaで扱う
import java.io.{InputStreamReader, FileInputStream, BufferedReader}
import java.nio.charset.{Charset, CharsetDecoder, CodingErrorAction}
/*
通常 Source.fromFile("sample.txt")では
java.nio.charset.MalformedInputException: Input length = 1
エラーが出る場合使う.
*/
object IgnoreDecodeTest{