Friday, October 13, 2017

How to Write a Simple Chat in Aiohttp

http://steelkiwi.com/blog/an-example-of-a-simple-chat-written-in-aiohttp/

Async IO Introducio

http://www.blog.pythonlibrary.org/2016/07/26/python-3-an-intro-to-asyncio/

AsyncIO - Chat - Rethinkdb

https://github.com/artydev/asynciochat/blob/master/app.py

Rethinkdb -Listen to multiple feeds with asyncio

From : https://gist.github.com/shivekkhurana/1de00e1e54c36d250a7f19905fe133b9
import rethinkdb as r
import asyncio
from typing import Callable, Dict


r.set_loop_type('asyncio')

async def get_connection():
    return await r.connect(
        db='test',
        host='localhost'
    )

async def set_change_handler(table_name: str, handler: Callable) -> None:
    print('Listening for changes on {}'.format(table_name))
    connection = await get_connection()
    feed = await r.table(table_name).changes().run(connection)
    while (await feed.fetch_next()):
        change = await feed.next()
        handler(change)
        print('Got a change on table: {}; {}'.format(table_name, change))


def get_handler_map():
    # add any table_name: handler_func here
    return {
        'events': print,
        'actions_status': print,
        'triggers_status': print
    }


def main():
    loop = asyncio.get_event_loop()
    for table_name, handler in get_handler_map().items():
        loop.create_task(set_change_handler(table_name, handler))

    loop.run_forever()

if __name__ == '__main__':
    main()

Tuesday, July 4, 2017

Développer un chat temps-réel avec Socket.io

https://blog.bini.io/developper-une-application-avec-socket-io/
Other links

File watchers and Web browser reload with NodeJS

This tips avod to manualy refresh the browser on file changes
  var express = require('express');
  var app = express();
  app.get([/\/$/, /.*\.html$/], function (req, res) {
    var filename = __dirname + req.path;
    filename += filename.endsWith('/')? 'index.html': '';
    fs.readFile(filename, function (_, data) {
      res.send(data
      + '<script src="/node_modules/socket.io-client/socket.io.js"></script>'
      + '<script>'
      + '  var socket = io();'
      + '  socket.on("file-change-event", function () {'
      + '    window.location.reload();'
      + '  });'
      + '</script>'
      );
    });
  });
  app.use(express.static(__dirname));

  var http = require('http').Server(app);
  http.listen(8080);

  var fs = require('fs');
  var io = require('socket.io')(http);
  fs.watch(__dirname, { recursive:true }, function () {
    io.emit('file-change-event');
  });

Friday, April 21, 2017

VueJS in Post

VueSample

{{ message }}

Thursday, April 20, 2017

RiotJS compiled tag inside post...

Waiting riot message....