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 / 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 / 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
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 / 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):
@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 / requests-use-string-cookies.py
Created October 8, 2018 08:01
python requests use cookies from string copied from web browser
# -*- coding: utf-8 -*-
try:
# py3
from http.cookies import SimpleCookie
except ImportError:
# py2
from Cookie import SimpleCookie
import requests
from requests.cookies import morsel_to_cookie, RequestsCookieJar
@gsw945
gsw945 / new_radio_list.py
Created October 9, 2018 15:18
python-prompt-toolkit selection list
# -*- coding: utf-8 -*-
from prompt_toolkit.layout.margins import ScrollbarMargin
from prompt_toolkit.formatted_text import to_formatted_text
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.containers import Window
from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.key_bindings import KeyBindings
from prompt_toolkit.formatted_text import HTML
@gsw945
gsw945 / setup-01.py
Last active October 9, 2018 17:33
cdnjs downloader
# -*- coding: utf-8 -*-
import json
import requests
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import ANSI
from prompt_toolkit import print_formatted_text
@gsw945
gsw945 / cdnjs-dl.py
Last active October 11, 2018 11:23
cdnjs downloader(search library->choose version->download files->save file with auto create folder struct)
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import
import json
import logging
from multiprocessing.dummy import Pool as ThreadPool
from multiprocessing import Manager, freeze_support
import threading
import os
import sys
@gsw945
gsw945 / global-request.js
Created October 11, 2018 16:52
NodeJS global installed package usage demo
// npm install request -g
/**
* 导入全局包
* @see https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package/38535119#38535119
*/
function requireGlobal(packageName) {
var childProcess = require('child_process');
var path = require('path');
var fs = require('fs');