This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-29
Channels
- # aws (6)
- # beginners (33)
- # bitcoin (2)
- # boot (22)
- # carry (2)
- # cider (5)
- # clara (21)
- # cljs-dev (115)
- # cljsrn (40)
- # clojure (161)
- # clojure-dev (73)
- # clojure-italy (38)
- # clojure-russia (88)
- # clojure-spec (123)
- # clojure-uk (58)
- # clojurescript (88)
- # core-async (26)
- # cursive (5)
- # datascript (18)
- # datomic (26)
- # hoplon (50)
- # java (2)
- # jobs (1)
- # leiningen (10)
- # lumo (1)
- # off-topic (18)
- # om (9)
- # onyx (26)
- # parinfer (13)
- # pedestal (41)
- # quil (1)
- # re-frame (27)
- # reagent (21)
- # ring-swagger (11)
- # slack-help (3)
- # spacemacs (8)
- # specter (5)
- # sql (42)
- # timbre (1)
- # uncomplicate (7)
- # untangled (3)
- # videos (1)
- # yada (26)
Maybe my google-fu is failing me, but is there a simple way to unzip a file on disk to a a directory using Clojure? Everything I've found is about unzipping a single file, but I have a zip that has several. I want to unzip it and then read a specific one into memory.
Trying to build an ETL tool that downloads a zip file, unzips it, reads a specific file into memory, and then does some stuff to it.
Ideally I could use .getNextEntry or something similar and read to memory when it matches a regex
@cigrainger if you just need the information there is no need to unzip to files - you could read it file directly from the zip into memory
Oh that would be ideal! How would I do that with a specific file that's in the zip file? (One of multiple that are zipped in the archive)
cigrainger: give me a few - will fire up a repl and see if I can cook up some example code. I’m not senior with clojure but I have spent a lot of time with file manipulations and zip files : )
Awesome! Thanks. I'll play around with your suggestion re: ZipEntry as well. That was the general direction I was going but I couldn't find much and I'm not great with clojure yet either.
(ns zip-files.core
(:import (java.util.zip ZipFile)))
(defn get-entry-data [zip-file-path entry-name]
(let [zip-file (ZipFile. ( zip-file-path))
entries (enumeration-seq (.entries zip-file))
matching (filter #(= entry-name (.getName %)) entries)]
(if (not-empty matching)
(slurp (.getInputStream zip-file (first matching)))
(println "no entry" entry-name "found!"))))
where test.txt was one of many files within test.zip and the contents of test.txt were “Hello World!\n\n”
Awesome! Thank you!
I’m live translating this from some groovy code I wrote a while back (we’ll see if I get lynched here), but you can iterate through the entries within a zip file and then call the ZipEntry (.getInputStream zip-file zip-entry)
and then I believe you should be able to use slurp to get the contents of the input stream
@mbjarland Have a look at https://stackoverflow.com/questions/5419125/reading-a-zip-file-using-java-api-from-clojure#5419767
Hey folks, I have the following snippet:
(let [coll [1 2 3]]
(map #(println :test %) coll)
(map #(println :test2 %) coll))
This results in:
:test2 1
:test2 2
:test2 3
(nil nil nil)
And not my expectation:
:test 1
:test 2
:test 3
:test2 1
:test2 2
:test2 3
(nil nil nil)
Can anyone explain this behavior?@fatihict Yes, don't use map to execute side-effecting functions like println since map basically returns a lazy seq
you can wrap your map's in a (doall ... ) call, but it would be more idiomatic to use doseq for this case
jgeraert: doseq
works great for this, but there's also run!
which like this usage of map takes a function and a collection as args, but is run for side effects eagerly.
@fatihict meant to tag you above
@U051SS2EU Ah I see, thanks for the tip 🙂
Hey! I was wondering if repeated subvecs would ever allow the excluded data to be garbage collected if there was no way to access it any more? Or would I need to use (vec (rest x))
if I wanted to actually drop the first item in a vector?
I would use a persistent queue but I want in place updates too, performance of (vec (rest x))
being O(n) is a non-issue for me too, looking for the "idiomatic" solution more than anything 🙂
boot.user=> (for [x (do (println "x") [1 2]) y (do (println "y") [1 2])] [x y])
x
y
y
([1 1] [1 2] [2 1] [2 2])
i was p confused for a bit because i was using (q/random ...)
(from quil) inside the inner one xD
@fatihict or you can make something like that
(let [coll [1 2 3]
res (concat (map #(vector :test %) coll)
(map #(vector :test2 %) coll))]
(doseq [x res]
(apply println x)))
Someone Please suggest real-time-messaging clojure library. I might also need Screen Sharing and video chat.
Is this expected on clojure 1.9-alpha17?
(keyword :foo) ;; :foo
(keyword "anamespace" :foo) ;; ClassCastException
I understand that supporting coercions can be problematic but it is a little counter intuitive given the arity 1 behaviour
can anybody tell me how to use pprint? I mean in a file, not the REPL. What is the magic :require :use line i need to use?
the error says you're trying to call clojure.pprint, if you aliased it you need to call (pprint/pprint x), or (clojure.pprint/pprint x)
what i need is one WORKING example, which unfotrtunately i was not able to find :D:D
Exception in thread "main" java.lang.RuntimeException: No such var: clojure.core/clojure.pprint,
well, ia m not just playing around with the language, i want to make money with it 🙂
I run my startup on so many "alpha"s and pre-alpha spur-of-the-moment forks that I've lost count.
(defkeyframes blinkBlackGreyKF
[:0.00001% {:fill "#ddd"}]
[:50% {:fill "#000"}]
[:100% {:fill "#ddd"}])
works, but if I change the 0.00001 to 0.0 or 0 , it fails -- somehow the css refuses to display the % if it's 0lein ancient
, which is a plugin for one of the common clojure build tools, leiningen, actually makes it really easy to speculatively upgrade packages and run the entire test suite, only keeping the upgrades if your tests pass
hmmm... maybe the aplphas are so stable becuase of clojure's nature, i think it's harder to make bugs in clojure
whether to write tests and what kind of tests to write depends on how much time I have, what I'm writing, and what the lifespan of the code is expected to be
sometimes I'm wrong about how much time I have or what the lifespan of the code is going to be, and tests get added on a later iteration
i.e. I expect something to be a one-off prototype and it ends up in production. it'll grow tests sooner rather than later so I can be confident about happy paths when I need to make changes.
today i had the following problem: after one day braek of coding nothing worked,something was fucked up, i needed 3 hours to get it back to life
last time i wordked for corporate i solved this problem in that everyday one hour before going home i started to clean up and do notes about everything that was doing problems
I find that only really happens to me if I'm not constantly evaling my code and tests during development. i.e. if I spend 3 hours just writing code without evaling for some reason. that code will take much longer to get working than if I had just been evaling the code and my tests while going.
@mjo324_56 but if you had working code one day and two days later your code doesn't work, isn't the solution just to stash, revert to the working code, make sure it still works like you expect, then diff your stash and that working code?
i think you undrerstand my problems, i am curretly figuring out the perfect workflow for me
sometimes I end up writing pseudo-code that is only somewhat working lisp when trying to get ideas out of my head. that's the kind of code that takes forever to get actually working. I often put it into its own namespace that isn't required anywhere (a persistent *scratch*
of sorts) and then reference it in another coding session when I actually write tests and eval it as I'm going. I've found that if I try to get the code working, as opposed to using stream of consciousness code as "notes", I spend a ton of time just making it work. As a consequence, I try to be disciplined about making sure I eval everything as I go, to avoid the kind of scenarios where I write unusable code for several hours and then spend the rest of the day trying to make it usable.
depends what you mean by architecture @mjo324_56 and what you’re doing. There are lots of orthogonal concerns; code layout (namespace hierarchy / load orders), runtime data flow, use of polymorphism, state, building for composition, structuring data etc…
this is a #{64 65} byte signature -- as opposed to DER encoding which is #{70 71 72} byte sig
@cfleming Any way to temporarily disable paredit to make parens balanced again after pasting unbalanced parens or deleting code leaving it unbalanced?
I know about the menu, but I was thinking about, CTRL + "(" or something (tried that)
Thanks for the channel
Toggle Structural Editing Style in keymaps @joelsanchez
Let's give it a try!
That's wonderful 🙂
i often find myself with too many options to get something “polymorphic” done in clojure.. was wondering if someone could speak to this:
say I need to switch on a data’s type. there’s the standard map approach {:type :some-custom-type}. then you can wrap that :type
with a more formal multimethod
and defmethod :type/foo :type/bar, etc.
. you can also create a record to further formalize the map, and thus get access to things like (instance? _)
. you can also define a protocol for the various types and gain access to things like (satisfies? _)
. now with spec.alpha you can go another step and do things like (if (s/conforms? _) ...)
.
surely there’s a good blog post or two out there illuminating such matters… but every time I reach for polymorphism i find myself almost paralyzed with options, not really sure which is best in each case.
you'll love this https://leanpub.com/clojurepolymorphism/
i was asking myself the same question when i stumbled upon that
even the sample is very helpful
@lwhorton I guess it boils down to the definition of "polymorphism". In Clojure you're not tied to any particular approach because you can dispatch on arbitrary fns, so you can have the equivalent of dispatching based on OO hierarchy (Java classes), nominal typing (your own taxonomy), structural typing (spec, etc) ...
While in other languages (most I guess?), polymorphism bundles type system + dispatch/pattern matching together
@mjo324_56 this slack has a message limit that, when hit, removes the messages. I’m not sure whether multiple short messages like yours are counted as one, or as many, but consider combining them into a single, formatted message (a nice bonus is, they are more readable). just fyi
to answer your question — what does “I’d like to run a couple of functions” mean exactly? What you’ve posted certainly does just that. But what is the point?
(defn -main []
(func1)
(func2))
The result of the above will be whatever (func2)
evaluates to. Of course, if (func1)
produces side-effects (I/O, etc), these side-effects will occur.*unless (func1)
produces a lazy sequence which would never be realized.
(defn -main "This should be pretty simple." [] ( (println "hallo") (println "hallo2") ))
yes, try this, and see the difference:
(defn mainnn
"This should be pretty simple."
[]
(println "hallo")
(println "hallo2"))
You have an extra paren before the first println
. This evaluates the result of the first (println "hallo")
, which is nil
, as a function, and this is what creates the NPE.
Hello, I have a small question about spec. How does one specify a constant value in a regex spec? Like a vector that always must start with a keyword. I can do something like this (spec/cat :type #{:message} :contents string?)
(as part of a multi spec), but is there a way to say the first thing in the sequence must be :message
?