Fork me on GitHub
#babashka
<
2020-05-02
>
bherrmann01:05:29

FYI: This is a tiny multithreaded web server that I wrote. It has a tiny router and uses bootstrap. https://github.com/bherrmann7/bb-common/blob/master/wee_httpd.bb I started with the existing "single threaded" example web server, and added on to it.

💯 24
sogaiu11:05:18

sneaky use of single quotes to avoid escaping 🙂

sogaiu11:05:53

nice work!

sogaiu11:05:09

@borkdude looks like script/compile changed recently to use: set -eou pipefail instead of set -eo pipefail i am not having luck running the compile script with that change. removing the u seems to help. may be there is something else i should do instead?

borkdude11:05:27

@sogaiu yeah, I added -u to prevent silly mistakes on my end. what's the error you get

sogaiu11:05:54

$ bash script/compile
script/compile: line 5: BABASHKA_XMX: unbound variable

borkdude11:05:36

let me fix that

borkdude11:05:42

@sogaiu should work now

sogaiu11:05:52

@borkdude thanks! just tried it with success 🙂

nate13:05:42

hm, I was trying to add java.lang.Character to bb, so I could use https://github.com/joegallo/doric, which fails with:

clojure.lang.ExceptionInfo: Could not resolve symbol: Character/toTitleCase [at doric/core.clj, line 8, column 11]

nate13:05:05

I got it added to bb in my local dev

borkdude13:05:48

yes, PR welcome

nate13:05:58

wait, maybe it's an issue with doric

nate13:05:59

yes, I added it there

nate13:05:03

and built a new bb

borkdude13:05:35

btw, if you want to test before building, you can run lein bb '(+ 1 2 3)'

nate13:05:41

$ ./bb
Babashka v0.0.91-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (java.lang.Character/isDigit \4)
true
user=> (java.lang.Character/toTitleCase \t)
\T

borkdude13:05:45

this allows for faster iteration

nate13:05:58

so my bb has toTitleCase

nate13:05:09

but the code in doric looks like this:

(defn- title-case-word [w]
  (if (zero? (count w))
    w
    (str (Character/toTitleCase (first w))
         (subs w 1))))

nate13:05:28

no :import, but that should be ok for java.lang stuff, yes?

borkdude13:05:31

ah, you need to add it to the automatically imported classes in babashka.main

nate13:05:52

cool, will try that

nate14:05:57

that worked!

nate14:05:13

oh oh:

Could not resolve symbol: ns-resolve [at doric/core.clj, line 159, column 13]

nate14:05:27

that strikes me as a deeper change

borkdude14:05:31

We can add that to sci

borkdude14:05:48

it's like resolve, but it also takes an ns right?

