the pipeline from randomly spawning tasks to tree-structured concurrency to actors might be real...
- Pretty permalinks for this post:
- https://fireburn.ru/posts/rust-check-webmention
Here's a short Rust program using the microformats
crate that checks the presence of a webmention on a certain page, properly resolving all URLs and even scanning HTML content in entry["properties"]["content"]
.
use std::cell::{RefCell, Ref};
use std::rc::Rc;
use clap::Parser;
use microformats::types::PropertyValue;
use microformats::html5ever;
use microformats::html5ever::tendril::TendrilSink;
#[derive(thiserror::Error, Debug)]
enum Error {
#[error("http request error: {0}")]
Http(#[from] reqwest::Error),
#[error("microformats error: {0}")]
Microformats(#[from] microformats::Error),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
#[error("url parse error: {0}")]
UrlParse(#[from] url::ParseError),
}
#[derive(Debug)]
enum MentionType {
Reply,
Like,
Repost,
Bookmark,
Mention
}
fn check_mention(document: impl AsRef<str>, base_url: &url::Url, link: &url::Url) -> Result<Option<MentionType>, Error> {
// First, check the document for MF2 markup
let document = microformats::from_html(document.as_ref(), base_url.clone())?;
// Get an iterator of all items
let items_iter = document.items.iter()
.map(AsRef::as_ref)
.map(RefCell::borrow);
for item in items_iter {
let props = item.properties.borrow();
for (prop, interaction_type) in [
("in-reply-to", MentionType::Reply), ("like-of", MentionType::Like),
("bookmark-of", MentionType::Bookmark), ("repost-of", MentionType::Repost)
] {
if let Some(propvals) = props.get(prop) {
for val in propvals {
if let PropertyValue::Url(url) = val {
if url == link {
return Ok(Some(interaction_type))
}
}
}
}
}
// Process `content`
if let Some(PropertyValue::Fragment(content)) = props.get("content")
.map(Vec::as_slice)
.unwrap_or_default()
.first()
{
let root = html5ever::parse_document(html5ever::rcdom::RcDom::default(), Default::default())
.from_utf8()
.one(content.html.to_owned().as_bytes())
.document;
// This is a trick to unwrap recursion into a loop
//
// A list of unprocessed node is made. Then, in each
// iteration, the list is "taken" and replaced with an
// empty list, which is populated with nodes for the next
// iteration of the loop.
//
// Empty list means all nodes were processed.
let mut unprocessed_nodes: Vec<Rc<html5ever::rcdom::Node>> = root.children.borrow().iter().cloned().collect();
while unprocessed_nodes.len() > 0 {
// "Take" the list out of its memory slot, replace it with an empty list
let nodes = std::mem::take(&mut unprocessed_nodes);
for node in nodes.into_iter() {
// Add children nodes to the list for the next iteration
unprocessed_nodes.extend(node.children.borrow().iter().cloned());
if let html5ever::rcdom::NodeData::Element { ref name, ref attrs, .. } = node.data {
// If it's not `<a>`, skip it
if name.local != *"a" { continue; }
for attr in attrs.borrow().iter() {
// if it's not `<a href="...">`, skip it
if attr.name.local != *"href" { continue; }
// Be forgiving in parsing URLs, and resolve them against the base URL
if let Ok(url) = base_url.join(attr.value.as_ref()) {
if &url == link {
return Ok(Some(MentionType::Mention));
}
}
}
}
}
}
}
}
Ok(None)
}
#[derive(Parser, Debug)]
#[clap(
name = "kittybox-check-webmention",
author = "Vika <vika@fireburn.ru>",
version = env!("CARGO_PKG_VERSION"),
about = "Verify an incoming webmention"
)]
struct Args {
#[clap(value_parser)]
url: url::Url,
#[clap(value_parser)]
link: url::Url
}
#[tokio::main]
async fn main() -> Result<(), self::Error> {
let args = Args::parse();
let http: reqwest::Client = {
#[allow(unused_mut)]
let mut builder = reqwest::Client::builder()
.user_agent(concat!(
env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")
));
builder.build().unwrap()
};
let response = http.get(args.url.clone()).send().await?;
let text = response.text().await?;
if let Some(mention_type) = check_mention(text, &args.url, &args.link)? {
println!("{:?}", mention_type);
Ok(())
} else {
std::process::exit(1)
}
}
TIL Postgres can be turned into a job queue: https://www.depesz.com/2014/10/10/waiting-for-9-5-implement-skip-locked-for-row-level-locks/
Might be nice for implementing webmentions in Kittybox.
bluesky is Twitter all over again now, but decentralized and even more chaotic.
And I still don't know half the twitter culture, so I feel lost. And there are already more cultural things like the hellthread? My head is spinning I should probably get breakfast!
- Also published on:
- https://bsky.app/profile/vikanezrimaya.xyz/post/3jy7s7el7wl2u
Assuming the default bluesky feeds are open source, it would be easy to check if posts with links get downranked. This was the case at Twitter before when I was posse-ing β posts with links gained less impressions, and considering my account size, it was pretty much catastrophic.
- Pretty permalinks for this post:
- https://fireburn.ru/posts/i-joined-bluesky
Just managed to join bluesky!
my handle there is @vikanezrimaya.xyz, which also happens to be a domain I own and may migrate to soon!
The domain feature is nice. I wonder if there's a way to bind two domains to a profile π
- Pretty permalinks for this post:
- https://fireburn.ru/posts/kittybox-postgres-experiment-1
Just for fun, I decided to import a subset of my MF2-JSON data into Postgres and see if I can maybe improve Kittybox with it.
CREATE DATABASE mf2_test;
CREATE TABLE vika.mf2_json (url TEXT NOT NULL PRIMARY KEY, mf2 JSONB NOT NULL);
for post in $(ssh root@primrose "ls /persist/containers/kittybox/kittybox/data/fireburn.ru/posts/*.json"); do
json="$(ssh root@primrose cat "$post")"
echo "INSERT INTO vika.mf2_json (url, mf2) VALUES ('$(echo "$json" | jq -r ".properties.uid[]")', '$(echo "$json" | sed -e "s/'/''/g")') ON CONFLICT DO NOTHING;"
done | psql mf2_test --single-transaction
-- See which categories I am using for posts
SELECT DISTINCT jsonb_strip_nulls(jsonb_path_query(mf2['properties']['category'], '$[*]')) #>> '{}' AS tag FROM vika.mf2_json ORDER BY tag ASC;
-- Index the post corpus for full-text search
CREATE INDEX fulltext ON vika.mf2_json USING GIN (to_tsvector('english', mf2['properties']['content'][]));
-- Run a full-text search -- takes 90ms w/o index, 2ms with index!
SELECT url, mf2['properties']['content'][]['value'] FROM mf2_json WHERE to_tsvector('english', mf2['properties']['content'][]) @@ to_tsquery('Kittybox') ORDER BY mf2['properties']['published'][] DESC;
This makes it possible to run a lot of data analysis on posts. Maybe I'll finally have some stuff to populate my widget on the right of the main page with.
Oh, looks like Quill has been updated to indicate other social networks' character limits, because of one particular social network's downfall. Neat.
I don't remember the last time I opened that particular social network though...
Noticed that in Ethereum, major DeFi tokens all correlate to the price of Ethereum, maybe a bit too much. Perhaps that’s why everyone’s calling crypto a Ponzi scheme β how could different assets have such correlation in prices?
I have remembered an old easter egg in my website, and decided to try recreating it using CSS counters, which I have recently learned about. Here’s some CSS:
@counter-style rainbow-hearts {
system: cyclic;
symbols: "β€οΈ" "π§‘" "π" "π" "π" "π";
}
body {
counter-reset: like-icons;
}
span.like-icon::before {
counter-increment: like-icons;
content: "" counter(like-icons, rainbow-hearts);
}
span.like-icon-label {
display: none;
}
Using it with the following HTML will do the trick:
<span class="like-icon" aria-label="liked"><span class="like-icon-label" aria-hidden="true">β€οΈ</span></span>
I tried to make it compatible with screen readers and allow for a fallback icons for browsers not supporting counters (apparently text browsers don’t do a lot of CSS). This also means the CSS snippet can be excluded from the CSS sent to the browser if you don’t like having fun.
Are cars even worth it if they move slower than pedestrians? I ordered a taxi and the amount of time I spent waiting for it and the amount of time I will spend inside the car could’ve gotten me to my destination on foot, if not for the damn ice on the sidewalks that nobody cares to break...
Because the city only cares about cars and car owners. And pedestrians are always treated as second-class citizens...
I want to be free from the confines of this hyper-capitalist world we are living in.
I want to see the Internet that I never got to see β an open, free ecosystem run by enthusiasts from their closets.
I wonder what would be of it in our current highspeed era if it were not killed by corporations and silos.
Perhaps we would have something absolutely beautiful on our hands. Perhaps...we could still have it?
The word "sensitive content" makes me want to destroy this world because usually it gets applied by social networking silos to anything that is not capitalist-praising distilled fake-smile covered in glitter simulacrum and usually is an excuse to non-transparently suppress content undesirable to capitalists.
Kitty!!!
I often forget that my new authentication system has short-lived tokens that live a week, and long-term refresh tokens that last up to two months.
And Quill doesn’t seem to use refresh tokens...
One last thing remains. Moving to a new domain. Soonβ’
I just need to rent a cloud server, because I am literally hosting this server under my bed, and it might be dangerous now.
I’ve put a HTTP 451 page on my website in response to my country’s prohibition on LGBTQ+ content. Since I am transgender, publicizing the fact of my own existence is now quite literally illegal.
Fuck Russia.
A certain comment on Hacker News perfectly conveys how I see all financial systems and crypto, and seem so skeptical about the high price of Ethereum.
The US dollar is a medium of exchange, not an asset or an investment. You use dollars to buy things, you don’t own dollars just to own dollars.
Same could be said about cryptocurrency, about sticks and stones and even squirrel pelts (that were used as a currency in ancient times, if my memory serves me).
And this is why I am so annoyed with cryptobros and venture capitalists who dabble in cryptocurrencies β they view what should be a medium of exchange as an investment platform, resulting in the blockchain getting cramped.
I’m so grateful for the FTX crash right now. I hope it would scare capitalist leeches off.
Some governments are afraid of cryptocurrency, even though it is not anonymous (despite some claims by uneducated individuals) and very traceable -- even more so than physical money or bank accounts. I wonder, why... maybe they themselves do something illegal?
I need some sleep...