Fork me on GitHub
#off-topic
<
2022-04-21
>
Stuart09:04:48

I just don't get some peoples of way of thinking. In this system the user can select some pre-defined date ranges, they each are represented by an integer. 4 Hours = 11 6 Hours = 12 12 Hours = 13 24 Hours = 6 3 Days = 23 7 Days = 27 30 Days = 29 Every single I have to refer to my notes on what TimePeriodId is what range.

wow 1
😱 2
πŸ™€ 2
πŸ™ƒ 2
2
p-himik09:04:38

One possible reason - the periods have been added one by one, and a new one gets an incremental ID.

pavlosmelissinos10:04:06

I'd definitely write a function (a map really) from id to time range (and perhaps vice versa) if I had to deal with this a lot, even if it was just for me.

βž• 3
dgb2313:04:42

looks like the writer is thinking in enums here

dgb2313:04:59

(not the nice kind of enums)

πŸ˜† 2
emccue14:04:16

it makes perfect sense

emccue14:04:22

11 = 1 + 1 = 2, but there are two ones in there so 2 * (1 + 1) = 4 12 = (1 + 1) + (2 * 2) = 6 13 = (1 + 1 + 1) + (3 * 3) = 12 6 = (6 * 6) - (6 + 6) = 24

πŸ˜… 3
emccue14:04:52

the others are in days so that changes the game

emccue14:04:05

23 = 2(3) = 3 27 = 2(7) = 7 29 = 2(9) = 9, but in base 8 we carry = (2 + 1) (9 - 1) = 30

emccue14:04:13

you dont need your notes if you write a function to do the translation

Stuart14:04:45

I feel foolish for not even seeing that.

πŸ˜‚ 5
emccue14:04:05

heres the first direction

emccue14:04:07

(defn from-time-period-id [n]
  (let [digits (map str (str n))]
    (cond
      (= 1 (count digits))
      {:hours (- (* n
                    n)
                 (+ n
                    n))}

      (= (first digits) (second digits))
      {:hours (* (+ (parse-long (first digits))
                    (parse-long (second digits)))
                 (+ (parse-long (first digits))
                    (parse-long (second digits))))}

      (= "1" (first digits))
      {:hours (+ (apply + (map parse-long (repeat (parse-long (second digits))
                                                  "1")))
                 (* (parse-long (second digits))
                    (parse-long (second digits))))}

      :else
      {:days (if (= (parse-long (second digits)) 9)
               (parse-long (str (inc (parse-long (first digits))) 0))
               (parse-long (second digits)))})))

emccue14:04:46

(from-time-period-id 11)
=> {:hours 4}
(from-time-period-id 12)
=> {:hours 6}
(from-time-period-id 13)
=> {:hours 12}
(from-time-period-id 6)
=> {:hours 24}
(from-time-period-id 23)
=> {:days 3}
(from-time-period-id 27)
=> {:days 7}
(from-time-period-id 29)
=> {:days 30}

emccue14:04:15

(defn to-time-period-id
  [n]
  (loop [i 0]
    (if (= (from-time-period-id i) n)
      i 
      (recur (inc i)))))
=> #'user/to-time-period-id
(to-time-period-id {:hours 4})
=> 11
(to-time-period-id {:hours 6})
=> 12
(to-time-period-id {:hours 12})
=> 13
(to-time-period-id {:hours 24})
=> 6
(to-time-period-id {:days 3})
=> 23
(to-time-period-id {:days 7})
=> 27
(to-time-period-id {:days 30})
=> 29

emccue14:04:51

and in case anyone wants the full pattern

emccue14:04:25

