This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-16
Channels
- # aws-lambda (1)
- # bangalore-clj (2)
- # beginners (121)
- # boot (23)
- # cljs-dev (165)
- # cljsrn (8)
- # clojars (2)
- # clojure (164)
- # clojure-berlin (6)
- # clojure-chicago (3)
- # clojure-italy (5)
- # clojure-nl (1)
- # clojure-russia (4)
- # clojure-serbia (32)
- # clojure-sg (1)
- # clojure-spec (8)
- # clojure-uk (55)
- # clojurescript (94)
- # cursive (21)
- # datomic (30)
- # events (1)
- # hoplon (6)
- # jobs (1)
- # keechma (1)
- # liberator (2)
- # luminus (8)
- # off-topic (48)
- # om (12)
- # onyx (24)
- # parinfer (15)
- # pedestal (8)
- # re-frame (4)
- # sql (18)
- # test-check (31)
- # unrepl (70)
- # untangled (21)
{:keys [name content mime-type charset transfer-encoding], :or {:transfer-encoding :quoted-printable}}
I think, I doubt really use :or
so I am not overly familiar with the syntax off hand
indeed, and here's the error you would have got pre-spec:
(let [{:keys [foo] :or {foo :bar}} {}] foo)
=> :bar
(let [{:keys [foo] :or {:foo :bar}} {}] foo)
=> nil
Weird, that defn definitely isn't anywhere in my code. I wonder if a dependency got out of date somewhere...
my guess is you are getting a different aleph version or a different clojure version than you were yesterday
Unrelated question: Is there anything 'wrong' with creating atoms that contain a maps of core.async chans? I'm seeing some weird kind of thread starvation in my code, and that's the only area that seems problematic.
my guess is you are doing things with channels using swap!, which of course will re -run the function if it needs to, so doing side effecting things, like channel manipulation, is bad
But it seems innocuous? I have a few:
(swap! proxy-session-ip (fn [v x y]
(assoc v x y)) session-id (afghan.service/find-ip country-id))
and
(do
(info "Creating recieve channel: " reqid)
(swap! service/proxy-recieve-pool (fn [v r]
(assoc v r (async/chan 1))) reqid)
(service/add-work-item {:requestid reqid
:request {:headers heads
:request clean-req}} forward)
(info "Getting channel from recieve pool: " reqid)
(let [c (get @service/proxy-recieve-pool reqid)]
(info "Getting obj from recieve channel: " reqid)
(let [obj (async/<!! c)]
(do
(info "Closing recieve channel: " reqid)
(async/close! (get @service/proxy-recieve-pool reqid))
(info "Swapping out empty recieve channel: " reqid)
(swap! service/proxy-recieve-pool (fn [v r]
(dissoc v r)) reqid)
obj))))
is there a pattern for this: I want a "global registry" which is a dynamic map of :keywords to objects this map is modified as the program runs (things register and unregistering) is there a "clojure pattern" for doing this?
you can use an atom (around an immutable map), or a ConcurrentHashMap, but globals are not better an idea in clojure than in any other language, so I would recommend against them
by "global-registry" I really mean something like "directory for looking up other objects/services"
it'd kinda weird; if we look at humans, we can refer to each other by name but by modules, we'd ahve to (1) sort people by when they were born, and (2) older people can refer to younger people but younger people could not refer to other people // <-- this would be our communication pattern if we did not have a "name -> human" mapping
well, if you want to use that analogy, the name -> human mapping is local to each person, and populated by another person introducing a human with a name
@qqq - Datascript?
What could cause a core.async put!
to succeed instantly, but a <!!
to block for 40+ seconds, even if the buffer is empty? (Yeah, it's weird) There's also a async/alts! [event-channel (async/timeout)
, but that seems fine to me, I thought that wouldn't be blocked by the timeout.
bradford: so you're:
(put! ch 42)
and then you're
(<!! ch)
and this is blocking? @U085HE1PB
Hi, using clj-http
I make a simple get request. It request returns xml content in its body. If I make that request with postman plugin I get the xml, however clj-http response returns body="" with content-length being correct (the same as with postman)
so you might have some middleware or something reading the stream before the point you're looking at it
@U061HGP8C, thank you, I will check this
I mean, if I have to name the variable something that's appropriate for context its not a very lispy variable name 😂
its like naming a string "s" its just a placeholder that preserves the shape of the code and gets the implementer out of the variable name discussion
im really just joking. I wanted to be lazy and give it a lispy name, but I'll name it something descriptive and useful if I have to i guess
@tjtolton In clojure core most function inputs are simply called f
https://clojuredocs.org/clojure.core/update
Transducers are usually called xf or xform https://clojuredocs.org/clojure.core/transduce
@yogthos in selmer, can I access nested structures using vars? As in: item.var1
for var1 = :foo
and item = {:foo "bar"}
what’s typically the best way to convert a heavily “nested map of vector of maps” — i think i’m looking for a nice lens library. a transducer seems to be able to do this quite easily due to the callback nature of it, but there’s a bit of boilerplate involved here i wonder if there’s any decent clojure lens library ? is this where specter comes into play ?
Yep, Specter can do lens-y things, so that's probably what you want.
right, now i guess i have to get over myself and learn to accept its UPPERCASE syntax things 🙂
I am really interested in learning Specter, but I'm also curious about his lens pattern in general. I haven't heard about it before.
@captainlexington it’s commonly used in Haskell, not sure whether it’s used in many other languages
I think he actually kinda invented it himself then realized later that it was called lensing, so I wouldn't be surprised if it were a bit different than what you might find elsewhere.
I'm pretty ignorant about both lensing and Specter, though, so take that with a grain of salt. :-)
it’s very powerful, and saves you a lot of boilerplate — but on the other hand, requires a whole new vocabulary for tree traversals
@jeff.terrell that's right, although I do think "navigation" is a much better name
haskell has multiple abstractions for navigation (lens, traversal) while specter just has one
not sure why haskell complicates things like that, as there's no performance benefit to distinguishing – I think it may have something to do with the type system
traversy
replaces the original update function! Does traversy
works with datomic entity maps?
@souenzzo if it does not, you might be happier with Datomic pull, which returns ordinary maps
Does anyone know a hardware that allows for GPS tracking with an API to pull location information from?
unless you want something that would connect to pc over usb or something...im sure that exists
Hi all, I am trying to find a way to create a REST client in clojure in which I can send client certificates to the server!!!! I have the client client.crt and the client.key and I need to send them in a GET request
(defn entry-<-file [file]
(let [fname (.getName file)
[_ book_name page_number] (re-matches #"(.*).pdf-([0-9]*).png" fname)]
(println "entry-<-file: " fname)
(when book_name
[book_name (Integer. page_number) (slurp file)])))
(defn load-book-pages! []
(j/execute! db-spec ["drop table book_pages"])
(j/execute! db-spec
[(str
"create table book_pages "
"( book_name VARCHAR(20) "
", page_number BIGINT "
", png MEDIUMBLOB "
", PRIMARY KEY(book_name, page_number)) ")])
(let [entries (keep entry-<-file (file-seq ( "/tome/tb/data/calc1")))
groups-of-10 (partition 10 entries)]
(doseq [group-of-10 groups-of-10]
(jdbc/execute!
db-spec
(hc/format {:insert-into :book_pages
:columns [:book_name :page_number :png]
:values group-of-10})))))
I am inserting a bunch of (book_name, page_number, png_of_page) triples into a db.Currently, this is a bit slow as the png is loaded, serialized intoa . string, put into the sql statement, then executed.
I hate answering simple questions with a "maybe change your design" buuut... I've never heard of anyone having good experiences with blob/clob fields. most projects I've worked on in the last 5 years have stored a varchar with the path to a randomly generated unique path on disk instead
and I was hoping to stuff it all in the db, instead of (1) having a separate kv store and (2) stroing the shasum of the blobs
well I think that is basically what they do underneath, it's just not having access to that underneath tends to end up restricting you. ie if I want to send that blob to a http requester I'd much prefer to just point apache at the path than have to have it go through my application memory
it's directly from file, possibly cdn-able vs "load into db memory; load into app memory; stream over http / unable to be cached"
yes, it would be cdnable (depending on lots of things to do with setting it up of course)
not really sorry. I would say you need to make very sure that the path is both unique and unpredictable, as if it's predictable it's an attack vector. you also probably want it to be in some sort of place on disk that can't be traversed out of
nit on that gist, why not just (format "%02x" (bit-and % 0xFF))
instead of the substring stuff?
(.digest (java.security.MessageDigest/getInstance "sha-512") (.getBytes (slurp "build.boot")))
it actually seems like http://java.sun.com/javase/6/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File) might do what you want
using slurp to read a binary file is a terrible thing to do, and turning binary data in to a string before sticking it in the db is also terrible
Strings are pretty much garbage for anything except for data you are printing out as a displayed string to a person
slurp is bad for reading in binary data because it creates strings (which are garbage) and assumes a character encoding (or you can pass one in) because to build a String (from characters) from bytes you need an encoding, but binary data doesn't have one
(.toString (.digest (java.security.MessageDigest/getInstance "sha-512") (.getBytes (java.nio.file.Files/readAllBytes (java.nio.file.Paths/get (java.net.URI/create "build.boot"))))))
Has anyone had any difficulties with repl refresh when using cljc files with reader conditionals? I find clojure.tools.namespace.repl/refresh ignores the namespaces completely when using the conditionals within the ns form
@hiredman: I am putting quite a bt of google-fu into this; can you please tell me the RIGHT way to do this instead of saying " it's wrong?" 🙂
the nio way may be faster, but it may not, and you will need to expand some google juice working on the syntax for it and reading the javadocs
java.nio.file.Files/readAllBytes returns a byte array, so you cannot call getBytes on it
you seem to be randomly button mashing stuff together, that is not how you write a program
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllBytes(java.nio.file.Path)
depends on the program and the context, I've button-mashed out plenty of stuff over the years
I can completely be replaced by a bot that just (1) gets snippets from gist / SO and (2) runs the vodce, and (3) pastes the error into slack
(.digest (java.security.MessageDigest/getInstance "sha-512") (java.nio.file.Files/readAllBytes (java.nio.file.Paths/get "." (into-array ["build.boot"]))))
hey guys, does anyone know how to configure immutant/undertow to respond properly to byterange requests?
the bit-and is since the input is bytes, which are signed; so that turns it into a “unsigned byte”, if you will
I really wish our bot could handle strings
@qqq it’s pretty idiomatic for byte munging to represent 255 as 0xff
but yeah, it’s eight bits, all of them ones
as csm said, we need to handle signed bytes
@csm not for me, for negative bytes
peregrine.circle=> (format "%02x" -88 0xFF)
"ffffffffffffffa8"
peregrine.circle=> (format "%02x" (bit-and -88 0xFF))
"a8"
oh - for a byte though it might just work
peregrine.circle=> (format "%02x" (byte -88) 0xFF)
"a8"
yeah, it’s very type dependent I guess
that’s all clojure’s format is 😄
(defn format
"Formats a string using java.lang.String.format, see java.util.Formatter for format
string syntax"
{:added "1.0"
:static true}
^String [fmt & args]
(String/format fmt (to-array args)))
- much smaller function than I first expectedI bet that one function prevented an otherwise inevitable wrapper lib from being written, lol