Skip to content

Instantly share code, notes, and snippets.

View yaotti's full-sized avatar

Hiroshige Umino yaotti

View GitHub Profile
#!/usr/bin/env python
# coding: utf-8
def say(word=None):
print word
if __name__ == '__main__':
say(word='hi')
say(**{'word': 'hi'})
say(**{'wo'+'rd': 'hi'})
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>CSRF test</title>
</head>
<body onload="document.getElementById('f').submit();">
<form action="/some/post/url" method="post" id="f" target="ifr">
<input type="text" name="body" value="CSRF!" />
# aliases for git
alias g="git"
alias gad="git add"
alias gb="git branch -v"
alias gba="git branch -a"
alias gbl="git blame"
alias gbr="git branch -r"
alias gc="git commit -v"
alias gca="git commit -av"
alias gco="git checkout"
type student = { name: string; id: int };;
type hoge = { name: string; age: int };;
{ name = "hi"; id = 12 };;
(*
# type student = { name: string; id: int };;
type student = { name : string; id : int; }
# type hoge = { name: string; age: int };;
type hoge = { name : string; age : int; }
# { name = "hi"; id = 12 };;
#!/usr/bin/env python
# coding: utf-8
def _upheap(heap, x):
heap += [x]
l = len(heap) - 1 # 挿入する要素のindex
while (l-1)/2 >= 0: # 親がいる場合
if heap[(l-1)/2] > heap[l]:
heap[(l-1)/2], heap[l] = heap[l], heap[(l-1)/2]
l = (l-1)/2
(* fibonacci *)
let fib(x:int) =
let rec fib_i(n, a, b) =
if n = 1 || n = 2 then a
else fib_i(n-1, a+b, a)
in fib_i(x, 1, 1);;
(* 実行:
# #trace fib;;
fib is now traced.
# fib 4;;
;; はてな記法のリスト(-)をいい感じに挿入してくれる
;; C-lを押すたびに深いリストになっていく
(defun insert-list()
(interactive)
(let* ((end-point (point))
(start-point (- end-point 2))
(str (buffer-substring start-point end-point)))
(if (string-equal "- " str)
(delete-backward-char 1))
(insert "- ")))
#!/usr/bin/env python
# coding: utf8
def comb(n, r):
"calc combination"
if n == 0 or r == 0: return 1
# return (n - r + 1) / r * comb(n, r - 1)
# 先にrで割ると,小数点を切り捨ててしまう
return comb(n, r - 1) * (n - r + 1) / r
#print comb(10, 2) # 45
#!/usr/bin/env python
# coding: utf8
def hanoi(n, from_, to, via):
"tower of hanoi"
if n == 1:
print "move %d: %s => %s" % (n, from_, to)
else:
hanoi(n-1, from_, via, to)
print "move %d: %s => %s" % (n, from_, to)
hanoi(n-1, via, to, from_)
#!/usr/bin/env python
from time import sleep
def do_heavy_process():
sleep(3)
return 10
class myclass():
def __init__(self):
self.__val = None