Skip to content

Instantly share code, notes, and snippets.

View torufurukawa's full-sized avatar

Toru Furukawa torufurukawa

View GitHub Profile
@torufurukawa
torufurukawa / gist:9584318
Created March 16, 2014 14:48
libcloud で S3 へアップロード
from libcloud.storage.types import Provider
from libcloud.storage.providers import get_driver
ACCESS_KEY_ID, SECRET_ACCESS_KEY = 'chinko', 'manko'
driver_class = get_driver(Provider.S3_AP_NORTHEAST)
driver = driver_class(ACCESS_KEY_ID, SECRET_ACCESS_KEY)
container = driver.get_container(container_name='my-bucket-name')
with open('tenga.txt', 'rb') as iterator:
driver.upload_object_via_stream(iterator=iterator, container=container, object_name='tenga')
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("hello")
@torufurukawa
torufurukawa / cas_test.py
Created September 11, 2011 12:41
Google App Engin SDK memcache cas test
"""
- /init to initialize service
- /update?uid=XXX to tell service XXX is active
- /count to get how many clients are active within last TIME_LIMIT sec.
"""
KEY = 'users'
TIME_LIMIT = 10
MAX_RETRIES = 3
@torufurukawa
torufurukawa / gist:1231277
Created September 21, 2011 04:49
alias to create sandbox virtualenv
alias mksandbox='virtualenv --no-site-packages sandbox; source sandbox/bin/activate'
alias usesandbox='source sandbox/bin/activate'
@torufurukawa
torufurukawa / gist:1255594
Created October 1, 2011 04:29
App Engine's ReferenceProperty that does not raise ReferencePropertyResolveError.
from google.appengine.ext import db
class ReferenceProperty(db.ReferenceProperty):
"""A property that represents a many-to-one reference to another model.
This acts as identical to google.appengine.ext.db.ReferenceProperty,
except objects returns None when referenced entity does not exist
instead of raising ReferencePropertyResolveError.
"""
def __get__(self, *args, **kw):
@torufurukawa
torufurukawa / nonvirtualunittes.py
Created October 2, 2011 03:29
親クラスの setUp と tearDown を呼び出す TestCase クラス
import unittest
class TestCaseMeta(type):
"""Metaclass for TestCase class
This metaclass make setUp method calls all setUp methods in base classes
and then calls defined setUp method. Likewise tearDown but in opposite
order.
"""
@torufurukawa
torufurukawa / mytests.py
Created October 2, 2011 03:46
nonvirtualunittest.py を使う例
import unittest
from nonvirtualunittest import TestCase
class BaseTestCase(TestCase):
def setUp(self):
self.foo = [1]
class MyTestCase(BaseTestCase):
def setUp(self):
self.foo.append(2)
@torufurukawa
torufurukawa / cascadingunittest.py
Created October 12, 2011 22:42
setup と teardown を呼び出してくれる TestCase クラス
class CascadingTestCaseMeta(type):
"""Metaclass for TestCase class
This metaclass make setUp method calls all setUp methods in base classes
and then calls defined setUp method. Likewise tearDown but in opposite
order.
"""
def __init__(cls, name, bases, ns):
for method_name, reverse in [('setUp',False), ('tearDown', True)]:
@torufurukawa
torufurukawa / Makefile
Created October 13, 2011 01:44
Sphinx で継続ビルドする Makefile の一部
auto:
@while :; do make html_silent; sleep 1; done
html_silent: .built
@echo > /dev/null
.built: *.rst img/*
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@touch .built
@echo
@torufurukawa
torufurukawa / show-hg-message
Created October 19, 2011 10:41
Mercurial (hg) で現在のブランチにおけるログメッセージをすべて表示する
#!/bin/sh
hg log -b `hg branch` -v | awk '$1 !~ /(changeset|branch|user|date|files|description|tag):/ {print}'