diff --git a/docs/index.html b/docs/index.html index b019e3f5003..c9e5cf57327 100644 --- a/docs/index.html +++ b/docs/index.html @@ -89,6 +89,15 @@

News

+
  • + Server-Sent Events (SSE) Are Underrated (igorstechnoclub.com) +
  • + + + + + +
  • I thought I found a bug (www.os2museum.com)
  • @@ -153,7 +162,7 @@

    News

  • - macOS menu bar app that shows how full the ISS urine tank is in real time (github.com) + CRT Simulation in a GPU Shader, Looks Better Than Black Frame Insertion (blurbusters.com)
  • @@ -224,15 +233,6 @@

    News

    -
  • - A new learning experience on MDN (developer.mozilla.org) -
  • - - - - - -
  • Feel, don't think (ntietz.com)
  • diff --git a/docs/log.txt b/docs/log.txt index bbb951a323a..19a7887666d 100644 --- a/docs/log.txt +++ b/docs/log.txt @@ -1,41 +1,41 @@ -2024/12/26 15:16:26 error parsing https://mikehudack.substack.com/feed: http error: 403 Forbidden -2024/12/26 15:16:26 Fetched posts from https://mikehudack.substack.com/feed, took 57.826069ms -2024/12/26 15:16:26 error parsing https://themargins.substack.com/feed.xml: http error: 403 Forbidden -2024/12/26 15:16:26 Fetched posts from https://themargins.substack.com/feed.xml, took 65.915935ms -2024/12/26 15:16:26 error parsing https://highgrowthengineering.substack.com/feed: http error: 403 Forbidden -2024/12/26 15:16:26 Fetched posts from https://highgrowthengineering.substack.com/feed, took 112.270016ms -2024/12/26 15:16:26 Fetched posts from https://www.benkuhn.net/index.xml, took 149.597085ms -2024/12/26 15:16:26 Fetched posts from https://www.slowernews.com/rss.xml, took 153.413776ms -2024/12/26 15:16:26 Fetched posts from https://anewsletter.alisoneroman.com/feed, took 163.512747ms -2024/12/26 15:16:26 Fetched posts from https://macwright.com/rss.xml, took 191.149108ms -2024/12/26 15:16:26 Fetched posts from https://twobithistory.org/feed.xml, took 253.715751ms -2024/12/26 15:16:26 Fetched posts from https://jvns.ca/atom.xml, took 262.082831ms -2024/12/26 15:16:26 Fetched posts from https://blog.golang.org/feed.atom?format=xml, took 263.936447ms -2024/12/26 15:16:26 Fetched posts from https://joy.recurse.com/feed.atom, took 268.279796ms -2024/12/26 15:16:26 Fetched posts from https://www.wildlondon.org.uk/blog/all/rss.xml, took 296.156029ms -2024/12/26 15:16:26 Fetched posts from https://danluu.com/atom.xml, took 305.702537ms -2024/12/26 15:16:26 Fetched posts from https://routley.io/reserialised/great-expectations/2022-08-24/index.xml, took 343.629138ms -2024/12/26 15:16:26 Content still empty after HTML reader: https://pbat.ch/recurse/demos/trio/ -2024/12/26 15:16:26 Fetched posts from https://scattered-thoughts.net/rss.xml, took 513.044182ms -2024/12/26 15:16:26 Fetched posts from https://blog.veitheller.de/feed.rss, took 740.406675ms -2024/12/26 15:16:27 Fetched posts from https://solar.lowtechmagazine.com/feeds/all-en.atom.xml, took 1.032738957s -2024/12/26 15:16:27 Fetched posts from http://tonsky.me/blog/atom.xml, took 1.558082597s -2024/12/26 15:16:27 Fetched posts from https://commoncog.com/blog/rss/, took 1.713294999s -2024/12/26 15:16:28 Content still empty after HTML reader: https://todaythings.substack.com/p/to-acquire-a-goshawk-is-a-major-decision -2024/12/26 15:16:28 Fetched posts from https://gochugarugirl.com/feed/, took 2.936738041s -2024/12/26 15:16:29 Content still empty after HTML reader: https://yc-map.vercel.app/ -2024/12/26 15:16:30 Content still empty after HTML reader: http://tinylogger.com/max/wnTJ9xu3fw5UiXLp -2024/12/26 15:16:31 Content still empty after HTML reader: https://www.youtube.com/watch?v=IQqtsm-bBRU -2024/12/26 15:16:31 Content still empty after HTML reader: https://papermatch.mitanshu.tech/ -2024/12/26 15:16:31 Get "https://www.fixbrowser.org/": tls: failed to verify certificate: x509: certificate signed by unknown authority -2024/12/26 15:16:32 Fetched posts from https://blaggregator.recurse.com/atom.xml?token=4c4c4e40044244aab4a36e681dfb8fb0, took 6.584293795s -2024/12/26 15:16:32 Fetched posts from https://hnrss.org/frontpage?points=50, took 6.66856414s -2024/12/26 15:16:56 error parsing https://rachelbythebay.com/w/atom.xml: Get "https://rachelbythebay.com/w/atom.xml": dial tcp 216.218.228.215:443: i/o timeout -2024/12/26 15:16:56 Fetched posts from https://rachelbythebay.com/w/atom.xml, took 30.001801916s -2024/12/26 15:16:56 Skipping writing post, no content: https://pbat.ch/recurse/demos/trio/ -2024/12/26 15:16:56 Skipping writing post, no content: https://yc-map.vercel.app/ -2024/12/26 15:16:56 Skipping writing post, no content: https://www.youtube.com/watch?v=IQqtsm-bBRU -2024/12/26 15:16:56 Skipping writing post, no content: https://papermatch.mitanshu.tech/ -2024/12/26 15:16:56 Skipping writing post, no content: https://todaythings.substack.com/p/to-acquire-a-goshawk-is-a-major-decision -2024/12/26 15:16:56 Skipping writing post, no content: http://tinylogger.com/max/wnTJ9xu3fw5UiXLp -2024/12/26 15:16:56 Templated 41 posts, took 5.434664ms +2024/12/26 16:20:00 Fetched posts from https://www.slowernews.com/rss.xml, took 34.724119ms +2024/12/26 16:20:00 error parsing https://highgrowthengineering.substack.com/feed: http error: 403 Forbidden +2024/12/26 16:20:00 Fetched posts from https://highgrowthengineering.substack.com/feed, took 40.48465ms +2024/12/26 16:20:00 error parsing https://themargins.substack.com/feed.xml: http error: 403 Forbidden +2024/12/26 16:20:00 Fetched posts from https://themargins.substack.com/feed.xml, took 42.062072ms +2024/12/26 16:20:00 error parsing https://mikehudack.substack.com/feed: http error: 403 Forbidden +2024/12/26 16:20:00 Fetched posts from https://mikehudack.substack.com/feed, took 45.746484ms +2024/12/26 16:20:01 Fetched posts from https://macwright.com/rss.xml, took 80.525753ms +2024/12/26 16:20:01 Fetched posts from https://anewsletter.alisoneroman.com/feed, took 128.778466ms +2024/12/26 16:20:01 Fetched posts from https://www.benkuhn.net/index.xml, took 159.641063ms +2024/12/26 16:20:01 Fetched posts from https://jvns.ca/atom.xml, took 161.336374ms +2024/12/26 16:20:01 Fetched posts from https://twobithistory.org/feed.xml, took 162.985464ms +2024/12/26 16:20:01 Fetched posts from https://joy.recurse.com/feed.atom, took 205.953173ms +2024/12/26 16:20:01 Fetched posts from https://www.wildlondon.org.uk/blog/all/rss.xml, took 230.631267ms +2024/12/26 16:20:01 Fetched posts from https://routley.io/reserialised/great-expectations/2022-08-24/index.xml, took 311.537901ms +2024/12/26 16:20:01 Fetched posts from https://danluu.com/atom.xml, took 323.413862ms +2024/12/26 16:20:01 Fetched posts from https://blog.golang.org/feed.atom?format=xml, took 350.106822ms +2024/12/26 16:20:01 Fetched posts from https://scattered-thoughts.net/rss.xml, took 357.374621ms +2024/12/26 16:20:01 Content still empty after HTML reader: https://pbat.ch/recurse/demos/trio/ +2024/12/26 16:20:01 Fetched posts from https://blog.veitheller.de/feed.rss, took 642.68361ms +2024/12/26 16:20:01 Fetched posts from https://solar.lowtechmagazine.com/feeds/all-en.atom.xml, took 997.618397ms +2024/12/26 16:20:02 Fetched posts from http://tonsky.me/blog/atom.xml, took 1.065095493s +2024/12/26 16:20:02 Content still empty after HTML reader: https://todaythings.substack.com/p/to-acquire-a-goshawk-is-a-major-decision +2024/12/26 16:20:02 Content still empty after HTML reader: https://yc-map.vercel.app/ +2024/12/26 16:20:03 Fetched posts from https://commoncog.com/blog/rss/, took 2.127563324s +2024/12/26 16:20:03 Content still empty after HTML reader: http://tinylogger.com/max/wnTJ9xu3fw5UiXLp +2024/12/26 16:20:03 Fetched posts from https://gochugarugirl.com/feed/, took 2.716032231s +2024/12/26 16:20:04 Content still empty after HTML reader: https://www.youtube.com/watch?v=IQqtsm-bBRU +2024/12/26 16:20:04 Content still empty after HTML reader: https://papermatch.mitanshu.tech/ +2024/12/26 16:20:05 Get "https://www.fixbrowser.org/": tls: failed to verify certificate: x509: certificate signed by unknown authority +2024/12/26 16:20:05 Fetched posts from https://hnrss.org/frontpage?points=50, took 5.030483278s +2024/12/26 16:20:06 Fetched posts from https://blaggregator.recurse.com/atom.xml?token=4c4c4e40044244aab4a36e681dfb8fb0, took 5.826166058s +2024/12/26 16:20:30 error parsing https://rachelbythebay.com/w/atom.xml: Get "https://rachelbythebay.com/w/atom.xml": dial tcp 216.218.228.215:443: i/o timeout +2024/12/26 16:20:30 Fetched posts from https://rachelbythebay.com/w/atom.xml, took 30.003363711s +2024/12/26 16:20:30 Skipping writing post, no content: https://pbat.ch/recurse/demos/trio/ +2024/12/26 16:20:30 Skipping writing post, no content: https://yc-map.vercel.app/ +2024/12/26 16:20:30 Skipping writing post, no content: https://www.youtube.com/watch?v=IQqtsm-bBRU +2024/12/26 16:20:30 Skipping writing post, no content: https://papermatch.mitanshu.tech/ +2024/12/26 16:20:30 Skipping writing post, no content: https://todaythings.substack.com/p/to-acquire-a-goshawk-is-a-major-decision +2024/12/26 16:20:30 Skipping writing post, no content: http://tinylogger.com/max/wnTJ9xu3fw5UiXLp +2024/12/26 16:20:30 Templated 41 posts, took 6.211949ms diff --git a/docs/posts/a-minecraft-server-written-in-cobol.html b/docs/posts/a-minecraft-server-written-in-cobol.html index a1a42475785..b94599be6b1 100644 --- a/docs/posts/a-minecraft-server-written-in-cobol.html +++ b/docs/posts/a-minecraft-server-written-in-cobol.html @@ -34,7 +34,8 @@

    A Minecraft server written in COBOL

  • player inventory (limited to creative mode)
  • chat
  • commands (in-game and via an interactive console)
  • -
  • whitelist (persistent; stored in whitelist.json)
  • +
  • configuration via server.properties
  • +
  • whitelist (persistent; stored in whitelist.json)
  • Note that blocks with multiple states, orientations, or interactive blocks require large amounts of specialized code to make them behave properly, which is way beyond the scope of this project. @@ -64,14 +65,42 @@

    A Minecraft server written in COBOL

    Then execute make to build, followed by make run to start a server on port 25565.

    Or, using Docker:

    -
    docker build -t cobolcraft .
    -docker run --rm -p 25565:25565 -it cobolcraft
    -

    To configure the server, edit the variables in main.cob (limited options available).

    +
    # pull the image from Docker Hub
    +docker pull meyfa/cobolcraft:latest
    +
    +# or build it yourself
    +git clone https://github.com/meyfa/CobolCraft.git cobolcraft && cd cobolcraft
    +docker build --tag meyfa/cobolcraft .
    +
    +docker run --rm --interactive --tty \
    +     --publish 25565:25565 \
    +     --volume "$(pwd)/server.properties:/app/server.properties" \
    +     --volume "$(pwd)/whitelist.json:/app/whitelist.json" \
    +     --volume "$(pwd)/save:/app/save" \
    +    meyfa/cobolcraft
    +

    To configure the server, edit the server.properties file. +This file is generated automatically on first run with default values for all supported options:

    +

    Note: By default, the server is only accessible via localhost (i.e., only on your own system via localhost:25565). To make it accessible from the outside (your local network, via VPN, port forwarding, on a rented server, ...), you can start the Docker container like this:

    -
    docker run --rm -p 0.0.0.0:25565:25565 -it cobolcraft
    +
    docker run --rm -it -p 0.0.0.0:25565:25565 meyfa/cobolcraft

    Well, there are quite a lot of rumors and stigma surrounding COBOL. This intrigued me to find out more about this language, which is best done with some sort of project, in my opinion. diff --git a/docs/posts/a-new-learning-experience-on-mdn.html b/docs/posts/a-new-learning-experience-on-mdn.html deleted file mode 100644 index 166edc59511..00000000000 --- a/docs/posts/a-new-learning-experience-on-mdn.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - James Routley | Feed - - - - Back - Original -

    A new learning experience on MDN

    - -
    A new learning experience on MDN title. Common programming syntax used in CSS, HTML, Bash, and a star. A browser window in the top right with some code and a lightbulb signifying learning.
