Skip to content

Instantly share code, notes, and snippets.

@shoma
shoma / .pythonrc.py
Created September 9, 2011 01:34
my PYTHONSTARTUP script
# -*- coding: utf-8 -*-
"""my PYTHONSTARTUP script"""
import sys
import codecs
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
@shoma
shoma / python-shell-sample.py
Created November 30, 2011 04:29
shell like main loop
# -*- coding: utf-8 -*-
import sys
def call_command(name, *args):
"""
call method from command module.
command class have run method.
"""
command = import_subcommand(name)
@shoma
shoma / comment-sample.py
Created December 7, 2011 00:56
Better comment for python
# -*- coding: utf-8 -*-
u"""Hoge これはコメントの書き方のサンプルです。
ダブルクォート3つの中に書いたものがドキュメンテーション文字列として扱われます。
ファイルの先頭にあるこの部分は DESCRIPTION というブロックになります。
1行目は NAME というブロックになります。
先頭に u をつけているのはユニコード文字列として扱われるようにするためです。
# -*- coding: utf-8 -*-
print '|{0:{width}}|'.format('ああああ', width=8)
print '|{0:{width}}|'.format('あああ', width=8+3)
print '|{0:{width}}|'.format('ああ', width=8+2)
print '|{0:{width}}|'.format('あ', width=8+1)
print '|{0:{width}}|'.format('あa', width=8+1)
print '|{0:{width}}|'.format('aa', width=8)
print '|{0:{width}}|'.format('a', width=8)
@shoma
shoma / pre-commit-pep8.py
Created December 12, 2012 08:33
run pep8 on git pre-commit hook.
#!/usr/bin/env python
"""pre-commit-pep8.py
requirements
- pep8==1.3.3
- sh==1.07
in .git/hooks/pre-commit
#!/bin/sh
@shoma
shoma / VisionService.php
Last active November 5, 2016 16:39
An example usage for Google Cloud Vision API with PHP on GCE
<?php
require './vendor/autoload.php';
use Google_Client;
use Google_Service_Vision;
use Google_Service_Vision_AnnotateImageRequest;
use Google_Service_Vision_BatchAnnotateImagesRequest;
use Google_Service_Vision_Feature;
use Google_Service_Vision_Image;
use Google_Service_Vision_ImageSource;
@shoma
shoma / dietcube.gce.patch
Created February 29, 2016 03:21
A patch to run DietCube on Google Compute Engine
diff -uprN orig/vendor/dietcube/dietcube/src/Application.php gce/vendor/dietcube/dietcube/src/Application.php
--- orig/vendor/dietcube/dietcube/src/Application.php 2016-01-29 13:08:52.000000000 +0900
+++ gce/vendor/dietcube/dietcube/src/Application.php 2016-02-25 19:36:22.315706094 +0900
@@ -71,7 +71,7 @@ abstract class Application
{
$server = $container['global.server']->get();
$this->host = $server['HTTP_HOST'];
- $this->port = $server['SERVER_PORT'];
+ $this->port = isset($server['SERVER_PORT']) ? $server['SERVER_PORT'] : 80;
$this->protocol = (($this->port == '443' || (isset($server['X_FORWARDED_PROTO']) && $server['X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http');
@shoma
shoma / wordle.py
Last active January 26, 2022 23:56
helper for wordle
import re
import os
import operator
from collections import OrderedDict
"""
https://www.powerlanguage.co.uk/wordle/
"""
@shoma
shoma / crds.yaml
Created November 16, 2022 11:00
Google Kubernetes Engine CustomResourceDefinition
apiVersion: v1
items:
- apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
creationTimestamp: "2022-11-16T06:18:36Z"
generation: 1
name: backendconfigs.cloud.google.com
resourceVersion: "806"
uid: 8cf21b33-1698-48e9-bb3b-2b6435cf4805