Skip to content

Instantly share code, notes, and snippets.

@imbolc
imbolc / gist:5140667
Created March 12, 2013 06:04
lmd-noname-deps
/*jslint node: true */
"use strict";
function noname_deps(paths) {
function format_single(path, parent_name) {
var dep = {path: path};
if (parent_name) {
dep.require = {};
dep.require[parent_name] = parent_name;
}
@imbolc
imbolc / gist:8441403
Last active January 3, 2016 09:19
read firefox cookies
import os
import sqlite3
import ConfigParser
class FirefoxCookies(object):
'''
Usage:
cookies = FirefoxCookies()
print cookies.items() # [(name, value), ...]
@imbolc
imbolc / aiorest-class-based-resource.py
Last active August 29, 2015 14:06
aiorest (asyncio) class-based resources
import asyncio
import aiorest
import aiohttp
class RESTResource:
# you can redefine it in subclasses
handlers = [
('list', 'GET', []),
@imbolc
imbolc / gist:f73cde848b96bd253b16
Last active August 29, 2015 14:08
`for` statement implementation with `while`
seq = ['a', 1, True, 'b', 'foo', 'bar']
for item in seq:
print(item)
print()
i = 0
while i < len(seq):
@imbolc
imbolc / gist:0deb6a5fad8fab4c678c
Created January 17, 2015 02:30
aiohttp get_argement helpers
from aiohttp import web
def get_qs_argument(request, *args, **kwargs):
return _get_argument(request.GET, *args, **kwargs)
def get_url_argument(request, *args, **kwargs):
return _get_argument(request.match_info, *args, **kwargs)
@imbolc
imbolc / keep_alive.py
Created October 27, 2015 16:59
Understanding aiohttp.ClientSession
from time import time
import asyncio
import aiohttp
from aiohttp import web
async def web_handler(request):
n = int(request.GET.get('n', 0))
return web.Response(text=str(n+1))
@imbolc
imbolc / aiohttp_rq.py
Created October 28, 2015 09:03
Testing of aiohttp + rq performance
'''
I started one server:
$ python aiohttp_rq.py server
And three workers in different terminals:
$ python aiohttp_rq.py worker
And I got next results with ab:
import asyncio
from aiohttp import web
from aiohttp_session import get_session, session_middleware, SimpleCookieStorage
async def show(request):
session = await get_session(request)
message = session.pop('message', None)
return web.Response(text='message: {}'.format(message))
@imbolc
imbolc / flash.py
Created January 4, 2016 12:02
aiohttp flash messages
from aiohttp_session import get_session
def flash(request, message):
request.setdefault('flash_outgoing', []).append(message)
async def context_processor(request):
return {
'get_flashed_messages': lambda: request.pop('flash_incoming')
@imbolc
imbolc / mongodb
Last active August 13, 2016 08:03 — forked from srpouyet/mongodb
Mongodb logrotate on debian Jessie
# Put this in /etc/logrotate.d/mongodb
# http://stackoverflow.com/questions/5004626/mongodb-log-file-growth
/var/log/mongodb/*.log {
daily
rotate 30
compress
dateext
missingok
notifempty