Skip to content

Instantly share code, notes, and snippets.

View kokumura's full-sized avatar

Kosuke Okumura kokumura

View GitHub Profile
@kokumura
kokumura / amazon-calc.js
Last active October 10, 2015 16:51 — forked from koyopro/amazon-calc.js
Amazonで一年間に使った金額と、注文履歴のTSVを出力するブックマークレット【2015年版】
// Amazonの注文履歴をTSV形式で出力するスクリプト
//
// 2015-01-01 時点での DOM 構造に対応, GoogleCrome, Opera でテスト済。
// formatEntry関数を書き換えれば自由な書式で出力できます。
//
// 参考:
// - Amazonの注文履歴をCSV形式にして出力するスクリプト
// https://gist.github.com/arcatdmz/8500521
// - Amazon で使った金額の合計を出す奴 (2014 年バージョン)
// https://gist.github.com/polamjag/866a8af775c44b3c1a6d
@kokumura
kokumura / jj2.py
Last active December 3, 2015 08:46
Command line Jinja2 renderer
#!/usr/bin/env python
# -*- coding:utf8 -*-
import sys, optparse
import jinja2
def main(args, params):
encoding = params.encoding
tpl = jinja2.Template(sys.stdin.read().decode(encoding))
param = dict()
ex_args = list()
@kokumura
kokumura / gist:76455b2511e18ce9237a
Created February 10, 2016 06:58
テンションが上がるワンライナー
ls | perl -pe 's/([aiueo])/\1\1\1/ig;s/$/!!!/'
# -*- coding: utf-8 -*-
import scipy.sparse as sps
import numpy as np
from StringIO import StringIO
def _np_savez(compressed=False, *args, **kwds):
sio = StringIO()
if compressed:
np.savez_compressed(sio, *args, **kwds)
else:
@kokumura
kokumura / sqlite-ex.py
Created April 22, 2016 04:22
SQLiteにPythonでUDFを追加するやつ
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sqlite3
import numpy as np
class Median:
def __init__(self):
self.values = []
def step(self, value):
self.values.append(value)
@kokumura
kokumura / tty-exec.py
Last active June 1, 2016 04:50
tty-exec.py
#!/usr/bin/env python
import subprocess, pty, os, sys
def _safe_read(m):
try:
return os.fdopen(m,"r").read()
except IOError:
return ''
sout_m, sout_s = pty.openpty()
#include <stdlib.h>
#include <unistd.h>
void main(){
while(malloc(100*1024*1024));
while(1)sleep(60);
}
@kokumura
kokumura / jupyter-headers.py
Created November 18, 2016 10:03
Jupyter notebook の最初のセルによく書くやつ
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (10, 6)
import pandas as pd
import numpy as np
import requests
import time
import json
class AzureReco:
BASE_URL = 'https://westus.api.cognitive.microsoft.com/recommendations/v4.0'
def __init__(self, subscription_key):
self._subscription_key = subscription_key
@kokumura
kokumura / .screenrc
Last active November 21, 2016 12:56
escape ^Tx
bind n eval 'next'
bind p eval 'prev'
defscrollback 10000
# enable 256 color
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# don't resize terminal width when re-attached.