Fork me on GitHub
#clojure
<
2019-11-12
>
josh_tackett01:11:37

So example encrypt: (shell/sh "openssl" "aes-256-cbc" "-a" "-pass" "pass:password" :in "hola") Decrypt (shell/sh "openssl" "aes-256-cbc" "-a" "-d" "-pass" "pass:password" :in "U2FsdGVkX18B/CGSxe0V6G0HmcIuKUzkMhNC0Q9T61g=\n") Notice I can use the :in if I add a \n for the input. The problem is when I receive an encrypted string from a friend who did it with their console, I get the bad decrypt error. Any idea why?

noisesmith01:11:21

That part I'm not sure of. Backing up a moment to your initial issue, you can do aes-256-cbc via interop directly without shelling out.

noisesmith01:11:31

I'll have a small POC of that momentarily

Clypto01:11:56

@alexmiller is the http://ask.clojure.org site a stackoverflow instance, or a custom webapp clone?

alexmiller01:11:59

it's question2answer, which is a php/mysql oss app

noisesmith01:11:57

@josh_tackett I'm not sure but I think that's related to padding behavior on input? here's something that uses the java classes for encode - it's not done as it doesn't match the encoding you get, but it might be a start if you want to use that approach

(import (javax.crypto.spec IvParameterSpec
                           SecretKeySpec)
        (javax.crypto Cipher)
        (java.util Base64))

(defn zero-pad-bytes
  [n s]
  (let [output (byte-array n)
        fill (.getBytes s "UTF-8")]
    (dotimes [i (count fill)]
      (let [write-pos (dec (- (count output) i))
            read-pos (dec (- (count fill) i))]
        (aset output write-pos ^byte (get fill read-pos))))
    output))

(defn aes-cbc-encrypt
  [s]
  (let [enc-key "password"
        init-vector "encryptionIntVec"
        iv (IvParameterSpec. (.getBytes init-vector "UTF-8"))
        skey-spec (SecretKeySpec. (zero-pad-bytes 64 enc-key) "AES")
        cipher (Cipher/getInstance "AES/CBC/PKCS5PADDING")
        _ (.init cipher Cipher/ENCRYPT_MODE skey-spec iv)
        encrypted (.doFinal cipher (.getBytes s "UTF-8"))]
    (String. (.encode  (Base64/getEncoder) encrypted))))

talios01:11:56

delurks for over a year or so - recording an Illegal Argument podcast episode tonight - wondering how many clojurians are running UNDER Java 11+ at all?

seancorfield02:11:12

@talios We're still on OpenJDK 8 because we have some pieces of legacy infrastructure that won't run on 9+ (and that's why we've migrating off those things).

talios02:11:33

fun. good to know - sounds like we’re about to have another “but Java 11+ is dead/ignored rant” from Greg hah.

talios02:11:50

co-host of #illegalargument

seancorfield02:11:11

We've been testing against OpenJDK 11 for quite a while and we're close to moving up to that on some servers I think. We found an interesting change of behavior in the Locale class with currency formatting 🙂

alexmiller02:11:30

Based on the last Clojure survey, most are

alexmiller02:11:49

https://www.surveymonkey.com/results/SM-S9JVNXNQV/ Q16 - this is multi-select, so it's hard to tell exactly but almost 70% were still using Java 8

alexmiller02:11:12

I am very curious to see what this looks like for 2020. I expect 9 and 10 should be mostly dead (no one should use those now), but I'm expecting maybe about equal for 8 and 11

alexmiller02:11:31

that's my prediction at least :)

talios02:11:33

@alexmiller cheers for the link

seancorfield03:11:43

Java 9 was a very disruptive release for a lot of people -- so I can certainly see people staying on 8 much longer than they might have stayed on previous releases.

Sandae Macalalag03:11:02

Why would I use Clojure? I used it before during the early years of my career and it did help me to become a better programmer. I guess what is I'm asking now is, why would I use it? When most of the tooling/language now can make us productive? i.e. Functional Javascript, Immutable JS libraries, TypeScript typings, etc.

wcalderipe04:11:12

I did listen to this podcast episode a few days ago and I might answer a few of your questions https://clojuredesign.club/episode/036-why-do-you-recommend-clojure/

andy.fingerhut03:11:44

Having a common language for back-end and front-end development is cited by some as an advantage. Yes, I know JavaScript can do that, too, although I don't know whether server-side JavaScript is capable of achieving the same performance that Clojure on the JVM is (I haven't looked carefully to see).

andy.fingerhut03:11:51

Clojure is, by culture/convention/included-libraries, immutable by default, as opposed to something you have to go out of your way to opt into. Is that the case for JavaScript development these days?

seancorfield04:11:50

@sandae.macalalag We use it because we're on the JVM and it's a great general-purpose language that eliminates whole classes of potential errors by virtue of immutable data structures and the ability to work consistently with higher-level abstractions more easily than most other JVM languages. We also use it for the pure "joy" it brings with the fluid REPL-driven/-based workflow 🙂 It sounds like you're asking from a JS background p.o.v. so more from a client side of the house than the server side?

