This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-29
Channels
- # admin-announcements (48)
- # announcements (1)
- # beginners (80)
- # boot (150)
- # cljs-dev (12)
- # clojure (133)
- # clojure-dev (1)
- # clojure-italy (27)
- # clojure-japan (1)
- # clojure-russia (77)
- # clojurescript (236)
- # clojutre (3)
- # code-reviews (1)
- # core-async (14)
- # core-logic (4)
- # core-matrix (15)
- # cursive (5)
- # datomic (30)
- # editors (16)
- # events (1)
- # hoplon (1)
- # ldnclj (17)
- # off-topic (30)
- # om (2)
- # onyx (47)
- # reagent (8)
malcolmsparks: I’m recommending json-mode for emacs. It’s really helpful
is there any function for alphabetically sorting strings ?
@nicola: do you use cheshire?
(add-encoder schema.utils.ValidationError
(fn [validation-error jsonGenerator]
(encode-seq (s-utils/validation-error-explain validation-error) jsonGenerator)))
[schema.utils :as s-utils]
[cheshire.generate :refer [add-encoder encode-seq encode-str remove-encoder]]
@nicola: https://github.com/dakrone/cheshire#custom-encoders pretty nice stuff
@mitchelkuijpers: cool it works!
@nicola: good to hear
@lowl4tency: thanks!
@lazy-lambda: sort
works on any Comparable type, including String.
I'm baffled and I have to be doing something wrong here… I have a postgres database and a table with a column type of "DATE". I'm using clj-time
and clojure.java.jdbc
and I'm attempting the following:
(jdbc/insert! conn :table_name
(assoc attrs :effective_date (-> "2015-08-29" format/parse coerce/to-sql-date)))
ordinarily, I would say: "timezone issue", but it's a date and this seems to happen both early in the morning and late at night (I'm in MDT)…. so it seems like a poor fit for that.
This is because the date is interpreted in local time, and when it is converted to database compatible format, it wil surelly converted to UTC...
sorry, I have that backwards, it's:
(if-let [dt (to-date-time obj)]
(java.sql.Date. (.getMillis dt)))
So if yo pass it to utc, it just substracts the timezone offset and stores it in a database.
If you want store a naive date (in local time and without timezone) you should interpret your input as UTC, and then store it in a database..
Here's a question about NRepl. I'm doing something unfortunately tricky where I need to know when a WeakReference is only weakly referenced.
The idea being that when token is no longer referenced, I can set the flag that terminates the started thread.
Context: this is about starting a thread "on the side" for a Ring handler, and knowing when to shut down the thread because the entire Ring pipeline has been GCed.
What I'm seeing with VisualVM is that even after I (def token nil), there's still a reference to the token.
hlship: hmm, could it be in *1 or *2 etc?
just a wild guess
(format/parse "2015-08-29")
-> #object[org.joda.time.DateTime 0x76471283 "2015-08-29T00:00:00.000Z"]
(java.sql.Date. (.getMillis (format/parse "2015-08-29")))
-> #inst "2015-08-29T00:00:00.000-00:00"
Hm. I may just be barking down the wrong path. I've used a (let) so that token is only held for a short time, and my WeakReference is still not triggered.
Ok, I have a solution for my issue, but it involves a finalizer. Not happy about that, as finalizers are even chancier than WeakReferences.
so the workaround (which I don't feel great about) was to change the type of the column to a TIMESTAMP… I'm still dealing in dates in the UI, so the extra precision does me no good, but suddenly the same code works
seems like a bug, though I'm not sure where it is… guess I'll file against clj-time
and let them kick it back 😐
niwinz: rolling back my schema change and executing the following:
(jdbc/insert! conn :table_name
(assoc attrs :effective_date (-> "2015-08-29" format/parse-local coerce/to-sql-time))))
@hlship: this could be due to http://dev.clojure.org/jira/browse/NREPL-36
half-baked theory: that fn (compiled to a class as usual in clojure) references its classloader, and has closed over your Token?
An other option is indicate to the database that you are using UTC, so no any conversion will be done
huh, interesting. I'm using hikari… I'm curious how that affects connections in a pool though.. I don't want every query against that connection to use UTC
Since (I don't remember clearly) django 1.5, the default interaction with database is set to utc
(I'm also have worked with django in python, and I know that kind of issues from python)
kay… my test suite may save me here, but making that change will definitely make me want to do some thorough QA. I'll take a look into it though.
I wondered if anyone could give me ways to improve this small piece of code? https://gist.github.com/jamesmintram/232849395526ce9ca581
@voxdolo: Thanks - didnt realise that channel existed
Doing web stuff with Clojure? You might want to check out the latest release of Twixt 0.1.17 https://github.com/AvisoNovate/twixt/blob/master/CHANGELOG.md -- Twixt is an asset pipeline for Clojure web applications. It takes care of just-in-time compilation and transformation, letting you write CSS (as Less), HTML (as Jade), and JavaScript (as CoffeeScript) and a bunch of other useful stuff.
When using honeysql, are you supposed to have all this boilerplate: (clojure.java.jdbc/query db-spec (honeysql.core/format (honeysql.core/build :select 1))) just for running “SELECT 1” or am I missing something here?
I think it's actually a good approach, baking everything together often ends up with lots of tradeoffs, that said if your "client" library exposed a query wrapping step (ex via a protocol you could extend it to compile on demand (possibly cache etc etc)
https://github.com/mpenet/alia works like this but it's for another db "family", it can take string/java instances (bound, prepared, simple etc), and a clojure dsl and do the compilation internally
Well, since normally what you want to do with SQL is execute it, doing connection management in the SQL library makes sense to me… you know, so that the common tasks of connecting to the database, keeping some global connection that is automatically referred to and so on is abstracted away in a library instead of having to write it from scratch.
well relying on some global state is kind of hairy, but again, it's easy to write a super thin wrapper to do what you want mixing whatever libs you like for each task
@mpenet: it doesn’t look easy to me as I don’t know what’s the appropriate way of handling connections… you just mention, global state is hairy.
just pass it as an argument to your functions, could be done via a component for instance
mpenet: I don’t know what you mean by component and I still don’t know when/how to connect.
pupeno: check https://github.com/stuartsierra/component and related articles, that should help you getting started for these kind of things
If you need core.async error handling in Clojure(Script) I have 0.1 of https://github.com/alexanderkiel/async-error
I can see that Clojure is a productive language, but it feel there’s a philosophy of providing libraries in vacuum. How is a developer supposed to get from https://github.com/jkk/honeysql to https://github.com/stuartsierra/component and I still haven’t managed to connect to the database. I really want to switch my company to Clojure but it feels everything is unfinished by design. 😕
Mh, Luminus seems to be wiring clj-dbcp.
@pupeno: do you refer to the fact hat the Clojure universe likes to provide small libs rather than frameworks?
@akiel: no, that is fine. Look at this library for doing SQL from Python: http://www.pythoncentral.io/introductory-tutorial-python-sqlalchemy/ it has a function/method to connect to the database and the tutorial shows you how to. The HoneySQL tutorial doesn’t even mention the word connect.
pupeno: clj-dbcp and clj.jdbc provide more or less the same functionality, they're not going to give you a sql dsl
mpenet: I know, they are the other side of HoneySQL.
akiel: HoneySQL is obviously just one library… my problem is that I’m encountering this all the time and I’m concerned about the impact it’ll have on my developer’s productivity.
@pupeno: honysql is only about a SQL DSL not about connecting to your database - and in my opinion you should use https://github.com/krisajenkins/yesql instead
pupeno: there are libs like what you mention in clj, one ex is Korma, but it's not what the clj users would advise to use
well it demands to write a 3 line function to wire the 2 libs, I wouldn't think it makes you unproductive
mpenet: I know about Korma. I spent about two weeks working with them to get them to accept a pull request so it would connect using a database URL so that it would work on Heroku.
mpenet: not having to chose is faster than chosing. And the wiring that I’m seeing in Luminus is way more than 3 lines of code.
I don't know about what luminus is doing, but it requires very little time/effort to achieve, that's a fact
mpenet: it’s not my intention to flamewar, but stuartsierra’s component examples are way more than 3 lines of code.
it's a nice approach, but writing a function that takes a connection and a query representation, compiles the query and runs the query against a connection is small
mpenet: oh yes, that function is trivial… again, my problem is when/where to connect. I’m not familiar with the thread/process model of JVM and Clojure enough to make decisions about how to handle the connection.
A lot of people recommended yesql… my initial worry is that you either end up with a gazillion update functions or an update functions that update all the fields. Maybe I’m worrying over nothing but ActiveRecord, Rails’ SQL DSL, only updates the fields that changed. Is this a non-issue?
@pupeno: you need at least a connection pool - but I do not really use RDMS anymore from Clojure so it’s not obvious for me what to use
@akiel: I think I’ll just use it since it’s in the new version of Luminus. I’m curious though, what do you use?
Storm seems to have some issues if you use clojure > 1.5.1 ... very aggravating. I'd love to be wrong about this but I don't think I am.
I have a vector [“x” “y” “z”]
, now I want to find the th of the element in the vector which is equal to say “z”.
This is very easy with a loop, but is there any function ?
@lazy-lambda: what do you mean "the th of the element"
@lazy-lambda: if you mean index, you can use java's .indexOf e.g. (.indexOf ["x" "y" "z"] "z")
I was meaning index
no loop required!
@bostonaholic: @antishok Awesome ! I was looking for something like this.
@lazy-lambda: next time, you can search for methods on the vector by (javadoc clojure.lang.PersistentVector)
and if you're unsure of the class, you can (class [])
I'm very interested in the direct linking option, however! Seems like something I'd want disabled during REPL oriented development though ... perhaps something that should only be enabled for AOT? But then, I start having the misgivings of what I use & test not matching what I put out for deployment.
yes, you would likely not use this at dev time, then enable it when you build a jar
a key aspect of this is that compiled code retains both the direct (static) and indirect invocation paths - it is the choice of the caller which to use