Skip to content

Instantly share code, notes, and snippets.

from flask import Flask, render_template
app = Flask(__name__)
def gen_page(page):
def endpoint():
return render_template(page, page_name=page)
endpoint.__name__ = page
@Lothiraldan
Lothiraldan / gist:7c295329e7ec4a04d423
Created April 11, 2015 16:26
Function call in traceback detection
import inspect
import sys
def _get_code_id(callable):
if inspect.ismethod(callable):
return id(callable.im_func.func_code)
elif inspect.isfunction(callable):
return id(callable.func_code)
@Lothiraldan
Lothiraldan / gist:2c9a0f77aa64fc87079f
Created November 28, 2014 11:40
Oracle java 7 auto-accept SaltStack
{% if grains.os_family == 'Debian' %}
java7_read_license:
cmd.run:
- name: "echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections"
- unless: 'debconf-get-selections | grep "shared/accepted-oracle-license-v1-1"'
- require:
- pkg: debconf-utils
- require_in:
- pkg: java7_packages
def recv_future(zmqstream):
''' Retruns future for recv on zmqstream
'''
future = Future()
def _finish(reply):
future.set_result(reply)
zmqstream.on_recv(_finish)
from tornado.platform.asyncio import AsyncIOMainLoop
import asyncio
import tornado
import tornado.web
import tornado.gen
from inspect import isgeneratorfunction, isgenerator
AsyncIOMainLoop().install()
loop = asyncio.get_event_loop()
@Lothiraldan
Lothiraldan / fabfile.py
Created February 7, 2014 13:31
FabFile for creating VagrantFile using salt provisionner with pregenerated keys
"""Deployment tasks using fabric
"""
import sys
from os.path import join, abspath, dirname, expanduser, exists, normpath
from fabric.api import prompt, env, sudo, put, task, local, run, cd
# from settings import settings
from fabric.colors import green, red
from shutil import copy
@Lothiraldan
Lothiraldan / Output
Last active December 29, 2015 05:59
Tornado + yield from = <3
# http://localhost:8888/?mode=sync
http://wikipedia.com code: 200
http://google.com code: 200
http://example.com code: 200
#> time curl http://localhost:8888/\?mode\=sync
http://wikipedia.com code: 200<br/>http://google.com code: 200<br/>http://example.com code: 200curl http://localhost:8888/\?mode\=sync 0,01s user 0,00s system 0% cpu 1,106 total
# http://localhost:8888/?mode=async
import sys
import socket
from tornado.web import Application as BaseApplication
from tornado.options import define, options, parse_command_line
class Application(BaseApplication):
def listen(self, port, address="", **kwargs):
if options.fd:
@Lothiraldan
Lothiraldan / gist:5612446
Created May 20, 2013 14:05
Fix for circus #403
diff --git a/circus/process.py b/circus/process.py
index 070cb10..f7cb699 100644
--- a/circus/process.py
+++ b/circus/process.py
@@ -124,7 +124,7 @@ class Process(object):
if self.uid:
os.setuid(self.uid)
- self._worker = Popen(args, cwd=self.working_dir,
+ self._worker = Popen(args, bufsize=-1, cwd=self.working_dir,
diff --git a/circus/process.py b/circus/process.py
index 070cb10..f7cb699 100644
--- a/circus/process.py
+++ b/circus/process.py
@@ -124,7 +124,7 @@ class Process(object):
if self.uid:
os.setuid(self.uid)
- self._worker = Popen(args, cwd=self.working_dir,
+ self._worker = Popen(args, bufsize=-1, cwd=self.working_dir,