Fork me on GitHub
#off-topic
<
2022-03-15
>
Stuart11:03:40

Is it normal for sites to work if you have www. and be broken if you don't have www. ? Surprised I'm tried to access a large companies site (http://iwc.com) and it didn't work, but it works if I typed in http://www.iwc.com I always just assumed browsers would append the www bit, if I didn't type it.

Wanja Hentze14:03:06

Modern websites usually have both domain names and redirect one towards the other. The question is which one is the cannonical form 😄 There are arguments to be made for either, see http://no-www.org and https://www.yes-www.org.

Dimitar Uzunov18:03:55

It is normally handled by a server side redirect (the web server for one does a 302 redirect to the other). Since the redirect response is an empty body it looks as if the browser did it

gklijs20:03:06

Funny, I recently also ran into this, as I wanted to know which social platform was used just by looking at the first part of the url. Where some do and some don't use www.

manutter5111:03:21

I think most places just register both domain names (i.e. with and without the www.) to point to the same host. The browser does not automatically add it.

Thomas12:03:31

answers with a 301 to redirect to (can be seen using curl -v)

Stuart13:03:19

hmmm.. maybe one of my extensions blocks redirects then.

dgb2312:03:55

Technically you have to think of www as being an arbitrary subdomain which may or may not point to the same address. It is common to do so and then redirect either from the www subdomain or to the www subdomain, depending on whether it is the canonical url for a given site.

dgb2312:03:04

The redirect is issues by the webserver. The browser just reacts to it. There might be multiple (quasi partial) redirects being issues but handled internally to the webserver until it tells the browser where to go. If you open the network tab in the browser you can see that the mentioned site redirects from http to https as well:

Stuart13:03:02

I must have an extension stopping this from working. http://iwc.com just gives me

p-himik13:03:51

Same IP does not mean "handle in the same way". The server, while itself being the same, will distinguish between and .

p-himik13:03:06

Also, the server can pay attention to a lot of other things. Your IP's location, your browser, even your screen size (I think).

dgb2312:03:41

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections (Sidenote: Here they don’t talk much about 304 which is a bit of an underused response IMO.)

orestis15:03:32

622883673e74770430283014 is both a valid Mongo BSON ObjectID, and a "valid" JS number.

> JSON.parse('622883673e74770430283014')
Infinity
Don't ask me how we know 🙂

😬 2
😂 3
p-himik15:03:02

This post feels like the perfect recollection of the ethos of the "we should've switched to PostgreSQL sooner" kind of articles. :D

slipset18:03:46

Trust me, it’s quite an undertaking…

orestis18:03:44

We've embarked :)

slipset18:03:53

So have we…

orestis18:03:58

Perhaps we should compare notes @U04V5VAUN - were only reading so far, writes go to mongo, as we have a legacy Node app that reads from that.

orestis18:03:08

With a continuous process that updates Postgres so that everything is eventually synced.

mjw19:03:51

Ha! 622883673 x e^74770430283014 :rolling_on_the_floor_laughing:

noisesmith19:03:06

I'm going to start linking this tweet in commit messages when fixing egregiously stupid bugs

Nundrum22:03:07

What do you do when the problem you want to solve is beyond your capabilities?

Cora (she/her)22:03:47

ask for help 🙂

upvote 1
p-himik22:03:30

• Make the problem less hard • Improve your capabilities • Make it someone else's problem (asking for help, delegating) • Decide it's not a problem. :D (those are options, and not a TODO list)

Nundrum22:03:25

This is a carryover from #clojure-art I'm trying to get the capability to draw in a given X11 window with any Clojure library. The problem cuts from from Xlib up to AWT and on into Java2d|Clojure2D|Java-Gnome|Swing|Seesaw. There don't seem to be places to ask about AWT. I can't figure out how to make this less hard.

p-himik22:03:41

> I'm trying to get the capability to draw in a given X11 window with any Clojure library So that's how you have defined your problem. But why? From your messages in #clojure-art, it seems to me that you want to be able to write X11 and/or Wayland screensavers in Clojure. That might be quite a bit different problem.

Nundrum01:03:17

Not too hard to do in C or Rust. But getting that capability exposed in Java is a deep dive into old code.

phronmophobic03:03:56

I'm not sure what API you're trying to use, but it's often easier to directly wrap C libraries using ffi libraries like clojure-jna or dtype-next than it is to use Java libraries that wrap C code.

p-himik07:03:12

If seems that you can use xephyr for that: https://stackoverflow.com/questions/1124997/is-there-any-way-to-run-an-application-as-a-screensaver-in-linux As an alternative, this is how Python does it - without having to go down all the way to the C level. Perhaps there's a wrapper for GTK libraries for Java that you could use in the same way. https://alvinalexander.com/python/python-screensaver-xscreensaver-linux/

🤯 1
Nundrum14:03:52

I was hoping I could just expose the existing Xlib functions through AWT or Swing or Java-Gnome. There was a project years ago called SaverBeans that seems to use libMotif to make the magic happen.

Nundrum14:03:15

xephy is a crazy option. I'll have to play with that.

noisesmith18:03:47

> expose the existing Xlib functions through AWT or Swing or Java-Gnome My understanding is that the point of AWT / Swing are to abstract away (remove) any differences between windowing systems on various OS. X11 is notoriously difficult / weird (it's a design from the '80s, when programming practices were radically different, and adapted to constraints we don't deal with in desktop apps today). If you want to learn to use X11, I think the best resources are elderly programmers who hang out on IRC.

noisesmith18:03:41

I've used Xephyr before - it makes load / reload workflows when writing X11 apps (especially window managers and screen savers) much easier.

👍 1
Nundrum18:03:57

I thought the point was more to make a common cross-platform capable library. Not to hide capabilities? My problem isn't the X11 part, it's the "make this work with Java" part. I've already written enough X11 in C to be reasonably comfortable with it.

Nundrum18:03:54

Even with Rust it requires some patching of the lower level libraries to get the root window.

phronmophobic19:03:18

If you're comfortable with C, then it's really worth checking out c ffi libraries like dtype-next and clojure-jna. You can write a small c wrapper that is easy to call from clojure.

Nundrum19:03:58

Do you think I can then somehow make the leap from there to making it work with Clojure2d? I expect that if I have to work at the JNA level, I would also have to re-implement everything from there up.

phronmophobic19:03:14

> Do you think I can then somehow make the leap from there to making it work with Clojure2d? Yes. I've implemented graphics for most of the 2d stuff like shapes, text, images, fills, paths, transforms, etc using Swing, JavaFx, Skia, and Skija on the clojure side, so it's definitely possible. They can all render to several raster formats so I assume that one of them should match what Xlib expects. I'd be happy to answer any questions.

phronmophobic19:03:31

If you want examples, then you can look at the corresponding namespaces in https://github.com/phronmophobic/membrane/tree/master/src/membrane: cljfx, java2d, skia, skija.

Nundrum19:03:15

I guess I don't understand. It looks like you're using AWT. But I what I would need to do is use JNA to get the root window reference and somehow coerce AWT to use that?

phronmophobic19:03:22

I'm not actually sure what xlib or xscreensaver expects, but I assume there's at least some way to draw a bitmap image. So the most basic plan would be to use clojure to draw into a buffer using a bitmap image format that xlib understands and then export a c function accessible via jna that can render that buffer. There's probably even fancier ways to do that.

phronmophobic19:03:53

It looks like there's a way to use opengl with xscreensaver. I know that skia can render using openGL as well as libraries like lwjgl.

Nundrum20:03:28

My expectation is that if I can get a handle to the window and a graphics context, I can draw on that window with that GC.

Nundrum20:03:49

But without a GC in that window, I don't think there's a way to even render a buffer/bitmap to it.

Nundrum20:03:15

And with OpenGL there would be the same problem - getting a handle to the correct window.

phronmophobic20:03:13

Right, that's where c ffi libraries come in. You either call xscreensaver directly or you write a small c wrapper, build a shared library, and expose whatever functionality you need that way.

phronmophobic20:03:10

That's essentially what any java library would do anyways.

Nundrum21:03:34

There's still some misunderstanding here. Nothing calls xscreensaver, not even the xscreensaver hacks themselves. There's no xscreensaver API to call.

Nundrum21:03:02

The hacks are just GUI programs that grab the root window and draw on it.

phronmophobic21:03:18

Ok, same deal. Either setup the opengl context via direct ffi calls or write a small c wrapper that sets up the opengl context and expose it for clojure to call via ffi.

Nundrum22:03:10

Thank you for trying. I still don't understand how to cross the bridge between ffi and java2d. Which I suppose is my lack of understanding what JNA would do for me?

phronmophobic22:03:19

JNA (Java Native Interface) is an ffi (Foreign Function Interface) option that allows java/clojure to call c functions and expose functions that can be called from c code.

Nundrum00:03:10

Those words strung together make sense 😉 I could call XtAppInitialize[1], then maybe XGetWindowAttributes[2] and get a pointer to a C struct representing the window I need to work on. But then I don't see a way to inform AWT or Java2D or openGL about what has happened. That's my hangup. Copying over pixmaps through ffi would work, but would also be really ugly when it comes to animation. 1: https://linux.die.net/man/3/xtappinitialize 2: https://tronche.com/gui/x/xlib/window-information/XGetWindowAttributes.html

phronmophobic00:03:30

There's more than one way to do it, but I'm assuming it's easier to adapt a working sample by using a setup similar to the following: 1. Expose a clojure function, drawMyScreenSaver as a c entry point that receives any necessary graphics context info as arguments and draws whatever you want to draw 2. Expose a c function, runMyScreenSaver, that you can call from clojure that creates the window, creates the graphics context, runs the graphics loop that calls your exposed clojure draw function 3. When your clojure programs starts, create a new OS thread that calls the exposed c function runMyScreenSaver > Copying over pixmaps through ffi would work, but would also be really ugly when it comes to animation You can just past raw pointers to memory. You shouldn't have to copy buffers.

1
thinking-face 1
Nundrum03:03:25

Are there docs for clojure-jna hiding somewhere? Maybe it's awesome, but the only example the project gives is calling printf.

phronmophobic06:03:38

clojure-jna is mostly just a light wrapper for JNA, so you may need to refer to JNA's docs to get a complete picture, https://github.com/java-native-access/jna

phronmophobic06:03:19

If you'd like an alternative, I highly recommend https://github.com/cnuernber/dtype-next/. I think the ramp up for dtype-next is a little steeper, but it's a highly capable library.