Skip to content

Instantly share code, notes, and snippets.

@ukyo
ukyo / method_missing.py
Created July 15, 2011 13:21
method missing in python
class MethodMissing(object):
def __getattr__(self, name):
try:
return self.__getattribute__(name)
except AttributeError:
def method(*args, **kw):
return self.method_missing(name, *args, **kw)
return method
def method_missing(self, name, *args, **kw):
@ukyo
ukyo / mecab_wakachi_patch.py
Created July 25, 2011 13:30
python-mecab wakachi gaki patch
from MeCab import Tagger
'''
Example:
>>> import MeCab
>>> import mecab_wakachi_patch.py
>>> m = Mecab.Tagger()
>>> m.wakachi('僕と契約して魔法少女になってよ')
'''
@ukyo
ukyo / dump.py
Created August 8, 2011 12:26
dump from mongodb
#!/usr/bin/python
#coding: utf8
import re
import pymongo
import MeCab
sub_url = re.compile('(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)').sub
sub_user_hash = re.compile('(@|#)[a-zA-Z0-9_]+').sub
@ukyo
ukyo / make_training_data.py
Created August 8, 2011 12:27
make lda training data
#!/usr/bin/python
# coding: utf8
import sys
import re
sub = re.compile('\n').sub
def hoge(text):
fuga = sub('', text).split(',')
foo = {}
@ukyo
ukyo / sais.go
Created August 26, 2011 09:10
sais go
package main
import (
"fmt"
"os"
"io/ioutil"
)
func getCounts() {
@ukyo
ukyo / kay_eclipse.py
Created September 1, 2011 13:33
generate a pydev project for kay.
#!/usr/bin/python
#coding: utf8
import sys
import os
import platform
from pit import Pit
PROJECT = """\
<?xml version="1.0" encoding="UTF-8"?>
@ukyo
ukyo / autoreference_dbref_patch.py
Created September 25, 2011 05:05
pymongo AutoReference DBRef patch
#coding: utf8
"""pymongoのAutoReferenceにパッチ当てるやつ
リスト内のDBRef全部にクエリを発行せずに{$in: [1,2,...,n]}する。
Example:
>>> from pymongo.son_manipulator import AutoReference, NamespaceInjector
>>> import autoreference_dbref_patch
"""
@ukyo
ukyo / BufferedFileReader.java
Created October 2, 2011 08:21
a simple file reader
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
public class BufferedFileReader {
private static BufferedFileReader opener = new BufferedFileReader();
@ukyo
ukyo / fs.js
Created December 18, 2011 20:24
tiny requestFileSytem Wrapper
//tiny requestFileSystem Wrapper
//author @ukyo
//apache license
//refer: http://d.hatena.ne.jp/shirokurostone/20111014/1318593601
var fs = (function(window){
var fs = {},
BlobBuilder = window.WebKitBlobBuilder || window.MozBlobuilder || window.MSBlobBuilder,
requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem,
@ukyo
ukyo / file0.txt
Last active February 15, 2018 05:42
javascriptで生成したファイルをローカルに保存する ref: https://qiita.com/ukyo/items/d623209655a003b13add
function download(blob, filename) {
const objectURL = window.URL.createObjectURL(blob),
a = document.createElement('a'),
e = document.createEvent('MouseEvent');
//a要素のdownload属性にファイル名を設定
a.download = filename;
a.href = objectURL;
//clickイベントを着火