Skip to content

Instantly share code, notes, and snippets.

View gsw945's full-sized avatar
🙏
buddha-like coding

玖亖伍 gsw945

🙏
buddha-like coding
View GitHub Profile
@gsw945
gsw945 / timeSync.bat
Created July 19, 2017 10:02
sync time manually for windows
@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
@gsw945
gsw945 / cat_line.py
Created July 19, 2017 10:04
show file content like Linux `cat` command but only show specified line
#!/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

Python Socket 编程详细介绍

Python 提供了两个基本的 socket 模块:

  • Socket 它提供了标准的BSD Socket API。
  • SocketServer 它提供了服务器重心,可以简化网络服务器的开发。

下面讲解下 Socket模块功能。

Socket 类型

# -*- 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))
@gsw945
gsw945 / pcip-list.txt
Last active January 29, 2023 06:05
sublime text 3 Preferences.sublime-settings file
# Package Control (from: https://packagecontrol.io/installation)
Solarized Color Scheme
DocBlockr
ChineseLocalizations
ConvertToUTF8
Terminal
Terminus
SublimeCodeIntel
Jedi - Python autocompletion
SFTP
@gsw945
gsw945 / top-win.cs
Created June 20, 2018 06:16
single cs file for winfrom by csc.exe from cli
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
@gsw945
gsw945 / logo.py
Created August 2, 2018 13:53 — forked from SuperDoxin/logo.py
Python Logo using bezier curves and the turtle module
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)
@gsw945
gsw945 / flask_reverse_proxy2other_server.py
Created August 11, 2018 10:37
flask reverse proxy to other server
import logging
try:
from urllib.parse import (
urlencode,
parse_qs,
urlsplit,
urlunsplit
)
except ImportError:
from urllib import urlencode