Skip to content

Instantly share code, notes, and snippets.

@yatt
yatt / graph.py
Created December 3, 2013 14:11
pydot practice; 隣接した都道府県を繋ぐ
#! /usr/bin/python2.6
# coding: utf-8
# グラフの可視化ライブラリ
import os
import pydot
# TODO: 疎行列への対応
@yatt
yatt / prime6.py
Created November 4, 2013 08:36
6桁の素数の個数
#! /usr/bin/python2.7
# coding: utf8
from math import sqrt, ceil
def sieve(upper):
n = int( ceil(sqrt(upper)) )
table = range(upper+1)
table[0] = table[1] = 0
@yatt
yatt / watchdog.py
Last active June 29, 2017 05:38
python watchdog class
#! /usr/bin/python2.7
# coding: utf-8
import threading
class WatchDog(object):
def __init__(self, interval, callback):
self.interval = interval # second
@yatt
yatt / test.py
Created September 26, 2013 02:17
test from sublime text 2 gist plugin
print 'hello sublime text gist plugin!'
@yatt
yatt / crossing.c
Last active December 22, 2015 05:19
codeIQ 432 結城浩のクロッシング問題
/*
O(n^2)のアルゴリズムです。
1~(入力される最大の数値)を100個の範囲に分けて、数値nが与えられた時に
範囲ごとに対応する操作を実行します。
 範囲1 nに対応する範囲より小さい範囲
  無視
 手順2 nに対応する範囲
#! /usr/bin/python2.7
# coding: utf-8
import mechanize
import BeautifulSoup
import datetime
def normalize_date(text):
# mm/dd -> yyyy/mm/dd
y = datetime.datetime.now().year
return '%d/%s' % (y, text[:5])
@yatt
yatt / lis.py
Last active December 17, 2015 20:58
longest increasing subsequence in python
def lis(seq, m=0, decrease=False):
# longest increasing subsequence
assert type(seq) is list
seq = [m] + seq
lng = [0] # lis length for index i
ptr = [-1] # lis previous pointer for index i
for i in xrange(1, len(seq)):
js = None
if not decrease:
js = filter(lambda j: seq[j] < seq[i], xrange(i))
@yatt
yatt / tweet.py
Last active December 17, 2015 06:58
tweet command.
#! /usr/bin/env python
# coding: utf-8
#
# simple twitter client
#
import sys
import os
import twitterlib
@yatt
yatt / block_all_imouto_bot.py
Created May 1, 2013 12:47
無慈悲な兄app
#! /usr/bin/python2.7
# coding: utf-8
#
# 毒舌な妹をブロックする
#
import sys
import os
import itertools
import twitterlib
@yatt
yatt / apiquota.py
Created April 27, 2013 09:20
appengine dashboardのquota detailsのページから、現在のquotaの消費状況を取得するPythonスクリプト
#! /usr/bin/python2.7
# coding: utf-8
# monitor appengine api status from 'Quota Details' page on your appengine dashboard.
import urllib
import mechanize
from BeautifulSoup import BeautifulSoup