This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute_pi(n): | |
""" | |
This function calculates the value of pi to 'n' number of decimal places | |
Args: | |
n: precision(Decimal places) | |
Returns: | |
pi: the value of pi to n-decimal places | |
""" | |
decimal.getcontext().prec = n + 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def calcPi(): | |
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3 | |
while True: | |
if 4*q+r-t < n*t: | |
yield n | |
nr = 10*(r-n*t) | |
n = ((10*(3*q+r))//t)-10*n | |
q *= 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import threading | |
import random | |
def thr(i): | |
# we need to create a new loop for the thread, and set it as the 'default' | |
# loop that will be returned by calls to asyncio.get_event_loop() from this | |
# thread. | |
loop = asyncio.new_event_loop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#this is mostly from: | |
#http://code.activestate.com/recipes/577187-python-thread-pool/ | |
from Queue import Queue | |
from threading import Thread, Event | |
from sys import stdout, stderr | |
from time import sleep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ftplib | |
import socket | |
import socks # socksipy (https://github.com/mikedougherty/SocksiPy) | |
class FTP(ftplib.FTP): | |
def __init__(self, host='', user='', passwd='', acct='', | |
timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
proxyconfig=None): | |
"""Like ftplib.FTP constructor, but with an added `proxyconfig` kwarg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Threaded Load-balancing Broker | |
""" | |
from __future__ import print_function | |
from threading import Thread | |
import zmq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To send the ip addres of the client/webbrowser to the server/webserver behind it there are a few options: | |
1- option forwardfor | |
2- send-proxy | |
3- source 0.0.0.0 usesrc clientip | |
1- option forwardfor | |
This is an easy option to configure in haproxy, it does require that http layer7 processing is used 'mode http' and the webserver/ webapplication that wants to log or use the ip of the client must use the http-header 'X-Forwarded-For' to read the clientip. | |
2- send-proxy / send-proxy-v2 / send-proxy-* | |
This is can be used both with mode tcp and http, it does however require that the server also understands the proxyprotocol. Some applications have added support for this protocol which adds a few bytes with ip information before the actual request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# TCP Port Forwarding via Socks5 Socket | |
# Original Author : WangYihang <[email protected]> (for port forwarding) | |
# (As gist: <https://gist.github.com/WangYihang/e7d36b744557e4673d2157499f6c6b5e>) | |
# Changes : NeoAtlantis <[email protected]> | |
# (adapted to pySocks, argparse for CLI invokation, encryption, etc.) | |
import argparse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import sys | |
from tcp import * | |
def handler(data): | |
print(data) | |
return input(">> ") | |
if __name__ == '__main__': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# TCP Port Forwarding (Reverse Proxy) | |
# Author : WangYihang <[email protected]> | |
# Requires Python 3.6 or above. | |
import socket | |
import threading | |
import sys |
NewerOlder