Skip to content

Instantly share code, notes, and snippets.

@rhoboro
rhoboro / janken.py
Created February 2, 2019 12:53
Pythonのジェネレータでじゃんけんプログラム
from random import randint
from enum import Enum
class Card(Enum):
Rock = 0
Paper = 1
Scissors = 2
@rhoboro
rhoboro / post.js
Last active October 15, 2018 09:47
alert("hoge");
@rhoboro
rhoboro / async_sample.py
Last active April 30, 2023 07:24
asyncio, aiohttpを利用した並列処理のサンプルコード
import asyncio
import aiohttp
import async_timeout
from aiohttp import ClientError
async def _fetch(session, url, coro):
"""HTTPリソースからデータを取得しコルーチンを呼び出す
@rhoboro
rhoboro / Dockerfile
Last active December 29, 2017 08:34
サービスアカウントgsutilを使う
# 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 November 22, 2017 01:16
GAE/SE/pyでfetchurlを使うメソッドのテスト
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 November 22, 2017 00:18
dict.get()の多次元版
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=[])
[SECTION1]
name=value
@rhoboro
rhoboro / ansible_gce_site.yml
Last active July 30, 2017 02:37
GCEインスタンスを作成=>ping=>削除するAnsibleのPlaybook
# [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権限も必要?
@rhoboro
rhoboro / Dockerfile
Last active July 28, 2017 03:06
GAE/pyのベースイメージ
FROM ubuntu:16.04
LABEL maintainer "rhoboro <rhoboro@gmail.com>"
ENV HOME /root
WORKDIR $HOME
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y -q python2.7-mysqldb zip build-essential make curl python-dev wget libmysqlclient-dev python-configparser \
&& wget https://bootstrap.pypa.io/get-pip.py \
&& python get-pip.py
# mysql-serverを入れる際にrootパスワードを聞かれるのを回避する

GitHubリポジトリ命名規則

方針

一覧性、検索性をあげるために前方から絞り込みやすくしたい

共通

  • 小文字アルファベット + _ で。