Skip to content

Instantly share code, notes, and snippets.

@puriketu99
puriketu99 / file0.txt
Created January 13, 2015 11:07
mysqlインストールコマンド ref: http://qiita.com/puriketu99/items/6eaf7f8d42870ecf7802
bash <(curl -Ls http://git.io/eUx7rg)
@puriketu99
puriketu99 / file0.txt
Last active August 29, 2015 14:11
sqlで度数分布表、ヒストグラムを書くイディオム ref: http://qiita.com/puriketu99/items/1b9a1537dbb2d4028bf8
select
turn_id,
sum(case when life >= 0 and life <= 5 then 1 else 0 end) as life_from0to5,
sum(case when life > 5 and life <= 10 then 1 else 0 end) as life_from5to10,
sum(case when life > 10 and life <= 15 then 1 else 0 end) as life_from10to15,
sum(case when life > 15 and life <= 20 then 1 else 0 end) as life_from15to20,
sum(case when life > 20 and life <= 25 then 1 else 0 end) as life_from20to25,
sum(case when life > 25 and life <= 30 then 1 else 0 end) as life_from25to30
from log_life
group by turn_id
@puriketu99
puriketu99 / sk_learn_sample.py
Last active August 29, 2015 14:10
機械学習クソ素人の俺がプロダクトをリリースするまでの2ヶ月で覚えたこと ref: http://qiita.com/puriketu99/items/c519a95c0b16ea63c1ac
# -*- coding: utf-8 -*-
from sklearn.svm import LinearSVC
from sklearn.ensemble import AdaBoostClassifier,ExtraTreesClassifier ,GradientBoostingClassifier, RandomForestClassifier
from sklearn.decomposition import TruncatedSVD
from sklearn import datasets
from sklearn.cross_validation import cross_val_score
# 学習データを用意する
iris = datasets.load_iris() #ライブラリ付属のサンプルデータ
@puriketu99
puriketu99 / file0.txt
Created November 18, 2014 05:05
PythonのmultiprocessingでPool.close()してもプロセスが一時停止中のまま残ってメモリがどんどん増える問題 ref: http://qiita.com/puriketu99/items/0e1c1c1b34df3fec9cbe
import multiprocessing
def score4abc(a,b):
score = a,b
return score
def wrapper_score4multi(args):
return score4abc(*args)
def main(a,foo):
@puriketu99
puriketu99 / sqlite3
Created August 29, 2014 10:50
【解決】sqlite3で"0001"をstringのカラムにinsertすると"1"として入る問題 ref: http://qiita.com/puriketu99/items/135542b08ad295fb8744
import sqlite3
DATABASE = "unko"
def sql4execute(sql,params=[]):
db = sqlite3.connect(DATABASE)
db.text_factory = str
cur = db.execute(sql,params)
db.commit()
db.close()
def levenshtein(s1, s2):
if len(s1) < len(s2):
return levenshtein(s2, s1)
# len(s1) >= len(s2)
if len(s2) == 0:
return len(s1)
previous_row = range(len(s2) + 1)
for i, c1 in enumerate(s1):
#! /usr/local/bin/python
# -*- coding:utf-8
import multiprocessing
from time import sleep
def foo():
def f(j,k):
l = j + k
print "no:%s" % i
@puriketu99
puriketu99 / zen2han.awk
Created July 17, 2014 06:20
日本語とかの全角を半角に変換するawk ref: http://qiita.com/puriketu99/items/116e7536300781ceb17a
# zen2han.awk
# 全角 英数字記号 を半角文字に変換する
# 全角カタカナ等も対象とする。
BEGIN{
split("0123456789", az, "");
split("0123456789", ah, "");
split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", bz, "");
split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", bh, "");
@puriketu99
puriketu99 / file0.txt
Created June 27, 2014 02:37
GAE/Pのbackground_thread.BackgroundThreadがFrontendsNotSupportedというエラーで動かない ref: http://qiita.com/puriketu99/items/afc7426c51273ca794f4
from threading import Thread
from django.core.mail import send_mail
subject = 'Hello!'
msg = '\n \n Hello World!'
sender = settings.DEFAULT_FROM_EMAIL
to = 'x...@xx.com
t = Thread(target=send_mail, args=[subject, msg, sender, to], kwargs={'fail_silently': False})
t.setDaemon(True)
@puriketu99
puriketu99 / file0.txt
Created June 26, 2014 16:40
GAE/Pでurlfetchのunittestを書く方法 ref: http://qiita.com/puriketu99/items/083bcc3c756019024632
import unittest
from google.appengine.ext import testbed, ndb
from mock import patch, Mock
class MyTestCase(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()