Live data from Hacker News

Ask HN: What novel tools are you using to write web sites/apps?

news.ycombinator.com

261–270 of 333 posts

Re: Ask HN: What novel tools are you using to write web sites/apps?

#261
I don’t do much on the apps/websites side of things. I’m a platform and systems developer by experience/preference.

That said, I’ve long maintained a blog. I prefer to build my own tools. I wrote a highly opinionated static site generator in Go over the course of the few evenings during March.

I used to use Ghost to host the blog on DigitalOcean but got tired of chasing NPM updates. I got a small VPS instead, installed OpenBSD, and now the site runs off relayd+httpd. relayd handles setting caching headers. httpd handles serving of HTML.

It’s working really nicely. If I didn’t use IBM Plex Sans as a font, my site would easily join the lists like 10kb club. I do set the caching header for it though.

Other than that, I’ve got a couple of side projects I’ve been noodling on. Back end will probably be Go. Front end app will likely be PHP/Laravel. PHP 7+ has been really nice to work with and it runs well on OpenBSD. If it ever got popular enough, shifting to elastic deployments with Docker/LXC/Podman would be straightforward.

Re: Ask HN: What novel tools are you using to write web sites/apps?

#262

This partially might be more of a what's old is new again, but here's what I use: - 100% server side rendered - Progressively enhanced (fully works without JS, but having JS enabled makes it nicer) - In select places where I need SPA-like snappiness I use a ~100 line long DOM diffing algorithm (I request full HTML through AJAX and diff it into the current page; if the user has no JS enabled then the page just refresh…

Which Rust templating tools are you using for server side HTML rendering?

I have my own crate for template rendering. I tried various existing ones but I ended up not liking any of them for one reason or another, so I've made my own.

Some of the features are:

* Fully static. It's compiled into Rust code instead of being dynamic. (I wanted to be able to use normal Rust code in my templates instead of a special template-only language, and I wanted the extra speed.)

* Built-in automatic HTML whitespace minification at compile time.

* Built-in XSS-safe string interpolation. You have to explicitly use the unsafe raw interpolation.

* It can interpolate any Rust value which implements the `Display` trait.

* Doesn't use Jinja's syntax.

* Doesn't have any extra unnecessary dependencies.

* Doesn't use inheritance for template composition, instead it uses simple textual inclusion plus late binding to achieve composition. Since it's hard to explain let me give a simple example. Let's assume I have a skeleton.html which looks like this:

    
    
        
    
    
        ~~ @paste body
    
    
And now I have index.html which is the actual template I render, and it looks like this:

    ~~ @include "skeleton.html"
    ~~ @snippet title
        Index
    ~~ @end
    ~~ @snippet body
        Hello world!
    ~~ @end
As you can see I first include the skeleton.html, and then I define the "title" and the "body" snippets after the skeleton has already pasted them. Normally this wouldn't work, but since the `@paste` directive is lazy it only gets resolved once the whole template is processed.

This makes it really simple to customize the templates, since you can just add `@paste`s wherever you'd like to have a customization point, and you don't have to think about doing things in the right order since the templating engine will take care of it for you.

(If you forget to define a snippet that was `@paste`d you'll get a compile time error; I also have other directives that allow you to set a default if there was no snippet defined.)

Re: Ask HN: What novel tools are you using to write web sites/apps?

#263
post #236

Earlier quoted context omitted.

Yeah, this seems problematic. What if you hard power off your server, how do you know your data didn't get corrupted? As someone who has written databases, and knows how difficult this is to get right, it makes my skin crawl. Backups and restore will also have to be DIY. Point in time restore probably won't be possible - and that's a life saver when you need it.

> What if you hard power off your server, how do you know your data didn't get corrupted? Atomically replacing the whole file instead of updating the data in-place, and using a checksumming filesystem like ZFS should give you such guarantee, no? > Backups and restore will also have to be DIY. Well, yeah. A daily cron job that `scp`s the data to an offsite location. Personally I don't really see much problem with that…

> Atomically replacing the whole file instead of updating the data in-place, and using a checksumming filesystem like ZFS should give you such guarantee, no?

No. You need to use fsync to ensure the file is flushed to disk. Also careful not to rename the file across mount points (/tmp is often a different mount and the most common location for people trying this.)

> Well, yeah. A daily cron job that `scp`s the data to an offsite location. Personally I don't really see much problem with that? It's easy to backup, and easy to restore.

That's fine, but your backup and restore granularity is daily. If you introduce a bug that writes the wrong / partial data, you can't recover anything that isn't in the previous day's backup.

With a typical database you have a transaction log and you could restore back to any point during the day.

This has been necessary about a dozen times during my career (once every two years or so on average.)

Re: Ask HN: What novel tools are you using to write web sites/apps?

#264

Earlier quoted context omitted.

> flush to disk periodically How do you protect yourself against incomplete writes? What about when there's a critical update that you don't want lost? I've done similar stuff in the past, but I handled things slightly differently. For tiny data structures I just spat out a short XML file. For larger data structures I synchronized all changes with a SQLite database.

> How do you protect yourself against incomplete writes? I don't update files on disk in-place. I write to a new file, and once it's done I do an atomic move and replace the old file with the new one. > What about when there's a critical update that you don't want lost? I immediately write it to the disk? (: I don't think it's possible to completely avoid this problem. In a traditional database if you suddenly lose p…

I like the approach of tailoring the app to the use case, so I'm not arguing you should do something differently.

The database has commit for exactly this reason. If you lose power, you will not acknowledge the commit to the client, so the client may retry. For example, the end user may get an error page. This is different from a case when the app would show modified values, but the next day, the modifications would be gone.

With the database, you still have the problem, that after a user sees an error, the transaction might have suceeded. Eg if connection drops at the moment when the DB receives the commit command.

Re: Ask HN: What novel tools are you using to write web sites/apps?

#266
post #263

Earlier quoted context omitted.

> What if you hard power off your server, how do you know your data didn't get corrupted? Atomically replacing the whole file instead of updating the data in-place, and using a checksumming filesystem like ZFS should give you such guarantee, no? > Backups and restore will also have to be DIY. Well, yeah. A daily cron job that `scp`s the data to an offsite location. Personally I don't really see much problem with that…

> Atomically replacing the whole file instead of updating the data in-place, and using a checksumming filesystem like ZFS should give you such guarantee, no? No. You need to use fsync to ensure the file is flushed to disk. Also careful not to rename the file across mount points (/tmp is often a different mount and the most common location for people trying this.) > Well, yeah. A daily cron job that `scp`s the data to…

> No. You need to use fsync to ensure the file is flushed to disk.

Are you sure? At least in case of ZFS AFAIK the file wouldn't get corrupted, since it uses copy-on-write internally. Sure, you might get the old data back, but you wouldn't get corruption. And it automatically checksums your files anyway so it will detect any data that did get corrupted, and if you're using RAID-1 (as you should for any important data) it will automatically repair it.

> Also careful not to rename the file across mount points (/tmp is often a different mount and the most common location for people trying this.)

You can't rename across mount points. (Linux's `rename` syscall and the corresponding C API will return an EXDEV error if you try.)

> If you introduce a bug that writes the wrong / partial data, you can't recover anything that isn't in the previous day's backup.

Sure. If I was working in a bank not being able to do that would be totally unacceptable. But in my case that's the tradeoff I'm willing to live with.

Post reply on HN