Skip to content

Instantly share code, notes, and snippets.

@satomacoto
satomacoto / TeX2PDF.applescript
Created January 12, 2012 15:31
TeX2PDF for CotEditor
(*
TeX2PDF for CotEditor
編集中のTeXファイルをDrag & Drop pTeX (http://www2.kumagaku.ac.jp/teacher/herogw/)でタイプセットするスクリプト。texファイルはどこかに保存されている必要があります。デフォルトではpTeX.appは“アプリケーション”フォルダにインストールされているとします。pTeX.appのスクリプトを参考にしました。少し書き換えればportsなどでインストールしたpTeXにも対応できるかもしれません。
*)
(* written by satomacoto. 2010.1.26 *)
tell application "CotEditor"
if exists front document then
@satomacoto
satomacoto / count_defaultdict.py
Created January 13, 2012 10:52
MapReduce in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
d = defaultdict(int)
for line in sys.stdin:
title, author, moji, rubi = line[:-1].split('¥t')
@satomacoto
satomacoto / Xtexshop-l
Created January 28, 2012 08:57
/Applications/UpTeX.app/teTeX/bin/Xtexshop-l landscape
#!/bin/sh
TEX=$*
DVI=`/usr/bin/basename "$TEX" ".tex"`
THECODE=`nkf -g "$TEX"`
case $THECODE in
UTF-8) KANJI="-kanji=utf8" ;;
EUC-JP) KANJI="-kanji=euc" ;;
Shift_JIS) KANJI="-kanji=sjis" ;;
ISO-2022-JP) KANJI="-kanji=jis" ;;
esac
@satomacoto
satomacoto / parameter_estimation.py
Created February 17, 2012 09:08
Parameter Estimation for Linear Dynamical Systems
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Parameter Estimation for Linear Dynamical Systems
x[t] = A*x[t-1] + w[t]
y[t] = C*x[t] + v[t]
w[t] ~ N(0,Q)
v[t] ~ N(0,R)
'''
@satomacoto
satomacoto / scatter.py
Created March 13, 2012 04:11
matplotlib - scatter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
data = """1 0.841470984807896
0.54030230586814 0.287797828416081
-0.416146836547142 0.172313864573127
-0.989992496600445 0.830544794233449
-0.653643620863612 0.414369558091726"""
@satomacoto
satomacoto / arrow.py
Created March 13, 2012 07:07
matplotlib - arrow
import matplotlib.pyplot as plt
from matplotlib.patches import Arrow
plt.figure(1, figsize=(3,3))
ax = plt.gca()
ax.annotate("",
xy=(0.2, 0.2), xycoords='data',
xytext=(0.8, 0.8), textcoords='data',
arrowprops=dict(arrowstyle="->",
@satomacoto
satomacoto / circle.py
Created March 13, 2012 07:09
matplotlib - circle
import matplotlib.pyplot as plt
circle1=plt.Circle((0,0),.2,color='r')
circle2=plt.Circle((.5,.5),.2,color='b')
circle3=plt.Circle((1,1),.2,color='g',clip_on=False)
fig = plt.gcf()
fig.gca().add_artist(circle1)
fig.gca().add_artist(circle2)
fig.gca().add_artist(circle3)
plt.show()
@satomacoto
satomacoto / mparser.py
Created April 12, 2012 03:25
Parser with MeCab
#! /usr/bin/python
# -*- encoding: utf-8 -*-
'''
Parser with MeCab
'''
import MeCab
import glob
import re
import os
@satomacoto
satomacoto / extract_youtube_videoid.py
Last active February 23, 2019 11:45
Extract youtube video id from html
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# extract YouTube videoids from html
import re
import json
import urllib2
from BeautifulSoup import BeautifulSoup
def get_videoids(url):
@satomacoto
satomacoto / youtube.html
Created May 25, 2012 12:18
A 連続再生 sample of YouTube Player API for <iframe> Embeds
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>A sample of YouTube Player API for <iframe> Embeds</title>
</head>
<body>
<!-- <iframe>(とプレイヤ)に置き換わる<div>タグ -->
<div id="player"></div>