Skip to content

Instantly share code, notes, and snippets.

View wtpayne's full-sized avatar

William Payne wtpayne

View GitHub Profile
@wtpayne
wtpayne / flask_geventwebsocket_example.py
Created July 6, 2012 23:37 — forked from lrvick/flask_geventwebsocket_example.py
Simple Websocket echo client/server with Flask and gevent / gevent-websocket
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
/req/testpage:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;900&amp;display=swap" rel="stylesheet">
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<body>
<div data-hx-sse="connect:/topic">
<div data-hx-sse="swap:outer">
<div data-hx-sse="swap:inner1"></div>
<div data-hx-sse="swap:inner2"></div>
</div>
</div>
</body>
@wtpayne
wtpayne / htmx-xact.js
Created January 2, 2021 18:25
HTMX extension for xact
htmx.defineExtension('xact', {
onEvent : function(name_evt_src, evt_src) {
// New logic is either swapped in or sent via SSE.
is_swap = (name_evt_src === 'htmx:afterSwap');
is_sse = name_evt_src.startsWith('htmx:sse:');
is_update = (is_swap || is_sse);
if (!is_update) {
return;
}
# -----------------------------------------------------------------------------
def _get_page(title, id_topic, list_id_ui):
"""
Return the HTML page.
"""
html = xact.lib.ui.web.markup.html
page = html.document(title = title)
with page.head:
html.meta(charset = 'utf-8')