Fork me on GitHub
#beginners
<
2017-12-20
>
josh_tackett00:12:26

quick question when I connect to an aws db do I need access keys? or can I just connect with user and pass?

admay01:12:09

You just need the username and password. You can build a JDBC URL based off of that and create a connection just like connecting to any other DB

seancorfield01:12:55

@admay It's better to use :dbtype and :dbname with :user and :password rather than trying to build the JDBC URL yourself.

seancorfield01:12:14

clojure.java.jdbc tries to make connecting easier by figuring out the URL for you.

seancorfield01:12:41

@josh_tackett Which AWS DB are you using? I haven't tried it myself but clojure.java.jdbc should have no problem connecting to their MySQL-variant and at least one person has used it with RedShift (it's given as one of the examples in the README for clojure.java.jdbc). If you have problems, head over to #sql and ask as I'm more likely to see it there.

josh_tackett01:12:38

@seancorfield No worries it was just an inbound configuration issue. FYI Amazon sets the default inbound rule for mysql to your IP address used when setting up the RDS instance

New To Clojure11:12:12

Is there a way to dump all data of JVM to start new JVM instances with the same initial data (state)?

vijaykiran13:12:11

I don’t think so

vijaykiran13:12:00

maybe you can run the JVM in a container/VM and save and reload the container

Prakash13:12:34

yeah I dont think it can be done, but it looks interesting. What are some use cases where this might be needed/useful?

New To Clojure13:12:20

@pcbalodi First use case is troubleshooting of a rare bug.

Prakash13:12:59

ah nice, that will be good

vijaykiran15:12:39

Depending on the type of the bug, you can take a heap dump and try analysing it

New To Clojure16:12:53

@vijaykiran In gdb? It's C, not Java.

vijaykiran16:12:26

hmm - I thought you were talking about JVM

justinlee17:12:22

that would be super complicated given all the file descriptors and other OS resources the JVM would have

alexmiller17:12:38

People have actually been working on this for years - they used to be called Isolates but I think they have a new name now

debamitro17:12:00

I tried seesaw with a hello world app, and though it is simple to use I didn’t like the start-up time of the app. Is there some library which can create a GUI that starts up instantly, like say electron apps do?

donaldball17:12:36

How are you starting your app?

donaldball17:12:25

While clojure startup time isn’t anything to brag about generally, tools like lein add meaningfully to the startup time. You probably want to build an uberjar and run it via java directly, as well as choose your jvm-opts judiciously.

debamitro18:12:26

@donaldball yes I did lein run. I’ll try the uberjar method and see. I also couldn’t figure out why a java app called ‘main’ starts up before my app. Actually I am a C/C++ person, and am not aware of Java’s quirks

noisesmith18:12:57

the “java app” is your process - clojure is a java library that generates and runs byte code in the jvm. “main” is a default name because neither you nor seesaw changed the default.

noisesmith18:12:30

leiningen is a shell script which in your case runs java in order to calculate a classpath, then runs a second java process with that classpath in order to run your clojure program

debamitro18:12:13

@noisesmith thanks a lot. Your explanations are very helpful.

Oleh K.18:12:25

I've got an error compiling cljs with node dependencies: node_modules/firebaseui/dist/firebaseui.css: Unexpected token, expected ( (1:8) Anybody knows what to do with this?

sb19:12:19

How much loc your productivity daily avg? and avg. how much loc one project in Clojure? (eg. with/out macros)

alexmiller19:12:50

git deltas on last 3 days:

3 files changed, 105 insertions(+), 41 deletions(-)
9 files changed, 63 insertions(+), 60 deletions(-)
2 files changed, 33 insertions(+), 36

alexmiller19:12:14

some of those lines required multiple hrs of research and/or testing :)

noisesmith19:12:05

on a good day I can add 5 new features while reducing line count by about 300 lines

noisesmith19:12:03

but “line” and “feature” are both kind of fuzzy metrics

seancorfield19:12:05

Yeah, I generally consider it a very productive day if I've added functionality and reduced the overall number of lines!

seancorfield19:12:46

