Skip to content

Instantly share code, notes, and snippets.

@satomacoto
satomacoto / gist:1521244
Created December 26, 2011 14:18
A Blogger HTML/JavaScript gadget to add line number to gists
<!-- add line number to gist -->
<script type="text/javascript">
var gists = document.getElementsByClassName('gist');
for (var i = 0; i < gists.length; i++) {
var lines = gists[i].getElementsByClassName('line');
for (var j = 0; j < lines.length; j++) {
var div = document.createElement('div');
div.innerHTML = j + 1;
div.style.cssFloat = 'left';
div.style.width = '30px';
@satomacoto
satomacoto / gist:1523083
Created December 27, 2011 08:49
LaTeX for Blogger, requires jQuery
<!--
LaTeX for Blogger, requires jQuery
1. Add a HTML/Javascript gadget in the Layout mode and write this code.
2. In the HTML edit mode, write equations as follows:
<div class="equation">
ax^2 + bx + c = 0
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
</div>
@satomacoto
satomacoto / mds.py
Created January 5, 2012 08:48
Multidimensional Scaling
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
多次元尺度構成法
Multidimensional Scaling; MDS
"""
import numpy as np
import matplotlib.pyplot as plt
@satomacoto
satomacoto / kpca.data
Created January 5, 2012 15:08
Kernel principal component analysis
6.040760282116731938e-02 2.003600989193874138e-01 0
-2.180560612167562751e-01 -8.292820699779238636e-01 0
-5.144639589460509033e-01 8.281746425448210935e-01 0
-4.740161490764375866e-03 -3.159114014274040476e-03 0
-1.417081236535422117e-01 -1.966777129492919621e-02 0
6.803427539200110341e-02 7.803962205781220240e-02 0
-1.875352326510989487e-01 2.345321639090314769e-01 0
2.805120457198624351e-01 1.557595199768933847e-01 0
-2.649491374332632043e-01 -3.705041702348287058e-02 0
-1.841101081351155799e-01 -6.072910303536597360e-02 0
@satomacoto
satomacoto / hira.py
Created January 7, 2012 16:50
Extracts rubies of Aozora Bunko
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
regex = u'^[ぁ-ゞ・ー]+$' # ひらがな+・+ーだけ
p = re.compile(regex)
for line in open('ruby.txt'):
file, kanji, yomi = line.strip().split('\t')
@satomacoto
satomacoto / plsa.py
Created January 11, 2012 13:21
PLSA
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import random
class plsa():
def __init__(self,n,nz=2):
@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 / 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"""