-

    A major update to the MDN Learn Web Development section started in November 2024 and was finally published in December 2024. -To summarize, the MDN Curriculum has been merged into Learn Web Development. -This post looks at the background leading up to this decision being made, what the changes mean specifically, and what updates you can expect to see in the future.

    Overview of learning material on MDN

    We originally launched the MDN Learn Web Development section in 2016 with the aim of making MDN more accessible to non-experts and helping to take new web developers from "beginner to comfortable".

    -

    The content was pretty successful — by 2019 it was being used by over a million people per month to learn web development topics. -However, it was noted that the structure was sub-par:

    -
      -
    1. The content had become bloated with topics that weren't really suitable for beginner web developers — either they were too advanced, or they were out of scope altogether.
    2. -
    3. Beginners tend to want a robust pathway they can follow to get the knowledge they need, rather than being expected to figure out what to learn and when.
    4. -
    5. Learners these days tend to want interactive multimedia content, not just text.
    6. -

    Developing the MDN curriculum

    To solve the second issue highlighted above, we created a resource to help guide people towards learning a better skillset, making them more employable, and enabling them to build a better, more accessible, more responsible web of tomorrow.

    -

    As part of this project, we did substantial research to find out exactly what skills are seen as essential in new hires, and what the most common knowledge gaps are. -The resulting curriculum was intended to be useful as a study guide for self-learners, and a syllabus for educators to base courses on. -We also used it as a place to experiment with including interactive multimedia content via our learning partner, Scrimba. -We launched the MDN Curriculum in early 2024.

    Why the update?

    The curriculum was well-received by educators, but we quickly received feedback that users found it confusing having two learning resources on MDN, with the curriculum/learning pathway in one place and the learning content in another place.

    -

    In addition, the pathway was just a curriculum; learners still had to figure out what content to look at to achieve the learning objectives. And it did nothing to solve the first issue listed above — the content was still bloated.

    The new state of learning material on MDN

    -

    To provide a less confusing, more streamlined learning experience, we decided to merge the curriculum pathway into the MDN Learn Web Development section, restructuring it in the process. The results can be seen at the following new URL — developer.mozilla.org/docs/Learn_web_development.

    - -

    The most significant changes are as follows:

    -
      -
    • The articles now follow the same structure as the curriculum, with useful background and environment setup information in Getting started, the web fundamentals everyone should know in Core, and optional extra topics in Extensions. There is a clear pathway to follow between each article in the first two major sections, so readers know what to learn next at each stage.
    • -
    • In some cases, content was deemed not suitable for a beginner audience and has been repurposed as extensions/additional articles or migrated to other parts of MDN.
    • -
    • The specific learning outcomes detailed in the curriculum have been added to the top of the Getting started, Core, and some of the Extension articles, to match the learning outcomes detailed in the Curriculum.
    • -
    • Other features from the Curriculum have been migrated across to the Learn Web Development section, such as the About page and Resources for educators.
    • -
    -

    Initially, the Curriculum section will stay, however it will be merged into the Learn area over the next few iterations of this work and will be removed when it is felt the time is right. -We will keep a downloadable version as a resource for educators.

    What's next for learners on MDN

    Moving forward, we will continue to update the content and design to make Learn Web Development even more useful to learners and educators.

    -

    We are intending to give the article content a significant overhaul as we move into 2025. A lot of the content is timeless and does a good job of teaching the fundamentals, but the pacing is uneven, some of the articles are pretty long (which can be intimidating for beginners), and some of the challenges and examples have been around for a long time. Inspired by resources such as the content produced by our learning partner, Scrimba, we intend to shake our content up a bit to make it more fun, bite-size, and digestible.

    -

    We are also looking at improving the design of our learning pages, to echo the bright bold design we used on the curriculum and improve the experience further. -You can expect to see regular iterative improvements going forward, so watch this space.

    Summary

    We hope you find the new Learn Web Development content structure useful — have a look around and let us know what you think.

    -

    If you still have unanswered questions or wish to report issues, please get in touch via the usual communication channels. -If your issue concerns a specific piece of content, you might want to file a GitHub issue.

    Previous Post Countdown to the holidays with daily coding challenges

    - - diff --git a/docs/posts/bad-research-idea-false-statements-in-e-graphs.html b/docs/posts/bad-research-idea-false-statements-in-e-graphs.html index 1e56d99b495..b3732f473b0 100644 --- a/docs/posts/bad-research-idea-false-statements-in-e-graphs.html +++ b/docs/posts/bad-research-idea-false-statements-in-e-graphs.html @@ -23,7 +23,7 @@

    bad research idea: false statements in e-graphs

    OK after much squinting at the progression of rewrite rules... I think I have found an example of where the logic goes wrong.

    Can you spot the error?

    -Screenshot 2024-12-23 at 10 06 52 PM +Screenshot 2024-12-23 at 10 06 52 PM

    The issue here is that the empty int list TupleInt.EMPTY is unified with TupleInt(0, partial(lambda i, self, j: Int.if_(j == self.length(), i, self[j])), 101, TupleInt.empty) aka TupleInt(0, lambda j: Int.if_(j == 0, 101, TupleInt.EMPTY[j])))

    Now let's say we do a naive index the empty list like TupleInt.EMPTY[0]. We could say this incorrect, or how we can represent it is that it unifies with Int.NEVER. But it can show up in the e-graph, because in if_ conditionals, the false branch can end up doing indexing that is not allowed. So we want it to not mess things up.

    And in this case then, it will evaluate to (lambda j: Int.if_(j == 0, 101, TupleInt.EMPTY[j])))(0) which is Int.if_(0 == 0, 101, TupleInt.EMPTY[0])) which is 101... So then what we get is that 101 is unified with Int.NEVER which... isn't good! Is really bad! Because it means all numbers can be unified together basically, i.e. false is true whatever.

    diff --git a/docs/posts/crt-simulation-in-a-gpu-shader-looks-better-than-black-frame-insertion.html b/docs/posts/crt-simulation-in-a-gpu-shader-looks-better-than-black-frame-insertion.html new file mode 100644 index 00000000000..70589ff13ae --- /dev/null +++ b/docs/posts/crt-simulation-in-a-gpu-shader-looks-better-than-black-frame-insertion.html @@ -0,0 +1,63 @@ + + + + + + + James Routley | Feed + + + + Back + Original +

    CRT Simulation in a GPU Shader, Looks Better Than Black Frame Insertion

    + +
    +

    Please enable cookies.

    +
    +

    + +

    You are unable to access blurbusters.com

    +

    + + + +
    +
    +
    +

    Why have I been blocked?

    + +

    This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

    +
    + +
    +

    What can I do to resolve this?

    + +

    You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.

    +
    +
    +
    + +

    + Cloudflare Ray ID: 8f82656f0ecfd6e5 + + + Your IP: + + 20.42.17.70 + + + Performance & security by Cloudflare + +

    + + +
    +
    + + diff --git a/docs/posts/feel-don-t-think.html b/docs/posts/feel-don-t-think.html index d54c7073732..3c72c0c2f06 100644 --- a/docs/posts/feel-don-t-think.html +++ b/docs/posts/feel-don-t-think.html @@ -156,7 +156,7 @@

    Feel, don't think

    If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. - To get new posts and support my work, subscribe to the newsletter. There is also an RSS feed. + To get new posts and support my work, subscribe to the newsletter. There is also an RSS feed.

    diff --git a/docs/posts/macos-menu-bar-app-that-shows-how-full-the-iss-urine-tank-is-in-real-time.html b/docs/posts/macos-menu-bar-app-that-shows-how-full-the-iss-urine-tank-is-in-real-time.html deleted file mode 100644 index ee28fac03db..00000000000 --- a/docs/posts/macos-menu-bar-app-that-shows-how-full-the-iss-urine-tank-is-in-real-time.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - James Routley | Feed - - - - Back - Original -

    macOS menu bar app that shows how full the ISS urine tank is in real time

    - -
    -

    pISSStream is a macOS menu bar app that shows how full the International Space Station's urine tank is in real time:

    -

    -

    Download yours while supplies last!

    -

    Uses NASA's official public ISS telemetry stream, provided by Lightstreamer.

    - -

    When pISSStream can connect to Lightstreamer and the ISS telemetry signal is being received by the ground station, the menu bar item shows 🧑🏽‍🚀🚽 alongside the fill percentage, and the menu simply reads "Connected"

    -

    -

    If either the connection to Lightstreamer or the ISS telemetry signal itself is lost, the menu bar item shows 🧑🏽‍🚀❗and the last received value if any, and the menu reads either "Connection Lost" or "Signal Lost (LOS)":

    -

    - -

    For some inexplicable reason people keep asking me why I (@Jaennaet) did this.

    -

    My motivation was entirely that I thought this was both a hilariously stupid use of a space station's telemetry stream, but also kind of amazing at the same time. It's remarkable that we live in a world where it takes an afternoon to bang out a joke application that reads actual realtime telemetry data from a space station's toilets.

    -

    Also a great excuse to learn Swift, but the sheer ridiculousness was what drove me.

    - -

    Not the epitome of good coding practices since this was my first Swift & macOS app ever, may break in exciting ways at the slightest excuse.

    -
      -
    • shrugs at stale data
    • -
    • not overly bothered with error handling
    • -
    - -

    I found out about the data stream from https://iss-mimic.github.io/Mimic/, which has considerably more and more interesting stats than just how full the piss tank is.

    -

    I will not be adding any of them.

    -
    - - diff --git a/docs/posts/server-sent-events-sse-are-underrated.html b/docs/posts/server-sent-events-sse-are-underrated.html new file mode 100644 index 00000000000..0d929d36265 --- /dev/null +++ b/docs/posts/server-sent-events-sse-are-underrated.html @@ -0,0 +1,308 @@ + + + + + + + James Routley | Feed + + + + Back + Original +

    Server-Sent Events (SSE) Are Underrated

    + +
    + + + + + + + + + +

    + + + +

    + + +

    Most developers know about WebSockets, but Server-Sent Events (SSE) offer a simpler, often overlooked alternative that deserves more attention. Let's explore why this technology is underrated and how it can benefit your applications.

    +

    What are Server-Sent Events?

    SSE establishes a one-way communication channel from server to client over HTTP. Unlike WebSockets' bidirectional connection, SSE maintains an open HTTP connection for server-to-client updates. Think of it as a radio broadcast: the server (station) transmits, and clients (receivers) listen.

    +

    Why are they Underrated?

    Two main factors contribute to SSE's underappreciation:

    +
      +
    1. WebSocket's Popularity: WebSockets' full-duplex communication capabilities often overshadow SSE's simpler approach
    2. +
    3. Perceived Limitations: The unidirectional nature might seem restrictive, though it's often sufficient for many use cases
    4. +
    +

    Key Strengths of SSE

    1. Implementation Simplicity

    SSE leverages standard HTTP protocols, eliminating the complexity of WebSocket connection management.

    +

    2. Infrastructure Compatibility

    SSE works seamlessly with existing HTTP infrastructure:

    + +

    3. Resource Efficiency

    Lower resource consumption compared to WebSockets due to:

    + +

    4. Automatic Reconnection

    Built-in browser support for:

    + +

    5. Clear Semantics

    One-way communication pattern enforces:

    + +

    Practical Applications

    SSE excels in these scenarios:

    +
      +
    1. Real-time News Feeds and Social Updates
    2. +
    3. Stock Tickers and Financial Data
    4. +
    5. Progress Bars and Task Monitoring
    6. +
    7. Server Logs Streaming
    8. +
    9. Collaborative Editing (for updates)
    10. +
    11. Gaming Leaderboards
    12. +
    13. Location Tracking Systems
    14. +
    +

    Implementation Examples

    Server-Side (Flask)

    from flask import Flask, Response, stream_with_context
    +import time
    +import random
    +
    +app = Flask(__name__)
    +
    +def generate_random_data():
    +    while True:
    +        data = f"data: Random value: {random.randint(1, 100)}\n\n"
    +        yield data
    +        time.sleep(1)
    +
    +@app.route('/stream')
    +def stream():
    +    return Response(
    +        stream_with_context(generate_random_data()),
    +        mimetype='text/event-stream'
    +    )
    +
    +if __name__ == '__main__':
    +    app.run(debug=True)
    +
    +

    Client-Side (JavaScript)

    const eventSource = new EventSource("/stream");
    +
    +eventSource.onmessage = function(event) {
    +    const dataDiv = document.getElementById("data");
    +    dataDiv.innerHTML += `<p>${event.data}</p>`;
    +};
    +
    +eventSource.onerror = function(error) {
    +    console.error("SSE error:", error);
    +};
    +
    +

    Code Explanation

    Server-Side Components:

    +

    Client-Side Components:

    +
    +

    Like the article so far? Subscribe to the blog so you don’t miss the next part +

    + +
    +

    Limitations and Considerations

    When implementing SSE, be aware of these constraints:

    +

    1. Unidirectional Communication

    +

    2. Browser Support

    +

    3. Data Format

    +

    Best Practices

      +
    1. Error Handling
    2. +
    +
    eventSource.onerror = function(error) {
    +    if (eventSource.readyState === EventSource.CLOSED) {
    +        console.log("Connection was closed");
    +    }
    +};
    +
    +
      +
    1. Connection Management
    2. +
    +
    // Clean up when done
    +function closeConnection() {
    +    eventSource.close();
    +}
    +
    +
      +
    1. Reconnection Strategy
    2. +
    +
    let retryAttempts = 0;
    +const maxRetries = 5;
    +
    +eventSource.onclose = function() {
    +    if (retryAttempts < maxRetries) {
    +        setTimeout(() => {
    +            // Reconnect logic
    +            retryAttempts++;
    +        }, 1000 * retryAttempts);
    +    }
    +};
    +
    +

    Real-World Example: ChatGPT's Implementation

    Modern Language Learning Models (LLMs) utilize Server-Sent Events (SSE) for streaming responses. Let's explore how these implementations work and what makes them unique.

    +

    The General Pattern

    All major LLM providers implement streaming using a common pattern:

    + +

    Important Note

    While SSE typically works with the browser's EventSource API, LLM implementations can't use this directly because:

    + +

    OpenAI Implementation

    Basic Request Structure

    curl https://api.openai.com/v1/chat/completions \
    +  -H "Content-Type: application/json" \
    +  -H "Authorization: Bearer $OPENAI_API_KEY" \
    +  -d '{
    +    "model": "gpt-4o-mini",
    +    "messages": [{"role": "user", "content": "Hello, world?"}],
    +    "stream": true,
    +    "stream_options": {
    +      "include_usage": true
    +    }
    +  }'
    +
    +

    Response Format

    Each chunk follows this structure:

    +
    "data":{
    +   "id":"chatcmpl-AiT7GQk8zzYSC0Q8UT1pzyRzwxBCN",
    +   "object":"chat.completion.chunk",
    +   "created":1735161718,
    +   "model":"gpt-4o-mini-2024-07-18",
    +   "system_fingerprint":"fp_0aa8d3e20b",
    +   "choices":[
    +      {
    +         "index":0,
    +         "delta":{
    +            "content":"!"
    +         },
    +         "logprobs":null,
    +         "finish_reason":null
    +      }
    +   ],
    +   "usage":null
    +}
    +
    +"data":{
    +   "id":"chatcmpl-AiT7GQk8zzYSC0Q8UT1pzyRzwxBCN",
    +   "object":"chat.completion.chunk",
    +   "created":1735161718,
    +   "model":"gpt-4o-mini-2024-07-18",
    +   "system_fingerprint":"fp_0aa8d3e20b",
    +   "choices":[
    +      {
    +         "index":0,
    +         "delta":{
    +            
    +         },
    +         "logprobs":null,
    +         "finish_reason":"stop"
    +      }
    +   ],
    +   "usage":null
    +}
    +
    +

    Key headers returned by OpenAI:

    +
    HTTP/2 200
    +date: Wed, 25 Dec 2024 21:21:59 GMT
    +content-type: text/event-stream; charset=utf-8
    +access-control-expose-headers: X-Request-ID
    +openai-organization: user-esvzealexvl5nbzmxrismbwf
    +openai-processing-ms: 100
    +openai-version: 2020-10-01
    +x-ratelimit-limit-requests: 10000
    +x-ratelimit-limit-tokens: 200000
    +x-ratelimit-remaining-requests: 9999
    +x-ratelimit-remaining-tokens: 199978
    +x-ratelimit-reset-requests: 8.64s
    +x-ratelimit-reset-tokens: 6ms
    +
    +

    Implementation Details

    Stream Completion

    The stream ends with:

    + +

    Usage Information

    Final message includes token usage:

    +
    "data":{
    +   "id":"chatcmpl-AiT7GQk8zzYSC0Q8UT1pzyRzwxBCN",
    +   "object":"chat.completion.chunk",
    +   "created":1735161718,
    +   "model":"gpt-4o-mini-2024-07-18",
    +   "system_fingerprint":"fp_0aa8d3e20b",
    +   "choices":[
    +      
    +   ],
    +   "usage":{
    +      "prompt_tokens":11,
    +      "completion_tokens":18,
    +      "total_tokens":29,
    +      "prompt_tokens_details":{
    +         "cached_tokens":0,
    +         "audio_tokens":0
    +      },
    +      "completion_tokens_details":{
    +         "reasoning_tokens":0,
    +         "audio_tokens":0,
    +         "accepted_prediction_tokens":0,
    +         "rejected_prediction_tokens":0
    +      }
    +   }
    +}
    +
    +

    Conclusion

    SSE provides an elegant solution for real-time, server-to-client communications. Its simplicity, efficiency, and integration with existing infrastructure make it an excellent choice for many applications. While WebSockets remain valuable for bidirectional communication, SSE offers a more focused and often more appropriate solution for one-way data streaming scenarios.

    + + + + + + +

    + + #webdev + +

    + + + + + + + + + + +
    + + diff --git a/docs/posts/siyuan-privacy-first-self-hosted-personal-knowledge-management-software.html b/docs/posts/siyuan-privacy-first-self-hosted-personal-knowledge-management-software.html index cad8707b485..bbb35e3c7f4 100644 --- a/docs/posts/siyuan-privacy-first-self-hosted-personal-knowledge-management-software.html +++ b/docs/posts/siyuan-privacy-first-self-hosted-personal-knowledge-management-software.html @@ -21,10 +21,10 @@

    Siyuan: Privacy-first, self-hosted personal knowledge management softwareSiYuan

    -中文 | 日本語 +中文 | 日本語


    - +

    Table of Contents


    - +

    💡 Introduction

    SiYuan is a privacy-first personal knowledge management system, support fine-grained block-level reference and Markdown WYSIWYG.

    Welcome to SiYuan English Discussion Forum to learn more.

    feature0.png

    feature51.png

    - +

    🔮 Features

    Most features are free, even for commercial use.