@sb I'm always happy to share our code base stats:

Clojure build/config 43 files 2150 total loc
Clojure source 243 files 56183 total loc,
    3099 fns, 710 of which are private,
    372 vars, 41 macros, 47 atoms,
    440 specs, 11 function specs.
Clojure tests 145 files 19484 total loc,
    23 specs, 1 function specs.

sb19:12:28

daily what is the optimal at different levels? eg. beginner, senior? (eg. reagent/re-frame/sente application)

seancorfield19:12:37

I don't think the LOC metric is at all useful (other than a vague measure of overall code base size). A daily metric is just nonsense.

seancorfield19:12:46

"daily productivity" is a terrible concept in general, to be honest.

sb19:12:58

Ok, in this case, how can I compare with myself?

sb19:12:17

Because I see.. one project size (at my case 3-5k loc)

sb19:12:57

I don’t know, what is really the normal metric. I totally understand what you wrote now.

seancorfield19:12:16

In some ways, with Clojure, I might expect a senior developer to produce more functionality with fewer lines of code than a beginner -- because a senior dev will often write more concise, more idiomatic code.

seancorfield19:12:02

Also, Clojure emphasizes "hammock time" -- thinking carefully about a problem, exploring code via the REPL, and only then writing the actual production code.

sb19:12:32

True. I do it in similar way.

sb19:12:12

Ok, that was a bad question 😄 .. just I want to check myself.

seancorfield19:12:18