Sandae Macalalag04:11:36

On server-side as well with NodeJS.

seancorfield04:11:56

FWIW, I've been a professional programmer for about 35 years and I've been using Clojure for close to nine years in production now, and I'm the happiest I've ever been -- and that counts for a lot, for me 🙂

👍 20
clj 4
seancorfield04:11:20

Overall tho', I think it's very hard to persuade folks to switch to Clojure(Script) when they believe they are already happy and productive with the language/tooling they already use... and I'm not sure how much effort it's worth putting into "evangelism"...?

4
wcalderipe05:11:51

Regardless of how many years as a programmer, I always found it interesting that most of the people working with Clojure always bring the "I enjoy the workflow with the REPL and I'm just a happier programmer" to the surface of this discussion. IMO, if a language/tooling can bring you joy on tasks you have to do more or less 40h per week its enough to at least give it a try. Going around the topic of putting effort into evangelism, I personally found easier to do pair programming with people and show them how's the workflow on a daily basis rather than just talk about the language, unfortunately, this takes more time and the person need to be open to experimenting with new language/tooling.

💯 8
Sandae Macalalag06:11:46

What IDE or editor you guys used to get the benefit of REPL fully?

wcalderipe07:11:58

There's plenty of them out in the wild and on top of my mind are emacs + cider, spacemacs, IntelliJ + Cursive, and Vim. Before Clojure I was working with Ruby and JavaScript with Vi so I opted for emacs + evil + cider. Most of my teammates are using IntelliJ + Cursive It always depends on what you want for yourself. As far as I understood, you're curious about Clojure and you want to try it. This is great! If you don't mind I'll give you one advice: if you choose emacs, I do not recommend you try to learn Clojure and it at the same time. Most likely you'll be frustrated with either of them because you introduced too many changes at the same time in your workflow. Try something with an easy setup like IntelliJ + Cursive while you're learning the basics of the language. Furthermore, it always interesting to see what the community is doing on a daily basis. The survey is a rich source of information. Source: https://www.surveymonkey.com/results/SM-S9JVNXNQV/

seancorfield06:11:31

The workflow thing is interesting because that isn't inherent in the language or the tools -- it's a practice you have to learn (or be taught), but it's a practice that doesn't "fit" with a lot of other technology because even those with "REPLs" don't have the same semantics and therefore can't really support that practice... I don't think we do a very good job of onboarding new folks with that practice...

12
valerauko06:11:00

is there any particular reason clojure.core's comparison operators (< etc) only work with numbers instead of using Comparable?

👍 4
henrik13:11:46

You mean like (< \a \b) for example? My (wild) guess is that they’re optimized for numbers for performance reasons.

valerauko14:11:58

yes. my use case would be comparing datetimes

valerauko14:11:24

optimizing for numbers is fine but that shouldn't mean throwing everything else out

andy.fingerhut14:11:02

You can use clojure.core/compare on any two Comparable objects, I believe, and define your own functions on top of clojure.core/compare with names more similar to what you want.

henrik15:11:49

Yes, as above. It’s not that you can’t do it, you just have to reach for the more general compare to do it. Take subs and subvec. They do the same thing, albeit on strings vs vectors. You could write a single function that checks the type of incoming argument and then delegates to the correct machinery, but that would incur some overhead for things commonly appear in hot code paths. I guess someone decided at some point (probably Rich), that it wasn’t worth it.

valerauko16:11:57

ok i'll just go override all the comparison operators in core brb my point is that at the language level it really shouldn't be hard to optimize for hot paths while also being convenient

andy.fingerhut17:11:57

I do not know how difficult or time consuming it would be to change Clojure's < > etc. to do as you wish, as I haven't investigated closely. I know that there are inner loops involving < > on long and int values that are desired to produce high performance JVM byte code, and it isn't clear to me that the compiler can always do as good a job of that if those functions worked on arbitrary objects, too.

andy.fingerhut17:11:29

As my own personal guess, I suspect the Clojure core developers would prefer to focus their efforts on other language enhancements than that one, even if it is possible.

valerauko03:11:09

those high-performance loops already expect numeric values, so i'd assume that optimizing the hot paths based on those inferred types shouldn't be impossible...

andy.fingerhut03:11:55

It seems impossible that generalizing < > etc. would make them faster. It might make them slower, although perhaps it could be done in such a way that they do not get much slower, true. As I mentioned, I think the main issue is that such a generalization of those functions isn't interesting to the Clojure core developers (again, my guess, not from certain knowledge of their priorities)

wcalderipe08:11:19

> it's a practice you have to learn (or be taught) True. IMO, it's like learning Vim just by yourself. Most of time you have no idea of what you can do and some times you do but you have no idea how to Google it. However, when you pair programming with someone in order to learn Vim it's so much easier. @ericnormand did a great job on this REPL-Driven Development course https://purelyfunctional.tv/courses/repl-driven-development-in-clojure/ (thank you for that)

