Fork me on GitHub
Kira Sotnikov09:07:16

malcolmsparks: I’m recommending json-mode for emacs. It’s really helpful


Hi, is there simple way to convert schema.utils.ValidationError to json?


Or more general, convert deftype to hash-map?


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]]


just wondering if anyone has tried integrating clojure with vaadin/zkoss


if people have though about it but decided against it, I’d like to know why not.


zcaudate: datomic console is Vaadin


@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 and I'm attempting the following:

(jdbc/insert! conn :table_name
                      (assoc attrs :effective_date (-> "2015-08-29" format/parse coerce/to-sql-date)))


The date reflected in the inserted table is "2015-08-28"


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...


2015-08-29 is interpreted as 2015-08-29T00:00:00 ...


clj-time uses java's .getMillis on a java.sql.Date object


right, that's what I'm seeing


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.


bother. One would hope that making it of Date type would dodge that 😕


I get it though, days are affected by TZ as well…


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..


okey-doke. Thanks niwinz.


Here's a question about NRepl. I'm doing something unfortunately tricky where I need to know when a WeakReference is only weakly referenced.


So (def token (start-thread-etc ...))


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.


So is that the case? And if so, what's the purpose of it, and how can I clear it out?


hlship: hmm, could it be in *1 or *2 etc?


just a wild guess


interesting idea, let me try ...


Tried typing nil to the command line a few times


that does not seem to affect it


niwinz: clj-time's parse parses into UTC, so I don't think that's it


(format/parse "2015-08-29")
-> #object[org.joda.time.DateTime 0x76471283 "2015-08-29T00:00:00.000Z"]


very strange!


I'm guessing the coercion of clj-time.format/to-sql-date is killing that somehow?


that seems like a thing that I would not be the first to see though


(java.sql.Date. (.getMillis (format/parse "2015-08-29")))
-> #inst "2015-08-29T00:00:00.000-00:00"


looks to have dropped the timezone


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.


Fortunately, the functionality in questions is just for development mode.


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 😐


can you try use java.sql.timestamp


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))))


I still see the date in the database as "2015-08-28"


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


I do care about TZ in other parts of the app


@voxdolo: interacting with database always in UTC is very good practice....


the timezone should be part of presentation only


ideally, yeah


fair enough… that's a potentially systemic issue.


hi mikepence simple_smile


hey voxdolo. congrats on the baby!


Since (I don't remember clearly) django 1.5, the default interaction with database is set to utc


(small worlds and thanks)


(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.


thanks for bouncing around ideas niwinz simple_smile it's much appreciated.


you are welcome!


I wondered if anyone could give me ways to improve this small piece of code?


jamesmintram: you might try over in #C053PTJE6


@voxdolo: Thanks - didnt realise that channel existed simple_smile




Doing web stuff with Clojure? You might want to check out the latest release of Twixt 0.1.17 -- 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.

Pablo Fernandez20:07:35

When using honeysql, are you supposed to have all this boilerplate: ( db-spec (honeysql.core/format (honeysql.core/build :select 1))) just for running “SELECT 1” or am I missing something here?


it's "just" a dsl to generate string queries, so yes.


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)


maybe something worth suggesting to

mpenet21:07:46 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

Pablo Fernandez21:07:10

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

Pablo Fernandez21:07:50

@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

Pablo Fernandez21:07:13

mpenet: I don’t know what you mean by component and I still don’t know when/how to connect.


(execute (:connection component) "select * from foo;" ...)


pupeno: check 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

Pablo Fernandez21:07:04

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 to 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. 😕

Pablo Fernandez21:07:35

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?

Pablo Fernandez21:07:39

@akiel: no, that is fine. Look at this library for doing SQL from Python: 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

Pablo Fernandez21:07:27

mpenet: I know, they are the other side of HoneySQL.

Pablo Fernandez21:07:43

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 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


and you have the flexibility to pick and choose the best tool for your task

Pablo Fernandez21:07:12

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.

Pablo Fernandez21:07:48

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

Pablo Fernandez21:07:11

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


component gives you dependency injection, and a nice abstraction to go a lot further


but you don't have to use it

Pablo Fernandez21:07:46

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.

Pablo Fernandez21:07:06

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

Pablo Fernandez21:07:39

@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?


I use Datomic


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 [])


1.8.0-alpha-3; I'm curious what the tuples & performance impacts story is.


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.

Alex Miller (Clojure team)23:07:09

yes, you would likely not use this at dev time, then enable it when you build a jar

Alex Miller (Clojure team)23:07:37

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