([0 {:hours 0}]
 [1 {:hours -1}]
 [2 {:hours 0}]
 [3 {:hours 3}]
 [4 {:hours 8}]
 [5 {:hours 15}]
 [6 {:hours 24}]
 [7 {:hours 35}]
 [8 {:hours 48}]
 [9 {:hours 63}]
 [10 {:hours 0}]
 [11 {:hours 4}]
 [12 {:hours 6}]
 [13 {:hours 12}]
 [14 {:hours 20}]
 [15 {:hours 30}]
 [16 {:hours 42}]
 [17 {:hours 56}]
 [18 {:hours 72}]
 [19 {:hours 90}]
 [20 {:days 0}]
 [21 {:days 1}]
 [22 {:hours 16}]
 [23 {:days 3}]
 [24 {:days 4}]
 [25 {:days 5}]
 [26 {:days 6}]
 [27 {:days 7}]
 [28 {:days 8}]
 [29 {:days 30}]
 [30 {:days 0}]
 [31 {:days 1}]
 [32 {:days 2}]
 [33 {:hours 36}]
 [34 {:days 4}]
 [35 {:days 5}]
 [36 {:days 6}]
 [37 {:days 7}]
 [38 {:days 8}]
 [39 {:days 40}]
 [40 {:days 0}]
 [41 {:days 1}]
 [42 {:days 2}]
 [43 {:days 3}]
 [44 {:hours 64}]
 [45 {:days 5}]
 [46 {:days 6}]
 [47 {:days 7}]
 [48 {:days 8}]
 [49 {:days 50}]
 [50 {:days 0}]
 [51 {:days 1}]
 [52 {:days 2}]
 [53 {:days 3}]
 [54 {:days 4}]
 [55 {:hours 100}]
 [56 {:days 6}]
 [57 {:days 7}]
 [58 {:days 8}]
 [59 {:days 60}]
 [60 {:days 0}]
 [61 {:days 1}]
 [62 {:days 2}]
 [63 {:days 3}]
 [64 {:days 4}]
 [65 {:days 5}]
 [66 {:hours 144}]
 [67 {:days 7}]
 [68 {:days 8}]
 [69 {:days 70}]
 [70 {:days 0}]
 [71 {:days 1}]
 [72 {:days 2}]
 [73 {:days 3}]
 [74 {:days 4}]
 [75 {:days 5}]
 [76 {:days 6}]
 [77 {:hours 196}]
 [78 {:days 8}]
 [79 {:days 80}]
 [80 {:days 0}]
 [81 {:days 1}]
 [82 {:days 2}]
 [83 {:days 3}]
 [84 {:days 4}]
 [85 {:days 5}]
 [86 {:days 6}]
 [87 {:days 7}]
 [88 {:hours 256}]
 [89 {:days 90}]
 [90 {:days 0}]
 [91 {:days 1}]
 [92 {:days 2}]
 [93 {:days 3}]
 [94 {:days 4}]
 [95 {:days 5}]
 [96 {:days 6}]
 [97 {:days 7}]
 [98 {:days 8}]
 [99 {:hours 324}])

emccue14:04:37

this is the new fizzbuzz

πŸ˜‚ 4
emccue14:04:07

well, strictly i can normalize this to hours and graph it

dgb2314:04:45

graph it as in visualize?

emccue14:04:35

πŸ’― 3
❀️ 1
emccue14:04:34

my algorithm doesn't work for more than 2 digits, but we can run ML on this to extrapolate

πŸ˜‚ 3
emccue14:04:03

but that can be an exercise for the reader

πŸ˜† 1
p-himik15:04:35

Such evils should not exist.

❀️ 1
πŸ’― 1
emccue15:04:42

shout out to clojure 1.11 for making this sort of logic easy and cross platform with parse-long

naomarik20:04:13

why would anyone choose this?

πŸ˜† 2
lread00:04:19

enumskulls!

😏 1
Sakib19:04:43

Can anyone suggest a theme for clojure development in vscode?

isak19:04:01

Synthwave '84

πŸ’― 1
partyparrot 2
dgb2319:04:01

I use Ayu mirage with a few adjustments (closest matching parens are highlighted), it’s minimal and kind of warm. I don’t like busy highlighting.

1
pez07:04:48

I use GitHub Dark Default. It is very complete (as are all GitHub themes) and restful for me, but might be a bit busy for others.

seancorfield19:04:18

@nsakib.cse You don't like any of the built-in ones?

seancorfield19:04:02

(I just use Dark+ -- but with Calva/LSP/etc that gives good syntax highlighting for Clojure)

seancorfield19:04:59

I consider Calva and Portal to be the two key Extensions for Clojure. I, personally, have Clover installed too and use that for the REPL (Socket REPL) instead of Calva's nREPL UI but I'm in a minority there πŸ™‚

πŸ‘€ 2
πŸ’‘ 1
Kelvin19:04:30

I use Calva everyday but I've never actually heard of Portal. Any benefits from using it?

teodorlu21:04:42

Check out #portal - it's great for digging into deep data structures.

seancorfield22:04:24

Portal is awesome πŸ™‚ I use it to display log messages from my app (via tap>) as well as test results. If you're using next.jdbc, Portal lets you navigate through your database via datafy/`nav` etc. Have you seen either Cognitect's REBL or Vlad's Reveal?

didibus23:04:54

I just can't get into VSCode, Emacs has ruined me. So Cider all the way for me πŸ˜› I'd say clj-kondo is my other cant-live-without tooling. I've got portal, but somehow I never use it, Cider has cider-inspect and I tend to use that each time over portal

didibus23:04:03

And then I use inf-clojure for socket REPLs. Though my guess is Clover has more features?

didibus23:04:31

My editor journey for Clojure has gone: Eclipse -> IntelliJ -> Atom -> Emacs -> VSCode -> Emacs

seancorfield23:04:57