user=> (ns-resolve 'clojure.set 'join)
Execution error at user/eval138 (REPL:1).
No namespace: clojure.set found
user=> (require '[clojure.set])
nil
user=> (ns-resolve 'clojure.set 'join)
#'clojure.set/join

nate14:05:25

interesting

borkdude14:05:31

@U0510902N Simple workaround for now:

$ bb -e "(ns clojure.core) (defn ns-resolve [ns sym] (resolve (symbol (str ns) (str sym))))" -e "(ns-resolve 'clojure.string 'join)"
#'str/join

borkdude14:05:54

I'll make an issue in sci

borkdude14:05:43

oh I see, it resolves a symbol from the perspective of that namespace

borkdude14:05:49

but the workaround may still work for you in this case

borkdude14:05:10

I think in clojure 1.10 you would use requiring-resolve for this. I'll also add that

nate14:05:44

yeah, doric was last updated 6 years ago

nate14:05:58

I might be able to just fork it and improve it if needed

nate14:05:18

all this to get around the right-alignment of print-table

borkdude14:05:42

well, it's perfectly fine what he is doing.

borkdude14:05:54

is there something missing in print-table in babashka?

nate14:05:47

print-table works well

nate14:05:58

but all the columns are right aligned

nate14:05:14

and you can't left align them

borkdude14:05:33

right. so did you get it working with these workarounds?

nate14:05:05

I haven't tried it yet, will soon

borkdude15:05:06

Added ns-resolve to master

borkdude15:05:23

I'm now trying it. I'm getting some ISeq + Boolean exception

borkdude15:05:09

I'm debugging

nate15:05:18

sorry, I was going to be able to play with it and then a work thing exploded

borkdude15:05:07

no problemo

borkdude15:05:33

it may be a bug in sci, but I haven't discovered the issue yet

borkdude15:05:14

Weeeird. When this code is loaded from a library:

(defn columns1 [cols]
  (doall(for
            [col cols]
          col)))

(defn table
  [cols]
  (doall (for [col cols] col)))

borkdude15:05:34

and then you call (table nil), you get:

clojure.lang.ExceptionInfo: Don't know how to create ISeq from: java.lang.Boolean [at line 155, column 3]

borkdude15:05:43

but when you eval it from a REPL, it's fine

nate16:05:43

that error message, I can see where it might get the ISeq from, but the boolean?

borkdude16:05:27

I also can't reproduce it when I paste that code in a file and load it with load-file, but when I load that library code with load-file, the error is there, so it seems to be specific to that file...

borkdude16:05:44

Repro:

(ns doric.core
  (:refer-clojure :exclude [when]))

(defn when [col & [data]]
  (:when col true))

(defn columns1 [cols]
  (doall(for
            [col cols]
          col)))

(defn table
  [cols]
  (doall (for [col cols] col)))

(table nil)

borkdude16:05:54

I think sci's for macro doesn't fully qualify when 🙂

borkdude16:05:57

lemme fix that

borkdude16:05:58

ok, try again with master. also added the Character class

borkdude16:05:59

$ clj -A:bb-local -cp /tmp/doric/src -e "(use '[doric.core])" -e "(println (table [:a :b] [{:a 1 :b 2}]))"
|---+---|
| A | B |
|---+---|
| 1 | 2 |
|---+---|

nate16:05:29

awesome!

nate16:05:33

wow, thank you!

borkdude16:05:02

$ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {doric {:mvn/version "0.9.0"}}}')
$ ./bb -e "(use '[doric.core])" -e "(println (table [:a :b] [{:a 1 :b 2}]))"
|---+---|
| A | B |
|---+---|
| 1 | 2 |
|---+---|
😄

borkdude16:05:51

if you find another bug, let me know

borkdude16:05:45

if you want, we can add a test for this library in script/lib_tests

borkdude16:05:06

for some libraries I've just downloaded their test suite into test-resources/lib_tests

borkdude16:05:06

so I run their entire test suite with babashka

borkdude18:05:54

I'm working on it already - I think it's good to discover more things to make bb compatible with libs like this

nate18:05:49

I was just figuring out how I could include a lib

nate18:05:56

used medley as an example

nate18:05:05

nice to have these as a set of smoke tests

borkdude19:05:38

I also tried this guy's fork, for which there is a PR: https://github.com/jgdavey/doric But that PR breaks bb compatibility because of defprotocol. I hope I have some time soon, to see what can be done about that. It seems to be the most incompatible thing at the moment

nate19:05:33

thanks to your update, my little path manipulation script can show a path in a nicer way than usual:

$ ./scripts/empath $(clojure -Spath)
|-------------------------------------------------------------------------------------------+--------+-------+-------+-----------|
|                                          Element                                          | Exists |  Dir  |  File | Can Write |
|-------------------------------------------------------------------------------------------+--------+-------+-------+-----------|
| src                                                                                       | true   | true  | false | true      |
| /home/nate/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar                   | true   | false | true  | true      |
| /home/nate/.m2/repository/comb/comb/0.1.1/comb-0.1.1.jar                                  | true   | false | true  | true      |
| /home/nate/.m2/repository/doric/doric/0.9.0/doric-0.9.0.jar                               | true   | false | true  | true      |
| /home/nate/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar           | true   | false | true  | true      |
| /home/nate/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar | true   | false | true  | true      |
|-------------------------------------------------------------------------------------------+--------+-------+-------+-----------|

