Skip to content

Instantly share code, notes, and snippets.

@whosaysni
whosaysni / blastall
Last active August 29, 2015 14:04
Mimic legacy blast's blastall to execute BLAST+ commands: Legacy blastall のふりをして BLAST+ コマンドを実行する
#!/usr/bin/env python
# coding: utf-8
"""Mimic legacy blast's blastall to execute BLAST+ commands
"""
import argparse, os, sys
def main():
sys.stderr.write('>>>>> %s\n' %(' '.join(sys.argv)))
parser = argparse.ArgumentParser()
parser.add_argument('-p', dest='program', required=True)
@whosaysni
whosaysni / gist:2e3398bef09289be438a
Created August 5, 2014 04:50
Zとgzに対応する: loading both Z/gz compressed file
# 汚くて発狂しそう
def open_zfiles(filename):
open_method = open # builtin open
if filename.endswith('gz'):
open_method = gzip.open # gzip's open
elif filename.endswith('Z'):
from subprocess import Popen, PIPE
open_method = lambda fn: Popen(['zcat', fn], stdout=PIPE).stdout
with open_method(filename, 'rb') as infile:
return infile
@whosaysni
whosaysni / leakmeCT.py
Created August 6, 2014 03:30
Leak me CREATE TABLE / SQLAlchemy で実行直前のCREATE TABLEを横取りする
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
from sqlalchemy import Integer, DateTime, String, Text
from sqlalchemy import UniqueConstraint, Sequence
from sqlalchemy import create_engine
Base = declarative_base()
class SomeTable(Base):
__tablename__ = 'some_nice_table'
@whosaysni
whosaysni / gist:0f1e34d98ff330d0db14
Last active August 29, 2015 14:05
Compare images in two directories, showing difference/ディレクトリを探索して画像を比較し、差分画像を出力する
# coding: utf-8
from __future__ import print_function
from os import walk
from os.path import join, splitext
from PIL import Image, ImageChops
def compare_images(dir1, dir2):
for dirname, subdirnames, filenames in walk(dir1):
for filename in filenames:
@whosaysni
whosaysni / forked_argparse_test
Last active August 29, 2015 14:06
Doctesting argparse with multiprocessing / multiprocessing で argparse の doctest を書く
"""
>>> from argparse import ArgumentParser
>>> from multiprocessing import Process, Queue
>>> def build_parser():
... parser = ArgumentParser()
... parser.add_argument('-e', '--engage', action='store_true')
... parser.add_argument('-b', '--beam-me-up', action='store_true')
... parser.add_argument('-d', '--good-day-to-die', action='store_true')
... # blah blah blah
... return parser
@whosaysni
whosaysni / gist:5237182
Last active December 15, 2015 09:19
argparseをちょろっと翻訳。
# coding: utf-8
from gettext import NullTranslations
import argparse, sys
argparse.str = lambda s: s.encode(sys.stdout.encoding) if isinstance(s, unicode) else s
CATALOGUE = dict([
('usage: ',
u'使い方: '),
@whosaysni
whosaysni / sample.py
Last active December 16, 2015 13:46
ハイフンで区切られた語のリストから関連のある語のセットを抽出する
coding: utf-8
def answer(relations):
"""ハイフンで区切られた語のリストから連関グラフを抽出する
"""
# 語のペアの集合を生成する
pairs = [set(r.split('-')) for r in relations]
# pairs に要素が残っている間はループ
while pairs:
# 起点となるペアを取り出す
pivot = pairs.pop()
@whosaysni
whosaysni / fetch_issues.py
Created June 7, 2013 05:32
Fetching issues feed from GoogleCode hosted project.
# coding: utf-8
import os
import sys
import urllib
import tarfile
import time
from xml.etree import ElementTree as ET
from StringIO import StringIO
@whosaysni
whosaysni / gist:5733681
Created June 8, 2013 02:22
hello and farewell pthread
/*
pthtest --- hello pthread.
gcc -pthread -o pthtest pthtest.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@whosaysni
whosaysni / gist:5733769
Created June 8, 2013 02:43
Yoshinoya Merlin/吉野家マーリン
import win32com.client, time, binascii
Agent = win32com.client.Dispatch("Agent.Control.2")
Agent.Connected = 1
Agent.Characters.Load("Merlin", "C:\WINDOWS\MSAGENT\CHARS\MERLIN.ACS")
Merlin = Agent.Characters("Merlin")
Merlin.Show()
bdat = [ \