This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-12
Channels
- # adventofcode (42)
- # aleph (10)
- # announcements (1)
- # asami (138)
- # babashka (7)
- # beginners (7)
- # biff (13)
- # cider (7)
- # clj-kondo (15)
- # clojure (53)
- # clojure-austin (11)
- # clojure-belgium (2)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (55)
- # clojure-sweden (5)
- # clojure-uk (4)
- # cryogen (7)
- # cursive (63)
- # datomic (5)
- # eastwood (6)
- # emacs (31)
- # fulcro (7)
- # hyperfiddle (9)
- # introduce-yourself (3)
- # java (11)
- # lsp (10)
- # malli (14)
- # membrane (35)
- # off-topic (13)
- # portal (12)
- # prelude (1)
- # releases (2)
- # ring-swagger (27)
- # shadow-cljs (8)
- # timbre (25)
Is this a bug, or am I doing something wrong:
(def beatings-data
(let [root 200]
(->> (combo/combinations
[67/64
279/256
9/8
75/64
39/32
5/4]
2)
(mapcat (fn [[a b]]
(let [harmonics (range 1 4)]
(for [[h1 h1*] (map (fn [h] [h (* a h)]) harmonics)
[h2 h2*] (map (fn [h] [h (* b h)]) harmonics)]
(let [diff (* root (abs (- h1* h2*)))]
{:pair [a b]
:harmonics [h1 h2]
:diff [diff (float diff)]})))))
(filter #(> 20 (first (:diff %))))
(group-by :diff))))
(keys beatings-data) ;; [25/2 12.5] is clearly a key
(get beatings-data [25/2 12.5]) ;; => nil
Works fine when passing the a smaller vector to combo/combinations
, like:
[39/32 5/4]
In this case the issue is clojure floating point literals are doubles and you are coercing to floats
oh I see
thanks!
But why does it work with a small map?
It isn't, the key you claim to be working with the small map is a pair of ratios, which could not be produced by the code you shared
yeah, I meant the pair as input
When using a library, there’s often this image link to clojars. I’ve seen them in a lot of libs readme’s. What is it that generates it? And if it’s generated automatically, would it be a bad idea to have it create something with copyable text? Ideally with the tools.deps and lein style links?
Yeah, I find it frustrating as well. Being able to copy the text without having to go to Clojars would be nice.
The image is generated with this Markdown in the README: [![Clojars Project](
.
In the end, it's a trade-off between the convenience of end users and keeping the info in sync + the convenience of the devs. AFAIK, embedding images is the only that you can add some always up-to-date information to your README on GitHub without having to do any automation.
Ah yeah, you’re right, Github only allows embedding images. Just a small little frustration but sounds like it’s here to stay
unless…. https://webmasters.stackexchange.com/questions/13802/is-text-in-svg-selectable-copyable-in-browsers
oh it’s already an svg derp
Looks like a security feature on github’s side, to stop xss attacks from svg
Yeah, that was the idea; to have selectable text in an SVG. But GitHub does something to prevent it from being selectable. If you load the image (via their proxy) directly, you can select the text: https://camo.githubusercontent.com/615c0a94877758b800a2a85b020a4d538edb49ca99e193c86f0ce94322c35861/687474703a2f2f636c6f6a6172732e6f72672f6d65746f73696e2f6d616c6c692f6c61746573742d76657273696f6e2e737667
I honestly don't understand why people use this image. It's terrible for every user, and it saves you "the work" of replacing three characters when you make a release. How one can consider that a good trade-off is beyond me.
I believe it is used because we used to advertise it on Clojars as copyable (and, when rendered there, it was selectable). We no longer advertise that version of the badge, and just have http://shields.io badges, which aren't selectable:
Just wrote this userscript, it might ask you to access a couple of Clojars URLs when triggered for the first time.
// ==UserScript==
// @name Selectable Clojars coords
// @namespace
// @version 2023-12-12
// @description Make Clojars dep coordinates on GitHub selectable
// @author p-himik
// @match
// @icon
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
for (let img of document.querySelectorAll('a[href*="://clojars.org/"] > img[data-canonical-src$=".svg"]')) {
const svgPath = img.dataset.canonicalSrc;
// Capturing `img`, needed due to lexical scoping of closures.
const onload = ((img) => (response) => {
const txt = response.responseText;
if (txt) {
if (txt.toLowerCase().startsWith('<svg')) {
img.parentNode.outerHTML = txt;
} else if (txt.startsWith('<?xml')) {
const parser = new DOMParser();
const doc = parser.parseFromString(txt, 'application/xml');
const svg = doc.querySelector('svg');
if (svg) {
img.parentNode.outerHTML = svg.outerHTML;
}
}
}
})(img);
GM.xmlHttpRequest({method: 'GET',
url: svgPath,
onload: onload});
}
})();
Then you'll be able to triple-click any Clojars banner and select all the text in it since it'll be a regular SVG and not an IMG.
Oh my, I was the original author of this badge, you can direct your hate towards me 😅.
@U9MKYDN4Q I mean, it is a one extra click for the user vs additional action for the maintainer? And also the one that is easy to overlook? Seems like an acceptable trade-off to me.
Depending on how many installs you have it's thousands of extra clicks to save the maintainer three seconds when making a release. I never use it on any of my projects.
Oh cool, this user script could be a useful idea @U2FRKM4TW
@U06PNK4HG no hate from my end, was just curious about whether it’s possible to have something selectable, and wondering what the constraints were. Seems to be a github security issue, and I think @U2FRKM4TW’s solution is something that could be helpful,
I use tools.deps more these days anyway, so might need to modify it a bit, but I think the principle could still work - add some extension to the browser that changes these images
No, it's fine, I also hate that it can't be selected. I spent some time back in the day to figure out if it can be made selectable, since this is indeed just a Github restriction, it works for plain SVG
Sometimes, I put this badge alongside the selectable plain text like [
, so that the user can copy the artifact ID but then fill the version manually taken from the badge. But I'm not sure if that's helping much.
And since now there are two syntaxis for a dependency, I treat this badge just as an ad for Clojars that the user can click and copy what they actually need.
Yeah, I'll definitely improve upon that userscript to let a user copy the coords with the desired syntax without having to go to a separate page. :D
Hi all. Would you say there is any inconvenience naming a function starting with "def" as in "deflate" or "define"? My editor highlights it as a special form but other than that, it works fine.
Sounds like a bug in your editor -- what are you using?
i think emacs tooling is a bit loose/lax on things that start with def. But nothing the actual language cares about
We have lots of functions in our codebase at work that start with def
.
VS Code/Calva/LSP doesn't flag them. I'd have to ask my colleague whether his Emacs setup flags them... @U0NCTKEV8?
you are likely not just using clojure-mode, but clojure-mode with cider and maybe some language server mode, both of which effect highlighting (I am not using cider, but I am using eglot with clojure-lsp)