This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prop1(object): | |
@property | |
def x(self): | |
'''x property''' | |
return self._x | |
@x.setter | |
def x(self, value): | |
self._x = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import random | |
n = 5 | |
# ユーティリティ関数にすると便利かも? | |
random_str = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(n)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 標準入出力は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]))" とおしてそこてかんはるんたよぉぉぉぉ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rauth | |
# access_token/access_token_secretを取得している前提 | |
session = rauth.OAuth1Session( | |
"consumer_key", | |
"consumer_secret", | |
"access_token", | |
"access_token_secret") | |
# baseURLについてはsessionにセットする方法があるが省略 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _copy(src, dst): | |
subprocess.Popen(['cp', '-pr', src, dst]).communicate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class D(object): | |
def __new__(cls): | |
ins = super().__new__(cls) | |
print(id(ins)) | |
return ins | |
def __init__(self): | |
print(id(self)) | |
>>> d = D() | |
4333861392 |