Skip to content

Instantly share code, notes, and snippets.

@reiki4040
reiki4040 / memo_bashrc
Created April 6, 2014 10:10
.bashrc memo
# alias
alias ls='ls -G'
alias ll='ls -l'
alias la='ls -lA'
alias ..='cd ..'
alias grep='grep --color'
# git completion
if [ -f /usr/local/etc/bash_completion.d/git-prompt.sh ]; then
. /usr/local/etc/bash_completion.d/git-prompt.sh
@reiki4040
reiki4040 / variable_arguments.go
Created September 15, 2014 10:54
example variable arguments for golang
package main
import (
"fmt"
)
func PrintStrings(strings ...string) {
for _, s := range strings {
fmt.Printf("%s", s)
}
@reiki4040
reiki4040 / variable_arguments.py
Created September 15, 2014 11:15
example variable arguments for python.
import sys
def PrintStrings(*strings):
for s in strings:
sys.stdout.write(s)
print
def main():
PrintStrings("a", "b", "c")
@reiki4040
reiki4040 / validator.go
Created December 1, 2014 14:47
validation memo
package main
import (
"errors"
"fmt"
"net/url"
"reflect"
"strconv"
"strings"
)
@reiki4040
reiki4040 / rune_count_in_string_bench_test.go
Created December 17, 2014 14:53
benchmark utf8.RuneCountInString()
package benchrunecount
import (
"testing"
"unicode/utf8"
)
func BenchmarkRunCountInString16ascii(b *testing.B) {
str := "abcdefghijklmnop"
for i := 0; i < b.N; i++ {
@reiki4040
reiki4040 / kurume_temp2gf.py
Created February 4, 2013 13:26
get temperture and send growthforecast.
# -*- coding:utf-8 -*-
import json
import urllib3
def get_temperature(http):
# city=400040 Kurume city in Fukuoka.
resp = http.request('GET', 'http://weather.livedoor.com/forecast/webservice/json/v1?city=400040')
json_data = json.loads(resp.data.decode('utf-8'))
@reiki4040
reiki4040 / gist:5004644
Created February 21, 2013 13:11
fluent-plugin-parserにテスト追加中。 pattern not matchメッセージがとれない。。。標準出力、エラーではなく別の場所に出てるのかな。 pluginの中で、$log.warn で出してるところを取りたい。
def capture_stderr(&block)
original = $stderr
captured = $stderr = StringIO.new
begin
yield
ensure
$stderr = original
end
@reiki4040
reiki4040 / sqs_example.py
Created July 13, 2013 11:11
example for Amazon SQS
# -*- coding:utf-8 -*-
import time
import sys
import boto.sqs
from boto.sqs.message import Message
# tokyo region
DEFAULT_REGION = 'ap-northeast-1'
Q_NAME = 'myqueue'
@reiki4040
reiki4040 / your_logic.py
Created September 8, 2013 03:20
example for unit test.
# -*- coding:utf-8 -*-
def do_logic():
# your logic
return 'expect'
# -*- coding:utf-8 -*-
import unittest
import your_logic as logic
class LogicTest(unittest.TestCase):
def test_logic(self):
self.assertEquals('expect', logic.do_logic())
if __name__ == '__main__':