Skip to content

Instantly share code, notes, and snippets.

@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
@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
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()
def recv_future(zmqstream):
''' Retruns future for recv on zmqstream
'''
future = Future()
def _finish(reply):
future.set_result(reply)
zmqstream.on_recv(_finish)
@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
@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)
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
import asyncio
from aiohttp.web import Application, Response
@asyncio.coroutine
def resource(request):
return Response(text=repr(request.match_info))
@asyncio.coroutine
<code>
<test@email.com>
</code>
@Lothiraldan
Lothiraldan / .zshrc
Last active April 27, 2016 12:17
Mac OS X zshrc prank
ROOT_UID=0
if [ $UID != $ROOT_UID ]; then
sudo osascript -e "set Volume 10"
fi
fortune -a | tee /dev/fd/2 | say -v $(say -v "?" | cut -d ' ' -f 1 | ruby -e 'puts STDIN.readlines.shuffle' | head -n 1)&