If your team is Agile and doing some sort of story point estimation -- and is good at estimation (which most teams aren't!) -- then you could compare productivity in terms of story points completed. But even then I'd consider it a suspect metric.

sb19:12:19

Thanks, that is great idea! I’m still alone (learn Clojure).

seancorfield19:12:16

You'll probably find, at first, that you're very slow to write Clojure code -- unless you have an FP background it is very alien.

seancorfield19:12:33

Over time, you'll find yourself solving problems faster -- but probably with less code 🙂

sb19:12:04

Yes, I feel that. 🙂

sb19:12:11

Thanks 👍

seancorfield19:12:03

We actually track those stats I posted, updating a file in git every Monday. A quick scan of diffs suggests that two senior Clojure devs are usually producing about 300 lines of Clojure source a week and about 100 lines of Clojure tests.

seancorfield19:12:35

That said, there are weeks where our source lines went up by 1,000 and other weeks where it went down by 300!

sb19:12:44

Thank you very much this information, very useful for me!!

sb19:12:52

👍👍👍👍👍

sb19:12:04

I feel myself a little bit better. 😉

seancorfield19:12:28

The build/config stuff is our build.boot file and all our EDN config files (which control a lot of app behavior, as well as specifying each subproject's dependencies).

jedahan19:12:49

so i've got this list of objects, that I want to map to a hash of {:(.getKeyword object) (.getText object)}, should I be looking at juxt or is there an easier / more idiomatic way of doing this

justinlee19:12:26

🎶 ...and a macro in a sexp… 🎶

jedahan19:12:32

.getKeyword and .getText will return strings

noisesmith19:12:32

I assume the : in your example is illustrative - does that mean you need the string to be converted to a keyword?

noisesmith19:12:19

the simplest thing is going to be (fn [o] {(keyword (.getKeyword o)) (.getText o)})

noisesmith19:12:53

juxt would still require fn wrappers around the methods and then into to create a hash-map

alexmiller20:12:41

you could do something like (apply keyword ((juxt :keyword :text) (bean o)))

alexmiller20:12:03

if you’re looking to impress your friends rather than make it readable :)

gowder20:12:36

aieeee, I always struggle with java interop. Dear clojurist friends, I have a really stupid question: I'm trying to import this java class. https://jsoup.org/apidocs/index.html?org/jsoup/examples/HtmlToPlainText.html i have no problem importing and using the normal Jsoup class, but I can't seem to figure out the right ns form to import the examples.HtmlToPlainText class. I've tried (:import [org.jsoup Jsoup HtmlToPlainText]) and I've tried

(:import [org.jsoup Jsoup]
           [org.jsoup.examples HtmlToPlainText])
but in both cases the compiler throws ClassNotFoundException. Does anyone feel like cluing me in?

noisesmith20:12:22

@gowder how are you pulling in the jsoup dep for your project?

noisesmith20:12:50

also - is that :import inside your ns form or stand alone?

noisesmith20:12:08

because I would expect that error if using the keyword outside the ns

gowder20:12:29

@noisesmith off maven, via lein [org.jsoup/jsoup "1.11.2"] --- and yes, in my ns form.

noisesmith20:12:45

then you are doing something else wrong - those are the two likely issues

gowder20:12:49

I'm wondering now if the examples stuff just isn't in what's on maven

noisesmith20:12:55

are you sure you restarted since editing your deps?

gowder20:12:11

because I tried to pull in another subpackage and it didn't throw

(ns cleanup-case.core
  (:import [org.jsoup Jsoup]
           [org.jsoup.helper StringUtil]
           [org.jsoup.examples HtmlToPlainText])
  (:gen-class))
the helper one didn't blow up...

noisesmith20:12:14

you could look inside the jar - the classpath will show where the jar is on your file system

jedahan20:12:33

Hmm, I am having trouble filtering/mapping with a static method. (ChunkHelper/isText (first chunks)) works fine, but (filter ChunkHelper/isText chunks) errors with CompilerException java.lang.RuntimeException: Unable to find static field: isText in class ar.com.hjg.pngj.chunks.ChunkHelper,

noisesmith20:12:14

@slack1478 static methods are not first class, you can’t put them on the stack so you can’t pass them as an argument to filter

noisesmith20:12:29

you need to create a function that calls the static method

jedahan20:12:04

(filter #(ChunkHelper/isText %) chunks) seems to work

gowder20:12:33

oooh. that is indeed the problem (and now I just learned how to look in a jar file... cool)

noisesmith20:12:54

@gowder yeah they are zip files, even emacs and vim can open and peek inside 😄

gowder20:12:39

hmm. I wonder what will happen if I just compile jsoup myself and then stick that example class on the classpath. terrible things, probably...

noisesmith20:12:40

@gowder you can build and install to your local cache using maven, right? but if you are collaborating with others you probably want a private repo you can deploy to

noisesmith20:12:08

or just use an artifact that exists

jedahan21:12:55

Thanks for all your help @noisesmith @alexmiller and @tsulej - i made this little module for reading and writing png metadata

jedahan21:12:08

its really messy, and i think i can remove some of the deps, but it works

justinlee21:12:30

from the perspective of someone new to clojure, its looks nice and clear to me! that’s a fun project

noisesmith22:12:32

@slack1478 a couple of small things - line 22/23 you can replace (map …) (flatten) with (mapcat …)

noisesmith22:12:11

mapcat is like map but concatenates all the results into a sequence - it’s less aggressive than flatten and preferable when it works

noisesmith22:12:48

or, instead of mapcat or flatten, you can use (into {}) instead of (apply hash-map)

jedahan22:12:53

its kinda crazy I had to use pngj for reading metadata supposedly because I didn't understand how IIOImage works... and honestly I'm not sure if I should be using javax/iioimage, pngj, or apache commons imaging

jedahan22:12:01

they all kinda are broken in different ways

noisesmith22:12:04

as a very minor detail, on line 52 you don’t need to call vec on the metadata - reduce can use any collection directly that vec works on

jedahan22:12:09

or I had trouble understanding them / trawling through javadocs

genmeblog22:12:42

@slack1478 two points from my side: 1) you read file twice, for image and for metadata - can be optimized to read once; 2) metadata is hash-map, you don't need to convert it to vec and operate on pairs (I think)

genmeblog22:12:42

however reading once can be impossible here...

noisesmith22:12:42

you would need to do that if you want keywords though

noisesmith22:12:56

(regarding point 2)

jedahan22:12:13

@tsulej for 1) its a bit tricky since i am using two different libraries for reading and writing

jedahan22:12:22

best thing to do would be consolidate, then I can have it only read once

jedahan22:12:55

like, I can reduce the (File.) redundancy now