borkdude19:05:44

Is there a way to expand a thread to full screen?

nate19:05:31

yeah, click on Threads in upper left

borkdude19:05:55

oh right. that does look nice!

borkdude19:05:24

I'll make a new release, so you can show off this nice script to the rest of the world 😉

nate19:05:35

Sweet! thank you!

nate20:05:37

🎉

mbjarland18:05:09

Hi all. I tried to add the oracle jdbc driver to bb 0.90 by adding a new profile (in the same vein as the postgres and hsqldb already are) which contains the oracle jdbc driver jar. I have verified that the uberjar contains the driver and the build succeeds, but on trying to use the jar I get the following exception. The class oracle.jdbc.driver.T4CDriverExtension is in the uberjar. Any ideas on what’s going on or how to get past this much appreciated.

borkdude18:05:34

Did you add anything to babashka.impl.classes?

mbjarland18:05:49

aha, no I did not

borkdude18:05:34

Maybe it needs reflective access to that class. You can discover this by running with a GraalVM agent

borkdude18:05:41

or just googling what others did for that driver

mbjarland18:05:56

thanks for the pointer, I remember messing (think I even did a PR) with that file before. Ok I will at a minimum try to add the class it is complaining about and rebuild and see where that leaves me

borkdude18:05:36

you can run with lein bb instead of bb to just test before you with the image, just to see if there's nothing else broken

mbjarland18:05:36

yeah I have an issue where I need to build the uberjar on one system and do the graal compile on another (c dependencies on production servers differ and no access to lein there)

mbjarland18:05:52

the setup is a bit convoluted

borkdude18:05:21

well, there is a separate script/uberjar and script/compile now, so that works I guess

mbjarland18:05:41

yeah, seems you read my mind with that split

mbjarland18:05:20

and since I’m here, thanks for those graal build scripts, they have helped me in getting a few other projects built.

mbjarland18:05:53

I’m assuming the driver class should go into the classes def in that file?

mbjarland18:05:19

I did:

java.util.zip.GZIPOutputStream
          oracle.jdbc.driver.T4CDriverExtension
          ~(symbol "[B")
to no avail, ok will google it

mbjarland18:05:38

thanks for the help

borkdude18:05:51

and did it work with lein bb though?

mbjarland09:05:24

well I can’t run lein on the target machine an I can’t run the native version of bb produced on the machine where lein works, would that scenario not invalidate the lein bb idea?

mbjarland09:05:54

I found a graal ticket discussing the oracle driver, working through that now, we’ll see if I can get it working

mbjarland09:05:55

if yes, I can make some kind of pr, I suspect we can not check in the oracle driver as oracle is what they is, but I could set everything aside from the driver up so that other people who need this can just enable the feature and drop in the jar

borkdude09:05:54

they don't have their drivers on maven?

mbjarland09:05:17

well on maven central there is a reference to another repository where you get a 404

mbjarland09:05:03

and going to oracle you can get to a maven repository but you need an oracle account to use it which I’m sure involves agreeing to som draconian eula involving your first born child, the fires of hell, brimstone etc

mbjarland09:05:18

ah and it also depends on the driver version you need, could be the later versions actually exist in some repo

mbjarland09:05:28

I need ojdbc6 to match production environments

borkdude09:05:17

maybe add instructions how people can add these drivers to the classpath then, while building the uberjar

mbjarland09:05:25

I’ll work through this, if I get out on the other side with something useful I will ping that as a PR or here

mbjarland09:05:49

figured I could create an md page for oracle explaining the process, assuming I can actually get this to work

borkdude09:05:30

I have some docs for hypersql and postgres here: https://github.com/borkdude/babashka/blob/master/doc/build.md#hypersql Could add Oracle to that page