Fork me on GitHub
#clojure
<
2016-08-01
>
udhan04:08:57

Hi, I am facing really weired issue. Maybe i am trying something very stupid

udhan04:08:38

Here is piece of code

udhan04:08:42

Works fine if i make a post json request

udhan04:08:53

{ "text": { "text": "some text" }, "_id": "579ec8fd6c6f8134d72a14cd" }

udhan04:08:11

but if I try to access the key, i.e. text , its null

udhan04:08:40

I checked the type of bdy and its PersistentArrayMap

udhan04:08:20

Any help is really appriciated

udhan04:08:10

application uses liberator, compojure and monger

udhan04:08:01

if I directly use bdy as in first snippet, it adds entry in mongodb correctly. however if i try to read property of the body and add (e.g. by replacing {:text bdy} by {:text text}, :text is added as null

Chris O’Donnell04:08:52

@udhan: Is the key in your bdy map "text" or :text?

udhan04:08:37

I am assuming json/read converts string keys to keywords, however i tried both

udhan04:08:33

my request post body is simply

udhan04:08:36

{ "text":"some text" }

Chris O’Donnell04:08:29

can you print/log bdy to see what's actually in there?

Chris O’Donnell04:08:41

anyways, was just a guess as I head to bed. good luck!

udhan04:08:41

logger returns {text some text}

udhan04:08:10

sry I had to set logger as app wasnt printing anything on console

udhan04:08:30

@codonnell: no problem. Gn!

seylerius05:08:38

What's the best way to remove all keys but a specific few from a map?

seylerius05:08:16

Oh, select-keys

yonatanel07:08:47

@pesterhazy: regarding coercion, let's take simple example of transforming {:a name :b age} to {:a age b: name}, but not manually, because I want all the good stuff that Schema gives me, like validation and handling more than this one example.

maxim09:08:05

Perhaps this is a bug in clojure/data.json: When I convert / to json in Ruby I get this "/".to_json #=> "\"/\"" When I do the same in Clojure I get this (json/write-str "/") => "\"\\/\"" And when I apply Base64 encoding to the outputs I get different results as well. Am I missing something?

maxim09:08:42

I'm trying uploading files to AmazonS3 from front-end. In order to do that I need to generate a base64 signature. And the signatures based on data which includes pathnames.

niwinz09:08:43

As I can check, cheshire does it in the same way as ruby:

(require '[cheshire.core :as json])
(json/encode "/")
;; => "\"/\""

lmergen11:08:45

seems like you’re trying to import a class that does not exist ?

ilukinov11:08:55

every freaking day is a battle with setup and tools

ilukinov11:08:07

programming time 1%

ilukinov11:08:07

how to fix this? why this appeared I didn’t change any dependency just reopened idea and now I have this trace with 0 info in it

lmergen11:08:57

it’s a matter of becoming more familiar with the ecosystem

yonatanel11:08:59

@ilukinov: just by opening intellij? did you run anything inside it?

lmergen11:08:26

i think a good way to reduce to struggle with setup and tools is to limit the amount of automatic updates etc

ilukinov11:08:27

this appeared when I trying to run repl

ilukinov11:08:55

it throws this in my face and then still will start repl

ilukinov11:08:34

then when I try to load any clj file from my project it with throw again Loading src/eem_rest_api/scenarios.clj... java.lang.NoClassDefFoundError: Could not initialize class clojure.core.async.impl.channels__init clojure.lang.Compiler$CompilerException: java.lang.NoClassDefFoundError: Could not initialize class clojure.core.async.impl.channels__init, compiling:(clojure/core/async.clj:1:1)

yonatanel11:08:24

@ilukinov: Can we see your project.clj file and maybe some more of the project?

hans11:08:40

@ilukinov: maybe clean out your target/ directory.

ilukinov11:08:23

@hans we have a winner! why the hell it uses something from target folder? Why this “something” is broken? How I could figure it out without slack?

ilukinov11:08:22

how are you people staying sane being a programmers - I don’t know, it’s a mess, total mess.

hans11:08:11

if you don't like solving problems, then you should choose another profession.

hans11:08:41

1) everything is broken 2) it cannot be fixed 3) we can still get things done

lmergen12:08:07

i think it is fair to say that there are different types of problems, and dealing with package manager quirks is not high on my list of problems i like to solve either

ilukinov12:08:12

i like solving problems, but I don’t like battling with tools and digging into error messages with 0 info, It’s like if I use hammer yesterday and it worked, and today it became screwdriver.

lmergen12:08:52

however, in defense of clojure, it’s a relatively new language and not as mature as, say, java. the toolset voor java (or even scala) is much more mature.

hans12:08:00

@ilukinov: it only feels like that because you're inexperienced. this is certainly a problem with clojure (or most lisps, for that matter)

hans12:08:56

@ilukinov: after only a few years, you can make sense of the error messages even though they're sometimes not very explicit (or, which is often worse, too explicit).

ilukinov12:08:17

I think you just get tolerance tho pain thats it

ilukinov12:08:17

so you saying that you figured out that I need to clean my target/ folder from that error message about core/async?

hans12:08:26

yes. if you get low-level class-not-found errors, they're often caused by outdated .class files.

niwinz12:08:52

this is pretty common stuff on jvm, not clojure strictly related

niwinz12:08:29

java will thow similar error if such thing happens

hans12:08:35

dependency detection is hard. all tools that try fail at some point.

niwinz12:08:27

I found similar stuff in dependency detection in almost all languages that I have used. Although, clojure error are not the best on the world, I found similar stuff and cryptic errors in a bunch of other languages (in majority more mature that clojure...)

ilukinov12:08:48

here is another one WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/boolean? WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/boolean? WARNING: bounded-count already refers to: #'clojure.core/bounded-count in namespace: clojure.core.async, being replaced by: #'clojure.core.async/bounded-count WARNING: Inst already refers to: #'clojure.core/Inst in namespace: schema.core, being replaced by: #'schema.core/Inst WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: fipp.visit, being replaced by: #'fipp.visit/boolean?

ilukinov12:08:29

what does this mean? how the hell definition was replaced? what about name spaces? Does this mean that boolean? is no longer boolean? clojure’s native boolean? was replaced? why?

manutter5112:08:31

Yeah, that’s because they just added boolean? to clojure.core — it wasn’t there before so a bunch of libs all implemented it, and now it’s generating warnings

manutter5112:08:03

I’m pretty sure it’s safe to ignore for now, I haven’t heard of any problems with it

ilukinov12:08:22

to much to ignore for me

manutter5112:08:07

If you revert back to clojure version 1.8.0, you can avoid that, but you won’t get any of the clojure.spec stuff

ilukinov12:08:27

so I guess the more you ignore the less pane you have when you programming 😀

lmergen12:08:11

@ilukinov: tbh, running a beta version of clojure is not a good idea if you don’t like these kind of problems

lmergen12:08:21

heck, alpha version even

ilukinov12:08:28

@lmergen: but clojure.specs is so tasty, that I will ignore those errors

Rachel Westmacott14:08:53

My REPL keeps getting into a bad state where things like this happen:

(def first-of-month "2015-01-01")
=> #'user/first-of-month
(str first-of-month)
=> "Unbound: #'user/first-of-month”
If anyone has any idea where I’ve gone astray I’d love to to know.

lvh14:08:48

huh, weird

lvh14:08:50

is the namespace changing?

lvh14:08:57

How did you get that repl?

Rachel Westmacott14:08:27

It’s a Cursive REPL and I’m attempting to use the ‘Reloaded’ pattern

Rachel Westmacott14:08:30

mostly successfully

Rachel Westmacott14:08:46

but I have to restart the REPL a lot more often than I want to, because it gets into this state

Rachel Westmacott14:08:10

