nmtake

joined 2 years ago
[–] nmtake@lemm.ee 4 points 1 year ago

I prefer high-contrast themes these days and modus-themes work great. Note that Emacs 29 doesn't contain newer themes like modus-vivendi-tinted.

[–] nmtake@lemm.ee 3 points 1 year ago

Oh I didn't know the book is freely available under the CC license; I bought the Japanese translated version just a week ago. The book is quite difficult for me but the first chapter was very good read.

[–] nmtake@lemm.ee 2 points 2 years ago (1 children)

Oh I was completely wrong. cmp() takes a number (not Ordering) and returns Ordering. Sorry for bothering you.

[–] nmtake@lemm.ee 2 points 2 years ago (3 children)

The Enum Ordering provides compile-time safety. For example, if cmp() takes a string or int, the compiler can't catch invalid inputs ("less", "equal", -123, ...) at compile time and crash at runtime.

[–] nmtake@lemm.ee 2 points 2 years ago

I think it's a really good candidate for code reading for understanding how Lemmy API client works. I'd try to write some toy program with the crate in this week.

[–] nmtake@lemm.ee 1 points 2 years ago* (last edited 2 years ago)

As you said, GET /resolove_object (https://join-lemmy.org/api/interfaces/ResolveObject.html) may work:

$ post_id=9589178
$ curl 'https://lemm.ee/api/v3/resolve_object?q=https%3A%2F%2Fprogramming.dev%2Fpost%2F%24%7Bpost_id%7D' | jq .post.post.id
22873872
$ curl 'https://lemm.ee/api/v3/post?id=22873872' | jq '.post_view.post | [.id, .name]'
[
  22873872,
  "How do you get the url or id of the same post on a different instance?"
]
[–] nmtake@lemm.ee 3 points 2 years ago* (last edited 2 years ago)

I think you're right. In CGI, web server spawns a process for each incoming request to the CGI app, so the author provide static files for visitors to reduce the overhead.

Edit: here is the repository: https://codeberg.org/seppo/seppo and written in OCaml, so the single file CGI app is a compiled binary.

[–] nmtake@lemm.ee 3 points 2 years ago (1 children)

Hosting Lemmy instances on a localhost has these advantages: 1) no TLS required (right?), 2) can sniff the network traffic between the instances, 3) can change codes and settings of the all instances without asking to anyone, and more importantly, 4) no maintance cost. But if someone want to learn Web app deployment (TLS certs, hosting, etc.), your option would be a good idea.

[–] nmtake@lemm.ee 4 points 2 years ago (3 children)

For learning real Lemmy stuff, I'd run multiple Lemmy instances on LAN without internet connection to ensure the testing won't pollute the fediverse.

[–] nmtake@lemm.ee 3 points 2 years ago* (last edited 2 years ago)

Hi, thanks for setting up this community. I'm not a Lemmy source contributer but I like to read open sources. Here is a very simplified web application (including Lemmy) architecture overview and I hope this text helps for some newbies:

  1. A user agent (web browser, mobile app, etc.) sends an HTTP request to a Lemmy instance.
  2. The lemmy instance examines the HTTP request and dispatches the request to a relevant function called controller. The mapping from a path in the URL to a function is called a router - see https://github.com/LemmyNet/lemmy/blob/0.19.3/src/api_routes_http.rs for example.
  3. The controller makes an HTTP response for the request and returns it to the user agent.
  4. The user agent displays the returned response to the user.

To find an controller from a path in the router, just grep (or a similar search function you use) the Lemmy source. For example, if I want to know how GET /user/export_settings works, I'll run these commands:

$ git clone https://github.com/LemmyNet/lemmy/  # if you haven't download the source yet
$ cd lemmy
$ rg export_settings
src/api_routes_http.rs
131:  user_settings_backup::{export_settings, import_settings},
274:        web::resource("/user/export_settings")
276:          .route(web::get().to(export_settings)),

crates/apub/src/api/user_settings_backup.rs
68:pub async fn export_settings(
301:  use crate::api::user_settings_backup::{export_settings, import_settings};
366:    let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
402:    let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;

So we got the relevant route and the controller definitions very quickly. Settings to be exported are defined as a struct UserSettingsBackup. The controller is defined as pub async fn export_settings and it converts the struct to a JSON.

Rust might not be a easy programming language but the official text (calld The Book is very friendly for newbies, so don't hesitate to read and to write a simple program like guessing game.

[–] nmtake@lemm.ee 4 points 2 years ago

Have you checked the shell command history? (e.g, history | grep spotify)

view more: ‹ prev next ›