Skip to content

Instantly share code, notes, and snippets.

@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 / ExampleWithClass.py
Last active May 19, 2019 09:30
Example Python with statement 2013/8/24 fix LABEL comment at main(). LABEL was different to explain on blog. http://d.hatena.ne.jp/reiki4040/20130331/1364723288
class ExampleWithClass:
def __init__(self):
print('__init__')
def __del__(self):
print('__del__')
def __enter__(self):
print('__enter__')
#raise ValueError # [LABEL C]
@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__':
@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 / signal.go
Created October 2, 2014 14:38
signal handling example for golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {