This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-29
Channels
- # arachne (3)
- # bangalore-clj (6)
- # beginners (246)
- # boot (57)
- # business (1)
- # capetown (1)
- # cider (2)
- # clara (1)
- # cljsjs (36)
- # cljsrn (1)
- # clojure (150)
- # clojure-austin (4)
- # clojure-brasil (7)
- # clojure-china (2)
- # clojure-france (3)
- # clojure-greece (3)
- # clojure-japan (3)
- # clojure-russia (38)
- # clojure-spec (25)
- # clojure-uk (25)
- # clojurescript (320)
- # clojurex (1)
- # cursive (38)
- # datascript (48)
- # datomic (23)
- # emacs (29)
- # events (1)
- # funcool (2)
- # hoplon (64)
- # jobs (3)
- # luminus (10)
- # off-topic (26)
- # om (27)
- # om-next (1)
- # onyx (1)
- # parinfer (38)
- # perun (5)
- # planck (19)
- # re-frame (38)
- # reagent (19)
- # remote-jobs (1)
- # rum (2)
- # schema (2)
- # spacemacs (1)
- # specter (8)
- # test-check (10)
- # vim (7)
- # yada (14)
May I get an advice of application design? I have few defrecord
types as client for stateful integrations (stateful means I have to count requests were made, store session token, etc. on my side). My first naive implementation have all this fields as fields of defrecord
and each time I made request to external system I returned new instance of this defrecord
. Problem here, that I have to care about it, it looks like
;; main atom
(def sessions (atom {}))
;; init client session
(swap! session assoc :session-key (new-sabre-client))
;; run request to external system
(let [{:keys [client response] (invoke (get @sessions :session-key) {:param :param})}]
(swap! session assoc :session-key client)
response)
I want to use simple interface like:
;; Difference here is that defrecord is not changing
(let [session (new-sabre-session)]
(invoke session {:param :param})
(invoke session {:param :param}))
So, here is the question: is managing state in external atom like structure is good idea?
or may be using deftype
with mutation, will be good idea, just update session-info after each call
Joy of clojure says: “We won’t go into it here because using such classes is almost never the right solution"
I think the trend of managing stateful resource is using things like Component/Mount over atoms (Of course I am blindly assuming you don't know them... Sorry if you know already...)
Yea, I know about them however I can’t imagine how use them here. My problem is that calling method of some defrecord
shoud return some value, and it also changes defrecord
at same time
so, return map with two items (new defrecord and value of method) seems too ugly for me
because I need to replace old defrecord with new one, after each function execution
Guy sitting next to me (Expert) says Atoms are a good idea, (should start/stop with component, however) so I guess you are on the right track on that part...
so, let’s suppose we have an atom, we generate session-key there as key and consider it as defrecord
each time I call invoke
I have to swap! session-key with new state of my connection
defrecord will be as constant, but whole state will live in atom associated with session-key
@rmuslimov : can you create a function that returns a function that closes over the atom?
@fiddlerwoaroof: I cobbled together something to auth against google using openid recently. Friend and buddy are clojure libraries that want to help with that, but I found that using open(id|auth|connect) requires such integration with your web routing and persistence layers that it’s both easier and simpler to roll your own. Failing that, you might also consider auth0 or a similar service.
@iku000888 nw, thank you
@rmuslimov : If I were approaching the problem my first pass would be creating a function that is bound to lexically closed over atom. In that way there is no real global state you can point to, you just have a function that updates the closed over atom.
@rmuslimov : it should still work, finding the right boundaries for function composition might take a few refactors. In the good old days of CLISP this type of solution was quite common.
yw — I hope you find a solution that works for you. Good Luck.
Hi, I am getting started with Boot and I was curious if there is a way to create new project with boot similar to lein. Thanks!
Thanks @shaun-mahood
is there a reason to use a record over a plain map if you're not supplying any implementations: like (defrecord Foo [a b c])... because if i use the nonpositional map->Foo it doesn't enforce that keys have to exist or that extra keys can't exist
is there another construct that gives you a guaranteed keyset and ignores keys not in the set?
ive hacked something like this to strip extra keys
(defn make-image [image-map]
(-> image-map
(select-keys (map keyword (Image/getBasis)))))
@olslash This blog post (and flowchart) helps fill in the motivation for different Clojure types https://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/
what would be the way to test whether a string is "printable" in clojure ? as in, whether it contains only ascii/utf-8 characters ?
@lmergen wouldn’t a string be “printable” if theres a typeface that knows how to print it?! Are you trying to figure out if it only contains “English” chars?
@pastafari i'm trying to do http request/response body logging, but i do not want to log binary data
i could check for a gazillion of content types, but i'd rather just have a simple predicate
ah wait, i can probably use a fancy string lib like funcool/cuerdas for a useful predicate
@lmergen also do go through https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
and i always re-read Joel Spolskys blog when dealing with strings: http://www.joelonsoftware.com/articles/Unicode.html
haha yeah, this is exactly why i wanted a better way to distinguish "real" binary data from readable text in some weird character encoding set
One question. I m trying to make a program which reads data from 3 external urls. The last two depends on numbers(ids) I read from the first url. Is it wise to store the data in a record. And how to a update a record with the new data I recieved from the last two urls
here’s a sketch:
(let [foo (ids-from-url url-1)
bar (fetch-url (url-2-from-ids foo))
baz (fetch-url (url-3-from-ids foo))]
; do something - perhaps return a map like {:foo foo :bar bar :baz baz}, or something else
)
i don’t know if a record is necessary - you can certainly use one if you want but i’d personally store them in a vector, like [an-id another-id a-third-id]
, because that seems simpler to me
i may have misinterpreted what you meant by “the data” - on rereading your question, i think you meant all of the data, not just the ids from the first url
I need for every painting this data : id, title, description, date, collection, colors and a url where a image can be found
i think i follow - if it were me, i’d use a map and clojure.spec
, but you could also use a record - if you wait to create the record until you’ve got all of the necessary data, it should be pretty straightforward
i don’t use records often, so i don’t have a good answer for your question of how to update a partial record with new data, sorry!
@roelofw Did you see this message I posted earlier? https://clojurians.slack.com/archives/clojure/p1480394579017686
That gives you good advice on whether a record is necessary (from what you've described, I'd say "no" in your case).
Sorry . I missed it . Thanks for posting again @seancorfield
@seancorfield oke, from that it seems I need a map
so I think It would be somethlng like this ( { id: 1 { :title "my own painting :date 21-01-2010 ,,, } id : 2 { .... } })
and so on
@seancorfield is this a right idea ?
@roelofw: map of map is good if you're looking things up by a specific key, vector of map is good if you're filtering by some predicate.
If you mostly just need a collection of paintings then vector of map is probably sufficient. You can always build a map of map from it if you need key-based lookup as well.
Past my bedtime but I'll be around tomorrow to answer questions :)
Do plugins have access to namespaces in the project they are required? I want to create a plugin to output JSON from a var defined in the project.
I think the answer might be "No" because I get java.lang.Exception: No namespace: foo found
for ns-resolve
when run as plugin. It works when run as a lib.
Found this which seems relevant, but it still doesn't work: https://github.com/technomancy/leiningen/blob/master/doc/PLUGINS.md#evaluating-in-project-context
I've created a sketch of what I want to accomplish: https://github.com/creese/lein-avro-compose
Hello all, is there any way to use eval passing local variable ?
(let [variable "string"] (eval (read-string "(println variable)")))
?@fabrao There is other people here who know the glory details as to why, but: You can't access those local bindings (created with let
), but you can access vars, so you could use with-local-vars
The treading macro ->> is misplaced within the anonymous function #(...), try making a function (defn read-single-painting [id] .. get http req ..) and use that within read-daata_painting. That way you an check that read-single-painting works, before putting it in the map
Also you are mapping the result of (println ....)
which is nil
over no collection (thus resulting in a transducer) and simply returning id_list
as your parens are in the wrong place.
did anyone tried to have round-trip of keywords as value in a map while serializing/deserializing json with cheshire ?
@yenda, the problem to watch out for is that keywords can contain spaces, but keyword literals (`:my-keyword`) do not
but your use case doesn't sound like it would be affected by that
also when keywordizing values (as opposed to keys), you usually don't want to keywordize all values, e.g. there may be a name or description attribute that should always be a string
I used a custom encoder to keep the semi-colon when encoding keywords but there doesn't seem to be a way to do the same to decode strings
Hello guys, does anyone have this two information concerning Stuart Halloway core.async youtube video => 1) Where are the slides ? 2) What tool does he use to draw process diagrams (around 46 min)
I’m not watching the video but I’d bet some money that the tool is omnigraffle
ok, I'll have a look then
slides are at https://github.com/stuarthalloway/presentations/tree/master/PhillyETE_2015 I think
great !!!
@alexmiller it is OmniGraffle 🙂
why most of known clojure programmers use Mac? :thinking_face:
at least most of those who give talks...
I think most programmers who give talks use macs these days, unless it's a .NET ecosystem talk/meetup/conference
but personally I get really excited when I see someone giving a talk with live coding on a Linux box!
@bfabry really? I never watched any ruby talk...
@saeidscorp I think it's holdover from the days where running Linux on a laptop was a huge risk (most stuff didn't work) and OS X is more Unix than even Linux is. So since most production servers were Linux it was simple enough to code on OS X and deploy to Linux.
I love my Mac Book Pro, but the new hardware is crap, so we'll see what happens next time I need to upgrade. I just wish I could get MBP quality hardware with Linux pre-installed and fully supported.
aside from that risk, which was really a risk those days, OS X is not much unixy, I think. yes it's based on unix but that freedom in not present in its philosophy. Linux? you can literally do whatever you want with it. 😁
it's close enough to make building for linux on a mac feasible unless you're using linux-specific stuff. There are always VMs too anyway. I like the build quality of MBPs and using Windows feels like using a rube goldberg machine sometimes
@saeidscorp it comes with a bash terminal and a unix-like fs, which is about 90% of what programmers are looking for
our codebase at work is C++ with support for macos/linux/windows/android/ios, we do all of our development on macs because they give us the least amount of headaches.
And it matters even less with Clojure where the JVM is involved. I've worked on systems were we developed on OSX and deployed to Solaris. So for me it's always come down to the features Apple provides with their hardware. Now that they're taking that away I may switch.
If on the other hand they released a MBP with a recent CPU/GPU and 32GB ram, I'd be all over that. Touch bars, mobile GPUs, etc. Not so much.
:thinking_face:
Although @saeidscorp I have to mention....OSX is Unix, Linux isn't 😉
and perhaps we should move this to off-topic sometime soon.
Yeah i think if I could find a PC laptop with good build quality I would run Linux on it instead of OSX. Not sure what's out there though, seems like every time I look at PC laptops they feel so flimsy.
ThinkPad hardware quality is still very good and hardware is well supported in Linux. Most ThinkPad models are even certified for Ubuntu & available pre-installed with Ubuntu somewhere (haven't seen in EU though)
surface line is awesome, and i’d switch my main dev machine from osx as soon as they release a quad core surface book
if I had the option I'd be tempted to go back to thinkpad+ubuntu for my next laptop, as I'm not super impressed with apple's hardware choices lately. but, I don't have the option, and honestly it doesn't bother me much
I was a thinkpad person for years but since I started using an xps13 (sputnik) I am not looking back
Looking for a lib that provides interpolation from map keywords like HugSQL uses for SQL queries. Something like: (fill-in “name=:name,password=:pwd,host=:hostname” {:name “Bob” :pwd “secret” :hostname “localhost"}) Google does not turn up anything obvious. Anyone?
I have an extra ClojureX London 2016 ticket for sale for the conference at Skillsmatter on 1st and 2nd December this week . It's on sale for the early bird price of £95. Would prefer a Paypal payment. Contact us if you're interested
I need to get all of wikipedia as raw text in clojure. I know that there are db dumps available at: https://dumps.wikimedia.org/ -- my question is: are there any java / clojure libraries for converintg the wikimedia markup to plain text?
looks like it's all written in java to start with https://www.mediawiki.org/wiki/Wikidata_Toolkit