Skip to content

Instantly share code, notes, and snippets.

View biggers's full-sized avatar

Mark Biggers biggers

View GitHub Profile
@jamiesun
jamiesun / udpserver.py
Created May 25, 2014 10:34
tornado UDP server
#!/usr/bin/env python
#coding=utf-8
import socket
import os
import errno
from tornado.ioloop import IOLoop
from tornado.platform.auto import set_close_exec
class UDPServer(object):
def __init__(self, io_loop=None):
@mivade
mivade / tornadobg.py
Last active March 17, 2020 02:07
Background tasks with tornado and concurrent.futures
"""A simple demonstration of running background tasks with Tornado.
Here I am using a basic TCP server which handles streams and keeps
them open while asynchronously performing a fake task in the
background. In order to test it, simply telnet to localhost port 8080
and start typing things to see that the server receives the messages.
The advantage to running on an executor instead of conventional
threads is that we can more easily shut it down by stopping the
tornado IO loop.
@mivade
mivade / coroutinify.py
Created August 3, 2015 17:53
Adapting blocking calls to Tornado coroutines with run_on_executor decorators
import random
import time
from tornado import gen
from tornado.concurrent import run_on_executor, futures
from tornado.ioloop import IOLoop
class TaskRunner(object):
def __init__(self, loop=None):
self.executor = futures.ThreadPoolExecutor(4)
self.loop = loop or IOLoop.instance()
@davebshow
davebshow / a_aioclient.py
Last active July 24, 2017 01:28
This gist details some simple profiling that I did to compare compare a Tornado based client implementation vs. a Aiohttp based implementation of gremlinclient. To do so, I simply dropped the Aiohttp websocket client in the place of the Tornado client in gremlinclient like shown in the following file. Next I did a simple IPython %timeit, followe…
import asyncio
import collections
import json
import uuid
import aiohttp
Message = collections.namedtuple(
"Message",
@biggers
biggers / Makefile.docker
Created March 22, 2016 15:46
GNU Makefile for docker-compose work
## -*- makefile -*-
## biggers@utsl.com, Mark Biggers
## GNU Makefile for docker-compose build & run of a Python or other Project
##
## REFs:
## https://docs.docker.com/compose/reference/
## https://github.com/docker/compose/releases
##
@jianingy
jianingy / iodatagram.py
Last active November 15, 2017 12:11
udp / raw socket for python tornado
#
# This piece of code is written by
# Jianing Yang <jianingy.yang@gmail.com>
# with love and passion!
#
# H A P P Y H A C K I N G !
# _____ ______
# ____==== ]OO|_n_n__][. | |
# [________]_|__|________)< |YANG|
# oo oo 'oo OOOO-| oo\\_ ~o~~o~
#!/usr/bin/env python
'''Script to pull data out of GitHub and push into Elasticsearch'''
import os
import sys
import requests
import httplib
import json # NOQA
from urlparse import urljoin
from uritemplate import expand
@biggers
biggers / ansible-tagged-install.sh
Last active January 18, 2017 14:10
Installing Ansible from 'git source' -- by tagged-release
## better, working "shell-recipe" for installing a tagged
## Ansible release, from Git source
## https://github.com/ansible/ansible/tags
sudo aptitude install python-yaml python-jinja2 python-paramiko
cd ~/git/Python
tag_name='v1.9.4-1'
git clone git://github.com/ansible/ansible.git --recursive
@biggers
biggers / x11vnc.sh
Created August 19, 2016 14:37
x11vnc service start-up script
#!/bin/sh
VNC_SERVER=/usr/bin/x11vnc
VNC_DISPLAY=:0
LOG_FILE=/tmp/x11vnc-run.log
case "$1" in
start|restart)
killall ${VNC_SERVER}
@fabianvf
fabianvf / oreilly_downloader.py
Last active February 26, 2020 13:42
Downloads Oreilly free ebooks by category. Requires requests library and python 2. Categories I've see so far are business, data, iot, security, web-platform, webops-perf, programming, so usage would look like: python oreilly_downloader.py business data iot security web-platform webops-perf programming
import os
import re
import sys
import requests
filename_matcher = re.compile(r'http://www.oreilly.com/(.*)/free/(.*).csp')
def main():
categories = sys.argv[1:]
urls = map(lambda x: 'http://www.oreilly.com/{}/free/'.format(x), categories)