Skip to content

Instantly share code, notes, and snippets.

rhoboro rhoboro

Block or report user

Report or block rhoboro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rhoboro
rhoboro / Dockerfile
Last active Mar 16, 2019
リストとジェネレータのメモリ効率を比較
View Dockerfile
FROM python:3.7
WORKDIR /usr/src/app
RUN pip install psutil memory-profiler
COPY . .
RUN ./mkdummy.sh
ENTRYPOINT ["python", "-m", "memory_profiler", "copy_file.py"]
@rhoboro
rhoboro / delete_instance.py
Last active Mar 8, 2019
Stackdriverを使ってGCEインスタンスの長時間起動を抑制する
View delete_instance.py
"""
Cloud Function: DeleteInstance
google-api-python-client==1.7.8
Environment Variable
AUTO_TOKEN: a value which is set in Stackdriver Notification WebHook
"""
import json
import os
@rhoboro
rhoboro / janken.py
Created Feb 2, 2019
Pythonのジェネレータでじゃんけんプログラム
View janken.py
from random import randint
from enum import Enum
class Card(Enum):
Rock = 0
Paper = 1
Scissors = 2
@rhoboro
rhoboro / async_sample.py
Last active May 14, 2019
asyncio, aiohttpを利用した並列処理のサンプルコード
View async_sample.py
import asyncio
import aiohttp
import async_timeout
from aiohttp import ClientError
async def _fetch(session, url, coro):
"""HTTPリソースからデータを取得しコルーチンを呼び出す
@rhoboro
rhoboro / Dockerfile
Last active Dec 29, 2017
サービスアカウントgsutilを使う
View Dockerfile
# put service-account-key to ./credentials.json
# docker build -t image/gsutil:0.1 .
# docker run --rm -it image/gsutil:0.1 ls gs://your_backet
FROM alpine:3.7
RUN apk update && apk add python \
&& wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-180.0.0-linux-x86_64.tar.gz \
&& tar zxvf google-cloud-sdk-180.0.0-linux-x86_64.tar.gz \
&& ./google-cloud-sdk/install.sh \
&& google-cloud-sdk/bin/gcloud config set component_manager/disable_update_check true
COPY credentials.json ./credentials.json
@rhoboro
rhoboro / gae_fetchurl_test.py
Created Nov 22, 2017
GAE/SE/pyでfetchurlを使うメソッドのテスト
View gae_fetchurl_test.py
import unittest
import json
from mock import Mock, patch
from google.appengine.ext import testbed
class FetchTestCase(unittest.TestCase):
def setUp(self):
@rhoboro
rhoboro / get_from_nested.py
Created Nov 22, 2017
dict.get()の多次元版
View get_from_nested.py
from collections import abc
def get_from_nested(dic, keys=None, default=None):
"""
>>> get_from_nested({'hoge': {'fuga': 1}}, keys=['hoge'], default=[])
{'fuga': 1}
>>> get_from_nested({'hoge': {'fuga': 1}}, keys=['hoge', 'fuga'], default=[])
1
>>> get_from_nested({'hoge': {'fuga': 1}}, keys=['hoge', 'fuga', 'yeah'], default=[])
View test.ini
[SECTION1]
name=value
@rhoboro
rhoboro / ansible_gce_site.yml
Last active Jul 30, 2017
GCEインスタンスを作成=>ping=>削除するAnsibleのPlaybook
View ansible_gce_site.yml
# [http://docs.ansible.com/ansible/latest/guide_gce.html](http://docs.ansible.com/ansible/latest/guide_gce.html)
# [gce - create or terminate GCE instances](http://docs.ansible.com/ansible/latest/gce_module.html)
# [AnsibleでGCEサーバーをセットアップする](https://blog.1q77.com/2014/07/ansible-gce/)
---
- name: Create instance
hosts: localhost
connection: local
gather_facts: no
vars:
# GCE管理者に加えてService Account User権限も必要?
You can’t perform that action at this time.