Skip to content

Instantly share code, notes, and snippets.

View adamstep's full-sized avatar

Adam Stepinski adamstep

View GitHub Profile
@adamstep
adamstep / ic.html
Created January 7, 2020 23:44
Intercooler input test
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://intercoolerjs.org/release/intercooler-1.2.3.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-mockjax@2.5.0/src/jquery.mockjax.min.js"></script>
</head>
<body>
<div id="page-content">
<form ic-post-to="/date" ic-select-from-response="#page-content" ic-target="#page-content">
<input type="text" name="year" value="2020">
<div ic-sse-src="/dashboard/events">
<div ic-trigger-on="sse:status-updated-123" ic-src="/status/123">
Not arrived
</div>
</div>
@adamstep
adamstep / mercure.py
Last active May 15, 2021 13:32
Using Mercure with Django for Server-sent events
# Helper functions for publishing events, generating JWT tokens, and generating the Hub URL.
def publish_event(event_type, topic, targets):
"""
Publishes an event to the Mercure Hub.
event_type: The type of the event, can be any string
topic: The topic the event will be sent to. Only subscribers who request this topic will get notified.
targets: The targets that are eligible to get the event.
"""
token = get_jwt_token([], targets)
[
{
"first_name": "Michael",
"last_name": "Scott",
"favorite_movies": [ "Diehard", "Threat Level Midnight" ]
},
{
"first_name": "Dwight",
"last_name": "Schrute",
"favorite_movies": [ "The Crow", "Wedding Crashers" ]