Skip to content

Instantly share code, notes, and snippets.

@naBe-
naBe- / dtls-client.py
Created October 19, 2017 06:33 — forked from manuels/dtls-client.py
dtls for python
# -*- coding: latin-1 -*-
#
# Copyright (C) AB Strakt
# Copyright (C) Jean-Paul Calderone
# See LICENSE for details.
"""
Simple SSL client, using blocking I/O
"""
@naBe-
naBe- / udpserver.py
Created October 11, 2017 19:44 — forked from jamiesun/udpserver.py
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):
@naBe-
naBe- / listen_sqla.py
Last active October 9, 2017 07:55 — forked from dtheodor/listen_sqla.py
Listen for pg_notify with SQL Alchemy + Psycopg2
import select
import datetime
import psycopg2
import psycopg2.extensions
from sqlalchemy import create_engine, text
engine = create_engine("postgresql+psycopg2://vagrant@/postgres")
@naBe-
naBe- / README.md
Created October 4, 2017 13:23 — forked from lbolla/README.md
Asynchronous programming in Tornado

Asynchronous programming with Tornado

Asynchronous programming can be tricky for beginners, therefore I think it's useful to iron some basic concepts to avoid common pitfalls.

For an explanation about generic asynchronous programming, I recommend you one of the [many][2] [resources][3] [online][4].

I will focus on solely on asynchronous programming in [Tornado][1]. From Tornado's homepage:

@naBe-
naBe- / streaming.py
Created September 21, 2017 08:50 — forked from bdarnell/streaming.py
Demo of streaming requests with Tornado
"""Demo of streaming requests with Tornado.
This script features a client using AsyncHTTPClient's body_producer
feature to slowly produce a large request body, and two server
handlers to receive this body (one is a proxy that forwards to the
other, also using body_producer).
It also demonstrates flow control: if --client_delay is smaller than
--server_delay, the client will eventually be suspended to allow the
server to catch up. You can see this in the logs, as the "client
@naBe-
naBe- / tornado-unix-socket.py
Created September 14, 2017 11:03 — forked from superduper/tornado-unix-socket.py
Tornado web server with unix socket support
import tornado.ioloop
import tornado.web
from tornado.options import options, define
from tornado.netutil import bind_unix_socket
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
@naBe-
naBe- / make_safely_shutdown.py
Created September 11, 2017 10:31 — forked from nicky-zs/make_safely_shutdown.py
Make the tornado httpserver.HTTPServer to be shutdown safely.
# vim: fileencoding=utf-8
import time, signal
from tornado import web, ioloop, options, httpserver
_SHUTDOWN_TIMEOUT = 30
def make_safely_shutdown(server):
io_loop = server.io_loop or ioloop.IOLoop.instance()
def stop_handler(*args, **keywords):
def shutdown():
@naBe-
naBe- / vxlan-mesh-create.sh
Created September 4, 2017 18:57
Create a vxlan mesh on multiple hosts for multiple bridged interfaces to create isolated user networks. The primary use-case here is tenant Isolation with OpenStack Ironic.
#!/bin/bash
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@naBe-
naBe- / AccountLogin.sql
Created July 17, 2017 22:16 — forked from ZeusAFK/AccountLogin.sql
Account login function for PosgreSQL in PLPGSQL
CREATE OR REPLACE FUNCTION accountlogin(varusername character varying, varpassword character varying)
RETURNS integer AS
$BODY$
DECLARE
res RECORD;
BEGIN
SELECT INTO res password, authority FROM account WHERE username = varusername;
IF FOUND = FALSE THEN
RETURN 2;
ELSEIF res.password <> varpassword THEN