获取本机的外网地址
# get outer ip
curl ifconfig.me
获取当前正在执行的脚本的路径
{ | |
"scope": "source.python", | |
"completions": | |
[ | |
{ "trigger": "python\t#!python", "contents": "#!python${1:3}" }, | |
{ "trigger": "coding\tfile encoding", "contents": "# -*- coding: ${1:utf-8} -*-" }, | |
{ "trigger": "doc\tblock doc", "contents": "\"\"\"${1:doc}\"\"\"" }, | |
{ "trigger": "import\timport...", "contents": "import ${1:module}" }, |
{ | |
"scope": "text.html.markdown, text.html.multimarkdown.markdown", | |
"completions": | |
[ | |
/** | |
* Primary | |
*/ | |
{ "trigger": "center_block\tBlock-Center", "contents": "<div align=\"center\">\n$1\n</div>" }, | |
{ "trigger": "mdi_tag\tImage", "contents": "<img src=\"${1:image_path}\" style=\"${2:max-width:600px;}\"><br/>" }, |
import logging | |
import os | |
import sys | |
def get_logger(name=None, file=None, stream=None, level=None, format=None, propagate=False): | |
"""make a logger""" | |
if stream is None: | |
stream = sys.stderr |
import os | |
try: | |
import configparser | |
except ImportError: | |
import ConfigParser as configparser | |
def get_config(config_file, section_name=None): | |
""" | |
load configuration file (like .ini). |
import argparse | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-n', '--num', dest='num', required=True, type=int, default=0) | |
parser.add_argument( | |
'-j', '--job-name', dest='job_name', required=True, |
获取本机的外网地址
# get outer ip
curl ifconfig.me
获取当前正在执行的脚本的路径
See the related question in stackoverflow.
Here is an example of how we can rewrite callback of ftplib.FTP.retrbinary
as generator. See the related question in stackoverflow.
PS: Rewriting callback of ftplib.FTP.retrbinary
is a bad idea, because the callback is blocking and might fill up your memory. In fact, urllib.urlopen
has already done the job in an elegant and non-blocking way. So, this exemaple is just for showing howto.
-- Copy table with indexes and triggers | |
CREATE TABLE newtable LIKE oldtable; | |
INSERT newtable SELECT * FROM oldtable; | |
-- copy table with just structure and data | |
CREATE TABLE tbl_new AS SELECT * FROM tbl_old; |