it’s starting to get annoying, so I thought I’d try and solve it

Rachel Westmacott14:08:03

I found a reproduction case: calling (reset) causes it, but only when (set-refresh-dirs “src” “dev”) includes user.clj. I’ve clearly not got to ‘the bottom’ of it. But I’m not updating user.clj very often so I can lose that for now.

dpsutton14:08:45

oh. you've got a user.clj file

dpsutton14:08:55

and user is the default "blank" namespace loaded

dpsutton14:08:45

there are two things called user its sounds like

Rachel Westmacott14:08:04

yep - its a convenient way of loading a bunch of (development / non-prod) code into the REPL

Rachel Westmacott14:08:17

well, there’s the namespace, and there’s the code that defines it - in that sense there are 2 things

dpsutton14:08:41

i think the repl's define a default namespace called user, and you have also defined a namespace called user

dpsutton14:08:45

those are the two things

dpsutton14:08:00

so its possible that it's getting interned in the other user when you are in a different user

Rachel Westmacott14:08:54

I would be surprised if the REPL were maintaining two separate namespaces with the same name.

Rachel Westmacott14:08:17

that (IMHO) would violate the principle of least astonishment

dpsutton14:08:51

can you post the namespace declaration from user.clj?

Rachel Westmacott14:08:50

not easily at the moment - I can try to produce a minimal repro case later

dpsutton14:08:28

well, is it (ns projectname.user) or just (ns user)?

Rachel Westmacott14:08:14

sorry:

(ns user
  (:require
    [clojure.repl :refer :all]
    [clojure.tools.namespace.repl :refer [refresh refresh-all set-refresh-dirs]]
    [com.stuartsierra.component :as c]
    [clojure.string :as string])
  (:import (java.sql BatchUpdateException)))

dpsutton14:08:53

you are definitely running two namespaces

dpsutton14:08:02

and you said you can reliably reproduce the problem when you have a user.clj file?

lumengxi19:08:03

anyone used https://github.com/Factual/s3-journal before? have couple of questions

dpsutton21:08:41

(inst/parse-timestamp (java.util.Date ) "2016-07-29T13:43:00") is throwing an error saying that it can't java.lang.Class cannot be cast to lang.IFn, which seems valid, but what "constructor" or date creation function can i use here

seancorfield21:08:01

(java.util.Date.) <— note the . at the end

dpsutton21:08:37

hmm. same issue

gfredericks21:08:47

you're supposed to pass it a function

gfredericks21:08:57

(fn [years months days ...] ...)

dpsutton21:08:05

right. so which function can i pass it.

gfredericks21:08:19

you'd write your own

seancorfield21:08:22

Ah, wasn’t sure what inst was...

gfredericks21:08:25

what are you actually trying to do?

dpsutton21:08:37

i didn't think that i needed a full fledged library, but i looked out and about and I see seancorfield with a library 🙂

dpsutton21:08:00

inst is the clojure.instant namespace in this instance

dpsutton21:08:08

i am trying to get a datetime object from a string

gfredericks21:08:32

try inst/read-instant-date

dpsutton21:08:05

well i'll be damned

dpsutton21:08:20

i got confused as i don't understand why these are def's instead of defn's

dpsutton21:08:24

but i appreciate it

gfredericks21:08:43

hackier thing that also would have worked: (read-string "#inst \"" time-string "\"")

gfredericks21:08:57

or (read-string (str "#inst " (pr-str time-string)))

dpsutton21:08:55

haha that is some gross looking stuff there 🙂

dpsutton21:08:46

@seancorfield: , appreciate you chiming in so quickly. do you also maintain clj-time?

dpsutton21:08:51

and much appreciated gfredericks. that code got super dense inside there pretty quickly

seancorfield23:08:23

@dpsutton: Well, "maintain" is a broad term… I’m one of the two official maintainers (with Michael Klishin) but mostly we just review and merge other people’s PRs these days.