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 / python-selenium-open-tab.md
Created September 30, 2018 01:15 — forked from lrhache/python-selenium-open-tab.md
Python Selenium - Open new tab / focus tab / close tab

On a recent project, I ran into an issue with Python Selenium webdriver. There's no easy way to open a new tab, grab whatever you need and return to original window opener.

Here's a couple people who ran into the same complication:

So, after many minutes (read about an hour) of searching, I decided to do find a quick solution to this problem.

@gsw945
gsw945 / transactions.py
Created September 18, 2018 08:36 — forked from elliotchance/transactions.py
Implementing all four SQL transaction isolation levels in Python
# -*- coding: utf8 -*-
from __future__ import print_function
class LockManager:
def __init__(self):
self.locks = []
def add(self, transaction, record_id):
if not self.exists(transaction, record_id):
next_xid = 1
active_xids = set()
records = []
def new_transaction():
global next_xid
next_xid += 1
active_xids.add(next_xid)
return Transaction(next_xid)
@gsw945
gsw945 / static-server.py
Last active August 12, 2018 07:24
static web server via aiohttp
# -*- coding: utf-8 -*-
# need to upgrade the default Python version on Ubuntu 16.04
# refer:
# https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get
# https://aiohttp.readthedocs.io/en/stable/web_advanced.html#static-file-handling
import os
import logging
try:
from aiohttp import web
@gsw945
gsw945 / simple-ddos.py
Created August 12, 2018 07:08
simple ddos via multiprocessing(.dummy) and requests
# -*- coding: utf-8 -*-
import os
import sys
import multiprocessing as mp
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool
from datetime import datetime
try:
import requests
except ImportError:
@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
@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 / 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 / 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
# -*- 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))