Skip to content

Instantly share code, notes, and snippets.

View FGtatsuro's full-sized avatar

FGtatsuro FGtatsuro

View GitHub Profile
class Prop1(object):
@property
def x(self):
'''x property'''
return self._x
@x.setter
def x(self, value):
self._x = value
@FGtatsuro
FGtatsuro / GatewayPorts_clientspecified
Created August 8, 2013 16:50
異なるPrivateネットワーク内の端末をsshで繋ぐ ref: http://qiita.com/FGtatsuro/items/e2767fa041c96a2bae1f
(pc3) $ sudo vi /etc/ssh/sshd_config
GatewayPorts clientspecified
(pc3) $ sudo /etc/init.d/sshd restart
sshd を停止中: [ OK ]
sshd を起動中: [ OK ]
# 20022番ポートの指定の前に,バインドするIP or FQDNを指定する.
(pc2) $ ssh -R (pc3):20022:localhost:22 (username)@(pc3)
@FGtatsuro
FGtatsuro / random_string
Last active December 25, 2015 01:19
ランダム文字列生成(Python) ref: http://qiita.com/FGtatsuro/items/92bca91ed665449ab047
import string
import random
n = 5
# ユーティリティ関数にすると便利かも?
random_str = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(n)])
@FGtatsuro
FGtatsuro / file0.txt
Created October 14, 2013 12:51
urllib.parse.quote関数使用時の注意 ref: http://qiita.com/FGtatsuro/items/75a4593fec954a32c10c
>>> help(urllib.parse.quote)
# 引数safeで指定された文字列はエンコード対象外となる。
quote(string, safe='/', encoding=None, errors=None)
quote('abc def') -> 'abc%20def'
(…)
By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
@FGtatsuro
FGtatsuro / python2
Created November 12, 2013 03:04
どこかで聞いたしゃべり方をするワンライナー ref: http://qiita.com/FGtatsuro/items/13abac09fb328f7bd9bc
# 標準入出力はUTF-8前提
# Python2.7
$ python -c "import sys;print('u\"'.join(unicode(sys.argv[1], 'utf-8')))" とおしてそこてかんはるんたよぉぉぉぉ
# Python3.3
$ python -c "import sys;print('\"'.join(sys.argv[1]))" とおしてそこてかんはるんたよぉぉぉぉ
@FGtatsuro
FGtatsuro / rauth_sample
Created November 13, 2013 18:22
rauthでTwitterAPIにアクセスするのが簡単すぎて、僕にも彼女が… ref: http://qiita.com/FGtatsuro/items/4513a26b19b805606929
import rauth
# access_token/access_token_secretを取得している前提
session = rauth.OAuth1Session(
"consumer_key",
"consumer_secret",
"access_token",
"access_token_secret")
# baseURLについてはsessionにセットする方法があるが省略
def _copy(src, dst):
subprocess.Popen(['cp', '-pr', src, dst]).communicate()
@FGtatsuro
FGtatsuro / file0.txt
Created January 30, 2014 18:11
泥沼の記憶(CSV)をワンライナーで処理する ref: http://qiita.com/FGtatsuro/items/5eecad6e4d2cab32eed3
4000,2000,5000,7000,20
4000,2000,5000,7000,20
4000,2000,5000,7000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
4000,3500,6010,6000,20
# 1. __new__でインスタンスをreturnしない場合
# ref. https://docs.python.org/2/reference/datamodel.html#object.__new__
class A(object):
def __new__(cls):
print('new')
# return super().__new__(cls)
def __init__(self):
print('init')
super().__init__()
>>> class D(object):
def __new__(cls):
ins = super().__new__(cls)
print(id(ins))
return ins
def __init__(self):
print(id(self))
>>> d = D()
4333861392