This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-15
Channels
- # admin-announcements (60)
- # adventofcode (37)
- # beginners (53)
- # boot (94)
- # bristol-clojurians (1)
- # cider (21)
- # clara (19)
- # cljsrn (1)
- # clojure (222)
- # clojure-chicago (1)
- # clojure-dev (2)
- # clojure-nl (11)
- # clojure-russia (301)
- # clojure-turkiye (1)
- # clojurecup (6)
- # clojurescript (30)
- # core-async (3)
- # cursive (64)
- # datascript (2)
- # datomic (55)
- # devops (16)
- # editors (1)
- # emacs (16)
- # ldnclj (6)
- # off-topic (18)
- # om (113)
- # onyx (3)
- # parinfer (1)
- # proton (48)
- # re-frame (20)
- # reagent (7)
@a.espolov: that structure you posted wouldn't compile.
Also, you can sort it like this;
(sort-by (comp :c :b :a) [{:a {:b {:c 1}}} {:a {:b {:c 0}}}])
(->> inspection-by (when (not (nil? (:sorting params))) (sort-by (comp :promo/name :inspection/promo)) (when (:value (:status (:filters params))) (filter #(= :inspection.status/unverified (:inspection/status %)))))) this way it’s ok?
@a.espolov: it's trying to substitute it into the first argument of the when
additionally, even if this were to work, if (:sorting params)
is nil, then the when will return nil and pass a nil down to the next function which is probably not what you want to happen
sorry - trying to put it in the last argument of when. try running a macroexpand on it
(macroexpand-1 '(->> inspection-by
(when (not (nil? (:sorting params)))
(sort-by (comp :promo/name :inspection/promo))
(when (:value (:status (:filters params)))
(filter #(= :inspection.status/unverified
(:inspection/status %)))))))
@dmitrig01: if usage “when” for run sort-by or not run then throw exception
@dmitrig01: whether you can use a macro - >> and functions at a branch of a chain of function calls?
Hi everyone, new to Clojure and hoping to make a website for a friends nonprofit using it
I'm working my way through the clojure for the brave and true and as a Java developer it's just very hard to grasp the recursion and functional programming, very frustrating!
joshua.d.horwitz: keep at it brother. your brain will be taffy for a little while, but it will click.
In the same boat myself, @joshua.d.horwitz It gets easier fast! Not that I understand any of the "advanced" topics like macros... but after a month I can get some stuff done, at least.
@polymeris: What are you using to learn?
Tool-wise, I am just using IDEA with the cursive plugin. Learing emacs alongside clojure seemed like too much
once it finally settles into place youll want to write everything in clojure
Is this one : http://rundis.github.io/blog/2015/buddy_auth_part2.html a good example how to make autherisation work ?
@polymeris: I might get the Joy of Clojure....think it adds anything that you don't get from Brave and True?
Shows you how to intermingle code/data early on, close over to create 'functional objects' (my expression). It is the first time I really saw what persistent data structures are.
Hopefully someone from the Clojure core team hangs out here, because I suspect they'd be best-placed to answer: I'd like to port clojure.tools.cli to Pixie (https://github.com/pixie-lang/pixie), and I want to make sure this is OK before pushing to GitHub.
If my reading of the Eclipse Public Licence is accurate, it seems that as long as I EPL derived code and preserve the contributors notice from the original, it should be legal to do.
However, I want to also make sure that it is in the spirit of the Clojure community before proceeding.
My feeling is that it benefits Clojurists to provide familiar libraries in Pixie, so when Pixie is a better fit than Clojure (shell scripts and other places where JVM startup time or memory overhead all but rules out Clojure), there is very minimal friction to being productive.
I think somebody started a cli lib for pixie recently tho, you might want to check it first
-> https://github.com/thomasmulvaney/invoke, but it's in a very early stage actually
Also, some people don't like the EPL since it forbids them to release code as GPL, so there's that to keep in mind.
Pixie is LGPL so I see no problem with the languge itself, but it's still might be a valid point nonetheless.
@pesterhazy: did you try using a profiling tool to see what the garbage is? I guess this could lead you to it's source originally, the garbage fountain.
garbage fountain? is that an expression?
well, "profiling is hard, let's go shopping"
I upgraded the ec2 instances and tripled the jvm heap, that seems to have fixed the issues
> I upgraded the ec2 instances and tripled the jvm heap, that seems to have fixed the issues lol 😄 garbage fountain was made up. 😄
@pesterhazy: it's not that hard really
It's decided then. From now on, the cause of GC issues shall be called the "garbage fountain".
naive question, with Hiccup markup would it be possible to generate HTML like “foo <span>bar</span> foo” or are you always locked to the “<span>foo</span><span>bar</span></span>foo</span>” structure?
I’m trying to get sort of XML flavored annotations of text
ah I guess it’s possible, it takes varargs
@joelkuiper: that's right. If all your spans are sitting in a div, you could get your original html with [:div "foo" [:span "bar"] "foo"]
.
Question for the database guys: What tools are Clojurians using to manage the shape and versioning of a large central Postgres database, e.g. for retail operations? My new junior hire is a Python guy and we have to make some tech decisions. Naturally, he would like to use SQLAlchemy because that's what he knows, but my experience with ORMs has been mixed. Rightfully he wants to reach for something familiar, but I would rather stick to Clojure. HoneySQL seems like the most sane query library, but it doesn't seem to be focused on migrations and a code first approach to maintaining the DB. Any advice? Appreciate it.
For migrations you have a few choices - ragtime (migrations with plain sql), joplin (based on ragtime but extended to non-sql databases and gives you ability to write code-based migration which can be useful), lobos (which is probably the most similar to Rails migrations), migratus (which looks similar to ragtime) or you can use Java solutions - liquibase or flyway (there should be some wrappers for those around).
maybe a off-topic question : I wil use yesql for my project but now I have to learn sql. Can someone recommend a free online course to learn it good and fast ?
@roelof: you could try starting with http://sql.learncodethehardway.org/
I really like the feedback kibit is giving me, just caught an (= .. ..) instead of (is (= .. ..)) in my tests
@borkdude: I didn't realize that kibit could catch something like that
@bostonaholic: apparently it has improved over the years
here’s an interesting interview type question 😛 given a sequence of pairs (e.g. [[1 2][4 10][5 10]] remove the overlapping pairs, (e.g. 4 10 in this case)
currently I’m sorting on the first element and then filtering statefully, but maybe there’s a more elegant solution
ie. there is a list of pairs, possibly unordered and "overlapping" means here that union of ranges produced from those values is non-empty? Are the ranges open or closed? (I'd guess closed, so that [5 7] [7 8] would overlap, but unsure).
Is there anything to gain from defining a protocol with the same methods as an existing java interface?
they’re closed indeed, the concrete use case are annotations of text, where we want to highlight the longest match only
@cddr it can be extended to other types that don't implement the interface
@borkdude: I'm not sure, but that may be the Eastwood linter giving you that warning, not kibit
Eastwood can definitely do that, and squiggly-clojure uses Eastwood by default, I believe.
@joelkuiper: I actually had that use case with dates (ie. ranges of dates, want to know the full "occupied" slots list)
right that’s very similar!
@joelkuiper: overlapping on the first or the last?
@joelkuiper: Not really practical to implement for an interview but an approach for large amounts of pairs would be a tree like an https://en.wikipedia.org/wiki/Interval_tree
both or either, [[5 10][4 9]] should return only [[5 10]], [[5 10][4 10]] should return [[4 10]], etc
yep interval tree is the “proper” solution I guess, but it’s as you say some work
and the library implementations are a bit lacking 😛
it’s a fairly common problem with dates and text spans too
I'd probably sort by range start, then do a sliding window with partition
and fold over that either adding a new value if ranges are disjunct, or substituting the last one if they are not.
that might make sense
I think 😛
(let [filter-dups (fn [f coll] (map first (vals (group-by f coll))))] (->> [[1 2][4 10][5 10][1 4]] (filter-dups first) (filter-dups second)))
one of my very first pieces of Clojure : https://gist.github.com/nha/f1474c905b38a7bf5466
Anyone a example of the code how to add a user to the database with luminus. I have read the docs about it on the luminus page but it's still not clear to me
(let [values [[1 2][4 10][5 10][1 4]]]
(as-> values $
(sort-by first $)
(reduce (fn [[[last-start last-end] & rest :as acc]
[new-start new-end :as range]]
(if (<= new-start last-end)
(cons [last-start new-end] rest)
(cons [new-start new-end] acc)))
[(first $)] $)
(reverse $)))
Does something exists in Clojure to parse strings ? Something like : (parse "the app is live" "the app is %status") ;;=> {:status "live}
Though you could probably write it yourself with a regexp
No one who has a example of code for adding a user with buddy. I try to make my first web site and this way its very frustating
@nha you can do that with the text formatter/parsers in the jdk
@alexmiller: you mean like jsapar ?
@nha look at MessageFormat and it's parse methods http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html#parse(java.lang.String
@alexmiller: Thanks
I'm sure there are other libs. I don't know anything about JsaPar
there is also regex support which is fairly well integrated in Clojure
and then of course various Clojure parsers too
@joelkuiper: If the list is ordered by the first number in each pair then you can use reduce
. If it isn't, then you can order it and use reduce
Is it possible to use test.chuck's checking
macro to refer to other generators? The goal is to use test.check
's bind
generator: https://github.com/gfredericks/test.chuck/blob/master/src/com/gfredericks/test/chuck/clojure_test.cljc#L97
this was posted today https://adambard.com/blog/clojure-auth-with-buddy/
oke, I cannot find out if a new person register in my new app. How I store the data in the database. I can find the data the user has added but how do I take care that the password is not stored in plain text and how do I store in in the h2 database
Really, buddy has really good documentation. I think friend is cryptic compared to that.
you want something like this https://github.com/krisajenkins/yesql#insertupdatedelete-and-more
or can I use this example : https://github.com/rundis/acme-buddy/blob/Part_1/acme-auth/src/acme_auth/store.clj
I have a function that takes named arguments like this: (defn f [& {a :a b :b}] [a b])
. I have a map {:a 1 :b 2}
. How do I call f
with the map so that the result is [1 2]
?
Here's one sample implementation - https://github.com/mikera/clojure-utils/blob/develop/src/main/clojure/mikera/cljutils/core.clj
Maybe kwargs looks slightly cleaner - two curly braces less, but handling them seems unwieldy to me.
(defn f [& {:keys [a b]})] [a b])
?? is that what you wanted? Then you can do (f :a 1 :b 2)
?
Not being able to apply kwarg functions easily is basically what turned me away from them.
In Ruby you can do function(*array)
or function(**hash)` to apply array and hash respectively.
Can I extract through destructuring just one value from the map and still get the rest or all of the original map?
I'm not so sure if that was recently, since I've seen it a while back, but yeah, I've seen the tweet. He's a smart guy with all that Jepsen stuff and I kind of agree.
@mbertheau: yeah, use :as something
inside the map pattern
Thanks. https://gist.github.com/john2x/e1dca953548bfdfb9844 seems to be a good cheat sheet on destructuring.
@roelof: which one? The one by rundis? It's ok, but it uses JWT so you might be a bit confused by that if you want to do a website.
Someone posted this above - https://adambard.com/blog/clojure-auth-with-buddy/ There's also this - http://kendru.github.io/restful-clojure/2015/03/13/securing-service-restful-clojure-part-4/ (as linked in the buddy readme
@mbertheau: that looks handy, I usually google and end up here when I need to check something - http://blog.jayfields.com/2010/07/clojure-destructuring.html
@jaen thanks . The kendru tutorials looks very good. When I do it from part 1 Everything is build up, Thanks
A) sort of
B) I'm not using it just yet
C) But I will definitely switch to that
so once I do, you can send coded messages to each other that I can't decipher by using gifs
emacs doesn't support slack directly, slack supports irc
@gfredericks: Heh, hello. Thanks for the advice
how do the insert user looks like when I have a file in resources/sql which contains the insert sql command. I work with yesql
Anybody know what’s wrong with clojars? No responce from site, could not fetch deps also
Normally you would do something like this `(defn add-user []
(database (connection) "xxx")
@roelof defqueries builds a function for every query it found on the sql/queries.sql file. Also, If you pass the connection parameter, the functions won’t need to be called with a connection argument every time. Every query in the file must have a name, which will be used to call the function that execute that query. If you have a SELECT query named select-item-by-id with one parameter named id, you must call that function like this: (select-item-by-id {:id id})
Remember that you need to name your queries using a comment line that start with the text: — name: name_of_my_function.
@rcanepa oke, so I can do like this ` (defn add-user[user-record] (insert-user(user-record] where users-record is a map with all the data entered in the form
You have to make sure that your map contains all the parameters you specified in the SQL query.
Any ideas on how to reduce (heh) two transducers into one? I currently have one transducers in which the reducing function calls another transducer. It is this way because I have sequences in sequences which in each 'level' needs to be reduced.