Skip to content

Instantly share code, notes, and snippets.

@mutsune
mutsune / RPolish.hs
Last active December 20, 2015 10:59
逆ポーランド記法を対話的に計算
module RPolish where
import Data.Char
import Data.Maybe
calc :: IO ()
calc = do
putStr "> "
line <- getLine
if not (head line == '0')
then do
@mutsune
mutsune / vnc.cmd
Last active December 21, 2015 20:39
VNC クライアントを起動させるバッチファイル for Windows
@echo off
set rsa_key="/path/to/id_rsa"
set user="your_username"
set ip="vnc_server_ip_address"
set dest="%user%@%ip%"
set run_vnc_option="-autokill"
set run_vnc="vncserver %run_vnc_option%"
@mutsune
mutsune / autossh_tunneling
Last active August 10, 2020 02:07
.ssh/config から LocalForward と DynamicForward の記述部分を読み取って、autossh でトンネルを掘ってもらうスクリプトです。
#!/bin/bash -e
SSH_CONFIG=~/.ssh/config
# ポートは適当
MONITOR_PORT=58626
_monitor_port_inc() { MONITOR_PORT="$(expr ${MONITOR_PORT} + 1)"; }
_is_local_forward() { [ $(echo "${1}" | egrep "^(\d)+:(\d|\.)+:(\d)+$") ]; }
_is_dynamic_forward() { [ $(echo "${1}" | egrep "^(\d)+$") ]; }
perl -MRegexp::Assemble::Compressed -le '$r=Regexp::Assemble::Compressed->new; $r->add( "hoge" ); $r->add( "moge" ); print $r->re'
@mutsune
mutsune / get emoji
Created April 11, 2014 10:57
まったくつまらないものを作ってしまいましたが、絵文字を表す Unicode の正規表現を出力するワンライナーです
eval $(curl -s http://www.unicode.org/Public/6.0.0/ucd/EmojiSources.txt | awk -F";" ' BEGIN { printf "perl -MRegexp::Assemble::Compressed -le \047$r=Regexp::Assemble::Compressed->new; " } { if ($1 !~ /^#/ && $1 ~ /^[0-9A-Fa-f]+$/) printf "$r->add( \"" $1 "\" ); " } END { printf "print $r->re\047\n" } ')
@mutsune
mutsune / controlFlowStatement.py
Created June 6, 2014 06:42
Python で制御構造っぽいものを定義
def repeat(n):
def _repeat(f, *args):
[ f(*args) for i in xrange(n)]
return _repeat
def _print(text):
print text
repeat(10)(_print, "hoge")
@mutsune
mutsune / csvToJson.py
Last active August 29, 2015 14:02
CSV から JSON への変換スクリプト (単純な Array か Object への変換)
#!/usr/bin/env python
# encoding: utf-8
import sys
indent = [" ", " "]
def t(n):
return "".join(indent[:n])
l = "\""
@mutsune
mutsune / viterbi.py
Last active February 21, 2016 17:15
A trial program of the viterbi algorithm with HMM for POS tagging.
import numpy as np
# data
x = ["Brown", "promises", "free"]
y = ["Noun", "Verb", "Adj"]
# suppose the probabilities
p_x_y = [[0.3, 0.2, 0.5], [0.3, 0.4, 0.1], [0.4, 0.4, 0.4]] # p(x_t, y_t)
p_y_y = [[0.4, 0.7, 0.5], [0.5, 0.1, 0.2], [0.1, 0.2, 0.3]] # p(y_t, y_t-1)
@mutsune
mutsune / custom.css
Created February 22, 2017 14:45
Fira Code with Ligature for Jupyter Notebook
@font-face {
font-family: 'Fira Code';
src: url("https://cdn.rawgit.com/dunovank/jupyter-themes/1e851888/jupyterthemes/fonts/monospace/firacode/firacode.otf") format("opentype");
}
.CodeMirror {
font-family: 'Fira Code';
font-variant-ligatures: initial;
}
#!/usr/bin/env python
import urllib.request
import os
import html
def save(path, content):
with open(path, "w") as file:
file.write(content)