Skip to content

Instantly share code, notes, and snippets.

View ktosiu's full-sized avatar

Marcin Boćkowski ktosiu

View GitHub Profile
@ktosiu
ktosiu / gist:d3344cf5d8fc53d6dc007f694a247379
Last active January 29, 2017 21:26 — forked from ties/gist:1424374
pcap/dpkt example that dumps (some) http request headers
#!/usr/bin/env python
import dpkt, pcap, socket
from ipaddr import IPv4Address, IPv6Address
import syslog
class HTTPRequest():
def __init__(self, host, uri, ip = None, user_agent = None):
self.uri = uri
self.user_agent = user_agent
self.host = host
@ktosiu
ktosiu / espresso.py
Created October 19, 2016 13:03 — forked from vivekfantain/espresso.py
zeromq XPUB/XSUB issue that cannot be explained
# Espresso Pattern
# This shows how to capture data using a pub-sub proxy
#
import time
from random import randint
from string import uppercase
from threading import Thread
@ktosiu
ktosiu / pubfwd.py
Created October 19, 2016 13:00 — forked from minrk/pubfwd.py
"""
An XPUB/XSUB broker that forwards subscriptions
"""
import os
import string
import sys
import time
from random import randint
from threading import Thread
@ktosiu
ktosiu / python_logging.yaml
Created October 5, 2016 06:22 — forked from bootandy/python_logging.yaml
Sample logging config file for python logging module
# use with: logging.config.dictConfig(yaml.load(open('logging.yaml', 'r')))
# Formatters detailed here: http://docs.python.org/2/library/logging.html#logrecord-attributes
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
detail:
format: '%(asctime)s - %(levelname)s - File: %(filename)s - %(funcName)s() - Line: %(lineno)d - %(message)s'
@ktosiu
ktosiu / gevent_http.md
Created October 5, 2016 06:22 — forked from softwaredoug/gevent_http.md
gevent_http

A response to Preetam Jinka's nice little Go demo.

Similar basic HTTP server using Gevent/Python

from gevent import pywsgi
import md5

def md5_body(environ, start_response):
    md5Hash = md5.new()
@ktosiu
ktosiu / gethreading.py
Created October 5, 2016 05:18 — forked from serialx/gethreading.py
gevent getthreading
import gevent, gevent.event
import threading, Queue, collections, time, functools
def _threads_poller_f():
while _OsThread._threads_count:
try:
t, rv, isexc = _OsThread._threads_results.get_nowait()
except Queue.Empty:
gevent.sleep()
else:
@ktosiu
ktosiu / gevent-multiprocess.py
Created October 5, 2016 05:18 — forked from notedit/gevent-multiprocess.py
gevent-multiprocess
import sys
from gevent import server
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
def echo(socket, address):
@ktosiu
ktosiu / gevent_examples.py
Created October 5, 2016 05:17 — forked from swinton/gevent_examples.py
Gevent examples
#!/usr/bin/env python
"""
Gevent examples.
"""
import json
import gevent
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Yuande Liu <miraclecome (at) gmail.com>
from __future__ import print_function, division
from gevent import monkey; monkey.patch_all()
import gevent
import time
#!/usr/bin/env python
"""Resolve hostnames concurrently, exit after 60 seconds.
Under the hood, this might use an asynchronous resolver based on
c-ares (the default) or thread-pool-based resolver.
You can choose between resolvers using GEVENT_RESOLVER environment
variable. To enable threading resolver:
GEVENT_RESOLVER=thread python dns_mass_resolve.py