Python 提供了两个基本的 socket 模块:
Socket
它提供了标准的BSD Socket API。SocketServer
它提供了服务器重心,可以简化网络服务器的开发。
下面讲解下 Socket模块功能。
@echo on & @setlocal enableextensions | |
@echo ========================= | |
@echo Turn off the time service | |
net stop w32time | |
@echo ====================================================================== | |
@echo Set the SNTP (Simple Network Time Protocol) source for the time server | |
w32tm /config /syncfromflags:manual /manualpeerlist:"0.it.pool.ntp.org 1.it.pool.ntp.org 2.it.pool.ntp.org 3.it.pool.ntp.org" | |
@echo ============================================= | |
@echo ... and then turn on the time service back on | |
net start w32time |
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import argparse | |
import os | |
import linecache | |
import sys | |
#!/usr/bin/env python | |
# A simple demonstration of using cairo to shape windows. | |
# Natan 'whatah' Zohar | |
import gtk | |
import math | |
class ShapedGUI: | |
def __init__(self): | |
self.window = gtk.Window() | |
self.window.show() # We show here so the window gets a border on it by the WM |
# -*- coding: utf-8 -*- | |
import hashlib | |
def file_md5sum(file_path): | |
'''计算文件md5值''' | |
hash_md5 = hashlib.md5() | |
chunk_size = 4096 | |
with open(file_path, "rb") as f: | |
chunk = f.read(chunk_size) | |
while bool(chunk): |
# -*- coding: utf-8 -*- | |
import os | |
def print_size(size): | |
'''打印文件大小''' | |
print('Size: {0} Byte'.format(size)) | |
print('Size: {0} KB'.format(size / 1024)) | |
print('Size: {0} MB'.format(size / 1024 / 1024)) | |
print('Size: {0} GB'.format(size / 1024 / 1024 / 1024)) |
# Package Control (from: https://packagecontrol.io/installation) | |
Solarized Color Scheme | |
DocBlockr | |
ChineseLocalizations | |
ConvertToUTF8 | |
Terminal | |
Terminus | |
SublimeCodeIntel | |
Jedi - Python autocompletion | |
SFTP |
using System; // Console | |
using System.Runtime.InteropServices; // DllImport、StructLayout | |
using System.Windows.Forms; // Screen、Form | |
using System.Drawing; // Rectangle | |
using System.ComponentModel; | |
using System.Diagnostics; // Process | |
/** | |
* https://docs.microsoft.com/en-us/dotnet/framework/app-domains/how-to-build-a-single-file-assembly | |
* https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe |
import turtle | |
import math | |
def lerp(a, b, t): | |
"""Linear interpolation function. returns a when t==0, returns b when t==1 | |
and linearly interpolates for values inbetween""" | |
return (a * (1 - t)) + (b * t) | |
import logging | |
try: | |
from urllib.parse import ( | |
urlencode, | |
parse_qs, | |
urlsplit, | |
urlunsplit | |
) | |
except ImportError: | |
from urllib import urlencode |