This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-08
Channels
- # aleph (11)
- # arachne (7)
- # aws (1)
- # bangalore-clj (4)
- # beginners (24)
- # boot (128)
- # bristol-clojurians (23)
- # cider (1)
- # cljs-dev (43)
- # cljsrn (6)
- # clojure (178)
- # clojure-austin (3)
- # clojure-chicago (1)
- # clojure-dusseldorf (14)
- # clojure-finland (15)
- # clojure-france (6)
- # clojure-italy (18)
- # clojure-portugal (2)
- # clojure-russia (67)
- # clojure-spec (148)
- # clojure-uk (55)
- # clojurescript (199)
- # core-async (4)
- # cursive (18)
- # datascript (5)
- # datomic (120)
- # devcards (3)
- # dirac (53)
- # emacs (11)
- # events (3)
- # gsoc (7)
- # jobs (1)
- # lein-figwheel (25)
- # leiningen (5)
- # lumo (12)
- # off-topic (29)
- # om (174)
- # om-next (2)
- # onyx (7)
- # perun (10)
- # protorepl (6)
- # re-frame (12)
- # remote-jobs (1)
- # ring (19)
- # ring-swagger (25)
- # rum (6)
- # spacemacs (13)
- # sql (3)
- # untangled (88)
- # yada (7)
Is there any notion of 'caching' a list of spec predicates that succeeds on a given object? Suppose I hve a spec that is recursive, I don't want it to manually chec for each subtree whether a certain property holds every time -- I want it to chec once, and then somehow tags it
@qqq these may be better in #clojure-spec, anyway, if I wanted to optimise a particular predicate for repeat calls with the same input then I would memoize it
Does anyone have any code to proxy all method invocations of a java object with some middleware? Something like:
(defn log [m & args} (println "I am logging") (.invoke m args))
(proxy-all jdbc-connection log)
Continued Example ...
(def p (proxy-all jdbc-connection log))
(.commit p)
"I am logging"
nil
@johnnyillinois you should check out the robert hooke library https://github.com/technomancy/robert-hooke .. does pretty much exactly what you want
you can often use reflection (java.lang.reflect.*) and a macro or two to do that sort of thing
@joshjones: thanks
Yeah I was hoping to not roll my own but hey open source library train here I come
hmm. what do I do if I have code that starts up events and a websocket, and it... well when I try to run lein uberjar
it actually runs my program and won't stop 😄
You have things defined with def
instead of defn
-- so it executes when namespaces are loaded.
(and namespaces are loaded when you run lein uberjar
because of AOT)
I'm guessing what I need to do is require some sort of argument when running. or just accept that I have to execute a specific function when running it?
Avoid def
🙂
right. is there any way to tell clojure to start something when I lein run it (or run the jar) but to not run it when I create the jar? Would that be the main
function I delete by reflex because Im a noob 😛
Sure, only call functions from inside -main
. Don't use def
.
Lesson learned. As usual, thanks Sean 😄
You can have a namespace with a -main
for lein run
and have a different namespace with a -main
for the JAR created by lein uberjar
.
What I tend to do is have the -main
for the uberjar and then have a (comment ...)
with various expressions that I can evaluate to define my application component, start it, stop it).
for example...
Hmm. ok. Now, when I try to run lein uberjar it creates it but tells me
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.
oh nm it's right it doesn't have gen-class
Per @hiredman you really don't need a gen-class
.
We don't AOT anything. We build an uberjar. We run the jar and tell it what the namespace is containing the -main
function.
alright, well it works with lein run
so I just gotta try it with the jar now ^_^
java -jar the-jar-file.jar -m our.main.namespace
hmm.
D:\home\devel\dtbot\target\uberjar>java -jar dtbot-0.1.0-SNAPSHOT-standalone.jar
Error: Could not find or load main class dtbot.core
Note: my example specified -m
to run the main namespace
Tried that, and it was the exact same error however
Same as lein run
(if you don't specify it in project.clj
)
lein run works actualy
The default -- if you don't specify :main
in project.clj
is to run clojure.main
which is the default entry point, which accepts the -m
argument to specify the namespace that contains the actual -main
to run.
right but the main namespace is (ns dtbot.core
Right, remove :main
from project.clj
Then you can specify it at runtime.
So remove :main ^:skip-aot dtbot.core
then
trying
@hiredman has a PR in to the Clojure site repo to update the docs to show this way of doing things because it totally avoids all the AOT stuff
oh there we go 😄
Oh boy. now here's a doozy. Tried to connect my lib (which uses websockets) to a.. let's say "bigger" account. io.netty.handler.codec.CorruptedFrameException: Max frame length of 65536 has been exceeded.
is this something I can... uhm... "fix" by allowing bigger packets? I'm using aleph/manifold
That would probably be due to receiving packets that contain... oh, about 6000 keys that are users, and a few other hundred various bits and pieces like channels and permissions and roles and emojis and all that jazz. Think, oh, 1631655 characters is a "small" packet.
(it comes in compressed with zlib though)
it's a stupid question but what does 65536 represent? bytes?
pr-str
(printf "%s" (pr-str #"..."))
printf or format don't know about clojure's print mechanism (it's just java.lang.String/format under the hood)
Ah, printf goes directly to format
which probably calls .toString
while print
(in the end) dispatches via print-method
which has an impl for java.util.regex.Pattern
(https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_print.clj#L393). Get it.
bitte!
some experts who can help me in the beginners channel with how to mock up a service in spec
okay, so im trying to create a function called upmerge to help me with configuration management. the idea is that, given a nested map, i want to push values up from the root into the leaves, with the caveat that anything specified closer to the leaves takes precedence. example input output:
rather, I can think of how to make it work as a recursive function, but it seems like it would be better written using a simple function passed to "merge with"
if you ask your question in the #specter channel there’s a good chance that the man himself will answer your question 🙂
hey all. would somebody be able to help me translate a curl
command line to something that wil work with clj-http
?
Command is
curl --basic -u "myFirstApp":"dsLE57s1wXRodpJqTYpUkUfY2S0iEv4i" --header "x-temboo-domain: /triss/master" --header "Content-Type: application/json" --header "Accept: application/json" -X POST --data '{
"inputs": [ {"name":"Query", "value":"Clojure"}]
}' ""
check the basic-auth
and body
parameters
thanks @pesterhazy
what do you mean encoding the data @triss? Your curl
command is saying that the content type is JSON, and the body is JSON. If you have a JSON string, just put that in the :body
parameter. If you have a clojure data structure, you need to turn it into a JSON string, probably with clojure.data.json
or cheshire
or something
Anybody do slack webhook integrations?
Code
(http/post "https://hooks.slack.com/services/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"
{:debug true
:form-params {:payload (json/encode {"text:" “TEST”})}})
Error
status: 500
body: missing_text_or_fallback_or_attachments
@josh_tackett I think if you send json you want to set the content-type header to application/json
@josh_tackett also I think you want your payload in the post body, not in the form params
it was the :
after text in string
other than that the request was correct
form-params is correct
is it possible to give an alias to keys in destructured args? e..g (defn do-something [{:keys [key1 :as key2]}])
@jdkealy you can do so if you use the other syntax for destructuring (the one that doesn’t use :keys
)
(defn do-something [{key1-alias :key1 key2-alias :key2}])
devn: I am persistently queue-rious.
I wonder if anyone is good with java streams, channels, bytes and byte-arrays. I'm having trouble with https://gist.github.com/danielstockton/a4ab9204a8d8806a95bd3c491ed932ca Trying to write some data out with fressian gzipped and then read it back. Currently, the fress/read line gives a EOFException. I would like to use the basic java API rather than a library.
I would invert the way you're trying to do that. Don't mess with a channel so you can write a bytebuffer to it.
it looks like data.fressian has an API for passing an OutputStream
I would think you can just pass the GZipOutputStream
to that, and then get transparent compression and fressian writing
you would need to use data.fressian/create-writer
and data.fressian/write-object
instead of the write
convenience method
Thanks, I'll look into those methods 👍
(def write-handlers
(-> fress/clojure-write-handlers
fress/associative-lookup
fress/inheritance-lookup))
(def read-handlers
(-> fress/clojure-read-handlers
fress/associative-lookup))
(def out
(let [baos (java.io.ByteArrayOutputStream.)
baos (GZIPOutputStream. baos)
writer (fress/create-writer baos :handlers write-handlers)]
(fress/write-object writer {:bob :jim})
(.toByteArray baos)))
(let [bais (java.io.ByteArrayInputStream. out)
bais (GZIPInputStream. bais)
reader (fress/create-reader bais :handlers read-handlers)
out (fress/read-object reader)]
out)
Something like this. I'm getting an exception because of .toByteArray not found on class GZIPOutputStream.Ha, funnily the read part works on some data I had already defined in my repl session.
it's because you're shadowing the name. use a new name for the GZIPOutputStream
You actually don't even need to keep a reference to the GZIPOutputStream, you could pass it in directly to create-writer
You're right, just got it working.
(def write-handlers
(-> fress/clojure-write-handlers
fress/associative-lookup
fress/inheritance-lookup))
(def read-handlers
(-> fress/clojure-read-handlers
fress/associative-lookup))
(defn compress [data]
(let [baos (java.io.ByteArrayOutputStream.)
gzip (GZIPOutputStream. baos)
writer (fress/create-writer gzip :handlers write-handlers)]
(fress/write-object writer data)
(.close gzip)
(.close baos)
(.toByteArray baos)))
(defn decompress [data]
(let [bais (java.io.ByteArrayInputStream. data)
bais (GZIPInputStream. bais)
reader (fress/create-reader bais :handlers read-handlers)
out (fress/read-object reader)]
out))
(decompress (compress {:bob :jim}))
I need a reference to close it, I think.
Thanks a lot for the help.
usually wrappable Input or Output streams can just be closed by the top level wrapper. Also, since this bottoms out in a ByteArray, it's not super critical to close it (no associated file handle to be leaked)
and the FressianWriter
closes whatever real writer you pass to it when you close it https://github.com/Datomic/fressian/blob/master/src/org/fressian/FressianWriter.java#L479
Hmm, if I omit the .close calls I get 'unexpected end of ZLIB input stream'
It looks like I only need to close the GZIP stream, not the baos
that makes sense. ZLIB probably has a footer-like structure and calling close
causes that to get written :thumbsup:
i have a protocol https://github.com/replikativ/konserve/blob/master/src/konserve/protocols.cljc and implementation https://github.com/replikativ/konserve/blob/master/src/konserve/serializers.cljc defined
now, in a project (https://github.com/replikativ/twitter-collector/blob/master/src/twitter_collector/core.clj) i use these protocols indirectly
i get "No implementation of method: :-serialize of protocol: #'konserve.protocols/PStoreSerializer found for class: konserve.serializers.FressianSerializer"
i have tried to import the record, but only evaling the form (in the REPL) of (defrecord FressianSerializer ...) helps
my problem is that i don't understand how the protocol implementations are exactly loaded and why they are missing in twitter-collector
most likely you are (re)loading the protocol definitions after loading the record definitions, effectively defining a new protocol with the same name
oh, actually, the other related possibility is you are importing the record jvm types without requiring the namespace that defines the records first
Hey clojurians, do you guys have advice for how to navigate clojure.core from the ide? I'm using CIDER, but my best bet still seems to be googling for examples and reading docs that group functions by what abstractions they deal with - i.e. seq, coll, etc
@hiredman the code is linked above, but i just required the protocol parts where i needed them. does this recreate protocol definitions? i am unclear about how to understand what is loaded when and why. is there a simple way to find out?
calling require will load it if it has not been loaded, calling require with :reload or :reload-all cause things to be reloaded, if you are working with an editor with a send to repl feature or eval-buffer or whatever, and you run on that on the protocol code, that will reload it
if you reload the protocol definitions, and reload the record definitions, if you still have instances of the previous record definitions in memory somewhere, they will still satisfy the old protocol, not the one you just redefined
i understand that. the konserve namespaces work even in a project where i use stuart sierras component with tools.namespace reload
require the namespace that defines the records, construct a record, call one of your protocol functions on it
then kill that repl, put a (println "FOO") at the top of the file where the protocols are defined, then do whatever you did where you saw the error before, you will see FOO printed out twice
somewhere in the middle is something that reloaded the protocol definitions, but not the record definitions, and either they both need to be reloaded or neither
@chriscraws I use intelliJ, and press F12. Mouse -> and <- map to navigating through the code. I would think emacs has a way to jump to a c.c function definition though, if that's what you're using.
likely when you changed the file that gave it a newer timestamp than the class file in target/
https://groups.google.com/d/msg/clojure/JC-OEMFNg2c/VDDqV-KCCQAJ here I am on the mailing list yesterday
that is the most common reason people give for aot compiling, and it is not required
@joshjones: I can jump through c.c ok, what i'm more looking for is a solid way to understand the relationships between the functions defined there, ideally without having to google for the information. for example, in the online clojure docs each has a 'related pages' section and tells me which functions perform what kind of tasks - is there any such organization implicitly in c.c?
thanks @hiredman ! 🙂 i didn't know about the -m switch. i hope the discouragement of gen-class gets more popular
@chriscraws well, you'll find namespace-related functions mostly grouped together, transient-related functions together, etc., but i don't think what you're looking for is going to be done in such a way in any code base, because the relationships between functions is not 1:1 and so well defined. You'll see logical groupings, but not a hyperlinked type of system