A few more features yes, but inf-clojure continues to improve, I gather. I stay in VS Code all day (aside from Slack πŸ˜† ) -- git integration, Jira/BitBucket, running tests, reading online docs (VS Code includes a basic web browser so I can put my cursor on something and ctrl-; j gets me the JavaDocs for a class or expression type or ctrl-; ? gets me the ClojureDocs for symbol.

seancorfield23:04:02

My journey started with TextMate πŸ™‚ but also included Eclipse (CCW), LightTable, Emacs, Atom, and VS Code. Emacs was in several slots there but even having used it on and off for, literally, decades I always end up getting frustrated and going to something else.

didibus23:04:19

Ya, it definitely requires more tinkering, and I always have to patch a few "bugs" on my various OS/PC I use it. But I love just never leaving Lisp, Lisp to customize and fix my editor, Lisp to code my programs in. Also, never having to use the mouse really changed things for me. There's some features I just can't find anywhere else.

didibus23:04:14

Personally, my favorites were Eclipse (CCW), Atom and Emacs. I'm super sad Atom kind of got side-stepped by VSCode. I could really see Atom becoming a modern JS based Emacs.

πŸ’― 1
didibus23:04:01

Oh, I had a VIM phase too, for 6 months, never got into the modal thing in the end. Also, it was too line-based, which didn't always work well for Lisp syntax.

seancorfield23:04:09

elisp just annoys me too much because it isn't Clojure πŸ™‚

πŸ’― 3
πŸ˜‚ 1
βž• 1
didibus23:04:29

Elisp is definitely one of a kind haha.

didibus23:04:24

Counterclockwise I feel I miss. It was the most beginner friendly in my experience. It used the eclipse project for the classpath. Had autocomplete, a great REPL, showed doc on hover, macroexoanded on Ctrl+hover, had basic Paredit, rainbow parens, and simple load file semantics and eval expression, and it integrated perfectly with Java. Since then, when we have a new team member, nothing seems to be as easy to pickup.

didibus00:04:53

I think inf-clojure hasn't changed much. I just checked it out again. The big advantage of Clover over it is that Clover injects dependencies into the socket repl, so for example code completion. Inf-clojure just maps emacs stuff to things you could run in a REPL yourself, like calling source and doc from the clojure.repl namespace. If you want code completion, you have to make sure compliment is in your classpath yourself and require it yourself.

didibus00:04:32

Spiral comes closer, but it's got a few bugs and hasn't been maintained. But it's basically an Unrepl based mode for Emacs.

seancorfield00:04:48

Clover doesn't require compliment BTW. It will use it if present.

seancorfield00:04:17

Mauricio is trying to get away from unrepl in Chlorine/Clover -- but it will still need to "inject" (evaluate) some code because it needs to "upgrade" the basic Socket REPL to have more control -- per my comments in the other thread about prepl.

didibus00:04:43

Without compliment it will still do auto-complete? It'll just inject some more custom code for auto-completion?

seancorfield00:04:24

You'd have to check the source for exactly what it does. I stopped using compliment ages ago and I get perfectly satisfactory completion for stuff I care about.

seancorfield00:04:02

As Oli's article says, Clojure itself is pretty powerful and can do a lot of editor support stuff pretty easily without needing extra dependencies in your stack πŸ™‚

didibus00:04:49

Ya, that's what inf-clojure relies on. But there's no auto-completion, especially of locals.

seancorfield00:04:55

These days I'm probably also getting auto-complete from LSP/clj-kondo in Calva (which I use for all the static stuff)

didibus01:04:38

Looks like Conjure injects compliment for auto-complete

didibus01:04:04

Ya, same, I have my own static completion based on clj-kondo and some custom local completion in Emacs that works even with forms that don't balance. I'm also completing Java using javap. But I need to update it to support tools.deps haha. One thing I've found though, I kind of want completion of things in the repl as well, for dynamically generated functions.

didibus01:04:53

I'm always tempted to abandon Cider for something that don't need to inject dependencies into the repl prior to repl starting, but then I always miss some of Ciders features, like the debugger, which I love.

didibus01:04:50

Ok, interestingly enough, it looks like Oli has switched exclusively to nRepl for Conjure. Seems he needs to have a follow up talk about that.

seancorfield02:04:56

I thought he had written about that switch?

seancorfield02:04:23

The old prepl version of Conjure was written in Clojure so I imagine (neo)vim integration was a bit clunky and slow? The new nREPL version of Conjure is written in Lua (it's fairly easy to write nREPL clients in non-Clojure languages) and Lua integrates with (neo)vim a lot more smoothly, right?

seancorfield02:04:01

OK @U0K064KQV Start here and read forward: https://clojurians.slack.com/archives/CK143P6D7/p1583374701076100 -- talks about nREPL vs prepl and then Oli starts talking about why he gave up on prepl and switched to nREPL. Seems like cljs support was a big part of it (cljs is not consistent with clj's prepl implementation -- or it wasn't two years ago).

πŸ‘ 1