Skip to content

Instantly share code, notes, and snippets.

View giwa's full-sized avatar

Ken Takagiwa giwa

  • Nombre Premier
  • Tokyo
View GitHub Profile
package main
import "fmt"
// このintSeqの関数はintSeqのbodyで定義されたanonymous functionを返します。帰ってくる関数はclosureを作るために変数iを含んでいます。
func intSeq() func() int {
i := 0
return func() int {
i += 1
return i
package main
import "fmt"
// この関数は基礎であるfact(0)にたどり着くまで自分自身を呼び続けます。
func fact(n int) int {
if n == 0 {
return 1
}
return n * fact(n-1)
@giwa
giwa / file0.txt
Last active August 29, 2015 14:15
CircleCIからPull Request にコメントする ref: http://qiita.com/giwa@github/items/a4c9395b895000407634
github = Github()
github.issue_comment('comment that you post in PR thread')
package main
import "fmt"
// zeroval, zeroptrの2つの関数を値と比較してポインタがどのように動くかを見ていきます。zerovalはintのパラメータを持っています。引数が渡される事によってパラメータに代入されます。zerovalは呼ばれた関数の中の変数とは違うivalのコピーを得ます。
func zeroval(ival int) {
ival = 0
}
// zeroptrは対照的に*intがパラメータです。これは、intのポインタをパラメータとして取ることを意味します。関数のbody中の*iptr参照先の値をメモリアドレスを参照しそのアドレスの現在の値を取得します。ポインターを参照して代入される値は参照された値を変更します。
package main
import "fmt"
import "math"
// 幾何学的な形の基本的なインターフェースです。
type geometry interface {
area() float64
perim() float64
}
@giwa
giwa / file0.txt
Last active July 25, 2018 13:36
トラフィックモニタリング with Kibana, ElasticSearch and Python ref: http://qiita.com/giwa/items/a24c722d8bc1b9a428cb
$ brew install elasticsearch
$ elasticsearch -v
Version: 1.4.4, Build: c88f77f/2015-02-19T13:05:36Z, JVM: 1.7.0_72
>>> # Let's create lists
>>> colors = "red blue green yellow".split()
>>> colors
['red', 'blue', 'green', 'yellow']
@giwa
giwa / lossy_counting.py
Created March 13, 2015 13:52
An implementation of lossy counting
"Lossy Counting"
from collections import defaultdict
class LossyCounting(object):
'Implemendation of Lossy Counting'
def __init__(self, epsilon):
self._n = 0
self._count = defaultdict(int)
@giwa
giwa / file0.txt
Last active August 29, 2015 14:17
Pythonicに sum of square を返す表現の歴史を振り返る ref: http://qiita.com/giwa/items/ed40135be78cede1af26
result = []
for i in range(n):
s = i * i
result.append(s)
print sum(result)
@giwa
giwa / file0.txt
Created March 27, 2015 18:03
すべてのscreenを消す One liner ref: http://qiita.com/giwa/items/57f4e64a0c66a65c34e4
screen -ls | grep Detached | awk '{ print $1}'| xargs -L 1 -I % screen -S % -X quit