Michael J Dorian14:11:35

Actually, can anyone recommend information on repl-based development practices? I use the repl a fair amount when writing my hobby code but I'd love to hear more ideas on the subject. Bonus points if I can convince the other dev on my hobby project that repl based development isn't total nonsense!

andy.fingerhut14:11:49

It looks like the http://purelyfunctional.tv link above, while not free, can give you access to all of Eric's courses, including the ones on REPL driven development, for $49/mo, so for $49 you can find out whether you like his courses or not, then stop if you don't want any more.

andy.fingerhut14:11:20

(I am not affiliated with that business, nor am I even a customer, but I've heard good reviews about his courses)

Michael J Dorian14:11:05

Thanks! I'll take a look! I don't suppose I could get that information in a book format could I? 😁

vlaaad14:11:44

I really enjoyed this video back in the day: https://vimeo.com/230220635

👍 8
Michael J Dorian14:11:35

Lol, ok, I will just get over my video aversion! Thanks!

andy.fingerhut14:11:26

I think it would take a lot of pages of screen shots to give a detailed account of what REPL driven development is like. Someone may have written it in book form, but it would be quite long in that form, I believe.

Michael J Dorian14:11:39

That makes sense!

andy.fingerhut14:11:39

Sean Corfield has a few videos publicly available where he demonstrates his workflow, which includes REBL. REBL is included with Datomic licenses, or is available for $3/month via Patreon subscription from Cognitect. Videos: https://www.youtube.com/channel/UC8GD-smsEvNyRd3EZ8oeSrA . REBL: http://rebl.cognitect.com/download.html

sogaiu17:11:43

thank you for mentioning (and creating?) this - am happily digesting it now :)

alexmiller17:11:10

All credit to @U06GS6P1N !

😊 4
NoahTheDuke15:11:10

Does anyone know of a project like https://github.com/slagyr/speclj that handles things like “before” and “after” blocks?

seancorfield16:11:12

There's a variant that is 100% compatible with clojure.test as well, including all the editor/tooling support https://github.com/clojure-expectations/clojure-test

seancorfield16:11:49

(you just don't quite get such nice output because the latter has to use clojure.test reporting mechanism, whereas the former has its own)

👍 4
NoahTheDuke16:11:55

Oh wow I’ve not seen that! Thanks, I’ll check those out!

seancorfield16:11:40

There's a #expectations channel if you have deeper questions. expectations.clojure.test is actively maintained and in heavy use where I work.

seancorfield17:11:58

Hmm, I should add an example of expecting which makes it flow a bit more like speclj:

(defexpect some-test
  (expecting "it is even"
    (expect even? (some-function))))
You can "expect" any predicate and you can "expect" a Spec (`clojure.spec`) as well -- plus all the destructuring more... predicates.

seancorfield17:11:39

(readme updated 🙂 )

😍 4
NoahTheDuke17:11:21

Damn, what speed!

seancorfield18:11:37

You caught me just after my morning coffee -- it was a good time 🙂

4
NoahTheDuke15:11:41

Sadly, that one has been defunct (and certainly not feature complete lol) for a couple years now

etiago16:11:03

I'm trying to achieve something that feels like there is probably a pattern/idiom for... but I'm not aware if there's any function to deal with it. I have a collection [a b c d e f] which I want to transform into a collection of collections [[a b c] [d e] [f]]. The way to aggregate is... take elements until a sum of a property of each element is met. On a more meta question, does anyone now of a search engine where I can search for type/shape interfaces? Something similar to what Haskell has, where I can find functions that map from [] to [[]].

etiago16:11:38

That seems exactly what I need 🙂 thank you!

aisamu16:11:50

And for your second question, a reduce would suffice. A stateful transducer would also do the trick (look into partition-by for inspiration)

thanks 4
alexmiller16:11:15

and partition-all is prob useful

thanks 4
etiago16:11:13

Thanks 🙂 looking into the partition functions now.

lilactown16:11:39

what’s the best way to run an embedded JS engine in the JVM? Still nashorn?

lilactown17:11:50

thanks y’all. I think I specifically need Node.js. I don’t think I can change the VM it runs in otherwise Graal would work

lilactown17:11:15

I’ll check out J2V8, which might be close enough, but I also found https://github.com/apigee/trireme

Jakub Holý21:11:34

Hi hackers! I need to replace a single occurrence of a string close to the beginning of a file . Is there a better way than invoking sed -i s/.../? Slurp + replace-first + spit is nice simple but not good and wasteful if the file is large. Perhaps line-seq and something to write it, but can I write into the file line-seq is reading? (Ideally I'd not pass the rest of the file after the change through my program as it is unchanged but I guess that isn't possible.)

noisesmith21:11:55

the underlying problem is that on disk a file is not a random access linked list of lines

noisesmith21:11:40

anything you do that changes the length of the file requires changing everything to the end of that inode (and potentially allocating a new inode and/or altering later ones) - but that's all OS and fs specific

👍 4
Jakub Holý22:11:01

I was afraid so. Thank you.