Fork me on GitHub
#clojure
<
2018-09-01
>
dl05:09:50

anyone developed a slack plugin in clojure before?

emccue05:09:06

nope, but a quick google shows at least 1 jvm library

emccue05:09:31

what are the hurdles you are running into?

emccue05:09:54

or are you still at the exploration stage?

ahungry05:09:22

How do you guys typically manage globals? I'm about to refactor/clean up my code barf for https://github.com/ahungry/ahubu and break it down into sensible modules (its a webkit based browser with vim/emacs like bindings and will have a lot of hooks ala emacs hook system soon). But I rely on a few global atoms such as the javafx stage + current scene (tab/buffer etc.)

emccue05:09:13

there are a few ways, but the simplest I know of is the Component system

emccue05:09:06

basically, wrap your "globals" as components

emccue05:09:02

and find a good entry place for injection

ahungry05:09:21

Nice, so basically a prebuilt DI setup?

ahungry05:09:27

well, framework to support it

emccue05:09:34

but if is a small app maybe you are fine with atoms

emccue05:09:10

I would just watch a talk or two on it

emccue05:09:26

that should give you enough to decide if its right for you

emccue05:09:42

there is nothing wrong with just using some atoms/refs

ahungry05:09:28

thanks - components reminds me a little bit of common lisp asdf defsystem

emccue05:09:54

looking at your github I can see youve done quite a bit of classical lisp

ahungry05:09:01

yea i'm not real sure why I put off looking into clojure for so long, but in the last 2 weeks, definitely bitten by the clojure bug 😆

dl06:09:22

@emccue I am just trying to figure out if its at all worth it to write a slack app

dl06:09:34

my idea was to create a kanban in slack, but it seems as if that is just not possible

ahungry06:09:32

I know lots of slack integrations are written in node, so i'm sure you could use clojurescript if for some reason plain old clojure can't (its just api calls though )

dl06:09:36

yeah maybe I am in the wrong channel lol

dl06:09:42

but they accept php and java too

dl06:09:45

so clojure should work

dl06:09:06

but I just realized that the slack extensions are rather boring

dl06:09:17

I cant display a cool kanban

dl06:09:33

in slack directly

ahungry06:09:01

I just saw this article pop up, slack has a poor policy on any add on that leaves what they're comfortable with https://g3rv4.com/2018/08/betterslack

dl06:09:19

I think we can do a chromium app and then distribute it in our company team

dl06:09:24

in case this works

dl06:09:34

or is there a way to create a standalone EXE or APP file for the team with anything lol

dl06:09:11

yeah with Electron

lilactown06:09:22

I’m building a slack app right now. I’ll probably use clojure for bits of it

dl06:09:45

yeah cool

dl06:09:47

what does your app do?

dl06:09:55

it probably can't display a kanban

dl06:09:04

or is there any part of the API I missed? 😄

lilactown06:09:06

sends text messages based on notifications

lilactown06:09:19

yeah they don’t support much outside of regular messaging

dl06:09:47

slack is just the best messenger for teams

Average-user06:09:57

whats the best option for profiling clojure?

Average-user16:09:55

I, ll do thar. Thanks

Average-user06:09:20

Something simple, If someone have used Haskell I'm searching something like "-prof"

lmergen06:09:28

@lucaspolymeris i like to use oracle jdk together with jmc myself, but YMMV

john13:09:22

@dl maybe you can send a picture as a message, and use that to show an SVG of the generated kanban?

dl17:09:12

@clojurians-slack interesting... but I would be interested in moving them too

dl17:09:24

anyway a have a php app in production that is the core of my business

dl17:09:55

with a mysql db running on a few instances

dl17:09:25

I want to create an interface in clojure as my first clojure project

dl17:09:49

what is the best way to go ahead?

dl17:09:54

can I inject clojure into php?

dl17:09:16

it uses a smooth deployment with the deployer php app

dl17:09:20

to multiple instances

dl17:09:44

anyway my plan is to move the script over to clojure long term

dl17:09:11

its basically a payment processing CRM with affiliate tracking

dl17:09:27

I have looked into firebase and datomic and think they are awesome

dl17:09:39

but I think I have to go step by step

dl17:09:14

maybe first design an interface in clojure, so that you can create new products and see the traffic stats there

dl17:09:23

and create new campaigns, change prices of the products, etc

dl17:09:33

add new affiliates and so on

dl17:09:16

anyway currently every legal entity that uses the script got their own DB and php instance with different domains

dl17:09:13

when migrating the code base over to clojure, should I keep it that way and maybe migrate each mysql db into their own datomic or should I create a big clojure app that keeps all of the code in one instance?

dl17:09:19

I have seen the datomic ions, thats pretty cool stuff...

dl17:09:50

he describes to do the backend in cl, and the frontend in cljs

dl17:09:10

maybe I should keep the backend in php for now and implement a frontedn that accesses the mysql db in cljs?

the2bears17:09:32

If you have scaling issues with php I'm not sure how "inject clojure into php" will help. Not sure what that would even look like. I would imagine you want to move responsibilities to Clojure piece by piece.

john17:09:35

@dl yeah, there's a lot of options. You can do a gradual migration or a clean slate, green field thing. Or variations in between. I don't have a lot of php experience

dl17:09:44

@the2bears hmm I think I miscommunicated scaling issues... the code is fast enough for now

dl17:09:31

maybe a better word would be its a little buggy and takes longer time than necessary to deploy a new domain

dl17:09:37

and its impossible to change domains for now

dl17:09:18

but I should look into cljs and not cl to setup the interface?

dl17:09:38

how do I access mysql then?

dl17:09:47

clojure (cl) vs clojurescript (cljs)

john17:09:52

Right, that might be the most incremental approach

dl17:09:59

I thought I need cl to access the mysqldb?

john17:09:36

Just building clojure views over your existing db

john17:09:03

(the common parlance is "clj" for clojure)

4
dl17:09:04

sorry for the newbie questions, I am currently working trough Getting Clojure by Russ Olsen

the2bears17:09:20

Well, you've given a pretty high-level and very vague description of your system w/some jargon specific to you. I would be hesitant to suggest anything without knowing what the architecture looks like now.

dl17:09:36

ok thanks for the feedback

john17:09:02

JDBC for connecting to DBs from Java

the2bears17:09:11

It you ask whether you should use CLJS for the front-end, what is it even replacing? (for example)

dl17:09:19

php frontend code

dl17:09:30

which I needed to delete

dl17:09:41

as the contractors did unsafe work

dl17:09:58

so as I did the backend, I will have to create the frontend I guess

the2bears17:09:04

But your approach makes sense in that front/back is usually a clear separation and lends itself nicely to a piece-by-piece approach to replacing and refactoring code.

dl17:09:09

and its a nice project to learn CLJ 🙂

dl17:09:29

however my questions is... can I directly access the DB from CLJS

dl17:09:45

or do I indeed need to start with a CLJ backend that accesses the DB

the2bears17:09:55

"front end" to me implies the user interface, is that what you mean?

john17:09:10

CLJ for talking to the db

dl17:09:19

it is a frontend where users can administer the CRM systems

dl17:09:24

add new products, change prices

the2bears17:09:26

Okay, is it in a browser or where?

john17:09:58

For the front end, either a thin thing generated as hiccup, sent out server side, or if you need a lot of dynamism, CLJS on the front end

john17:09:13

Most folks just go with CLJS/CLJ front/back

the2bears17:09:49

So back end talks to the dB, or should in most cases, as you don't want to expose it to the browser.

dl17:09:02

and I need to program the backend for the interface too

dl17:09:06

as I only have the DB

dl17:09:17

the data comes to the DB from the PHP script, which runs stable

dl17:09:21

I developed it over the years

dl17:09:40

it writes it in there whenever a sale goes trough the website via an API I developed

dl17:09:48

but only for the sales and adding customer data to the DB

john17:09:50

There's lots of ways to skin the cat. A good bridge from the php/rails world is the luminus template and tutorials

dl17:09:10

however there is no Backend code yet to display data or add new products

dl17:09:25

as I needed to fire the php devs and delete their code

the2bears17:09:28

Yeah, start by writing your UI w/CLJS and access the existing back-end.

john17:09:32

Luminus is probably your ideal onramp

dl17:09:39

no there is no existing backend for reading the data

dl17:09:56

or changeing the data, I do that in PHPmyAdmin now 😕

the2bears17:09:04

Well, something in php is reading the dB, no?

dl17:09:15

well yeah, but its only for the sales situation

dl17:09:25

when a customer comes to the page and makes purchases

the2bears17:09:34

Hmmm... more work on your architecture before deciding what to implement it with.

dl17:09:47

I think I got what you want to tell me

dl17:09:52

I think the way to go ahead is:

the2bears17:09:13

It's unclear from a slack conversation what you have and don't have. It's getting really off topic.

dl17:09:18

create a CLJ backend that access the current mysql data and exposes it as an API

dl17:09:36

create a CLJS frontend that connects to the CLJ backend and displays the data in the browser

dl17:09:41

and the user can do changes there

dl17:09:58

the core stuff where the sales happen is implemented in PHP and just works

dl17:09:05

maybe we can move that over to CLJ later 🙂

the2bears17:09:08

Yes, that's a good description. I don't do much web stuff, but look at the examples in the web frameworks for a starting point. Luminus was mentioned above.

dl17:09:17

thank you so much guys!

dl17:09:25

it really helped me clarify my thoughts...

dl17:09:04

what is the smoothest way for CLJ and CLJS to communicate?

john17:09:32

np! I'd recommend reviewing these strategies http://www.luminusweb.net/ and once you have a migration path worked out, then explore datomic ions and see if you can move your data model over

dl17:09:01

I will definitely look into datomic later

the2bears17:09:05

What do you mean? They will be separate processes. So I assume we're talking REST apis to get things going quickly.

dl17:09:14

but for now to get started its easier to use the extisting mysql dg

dl17:09:05

@the2bears yeah I mean how does backend and frontend code communicate... in PHP its kind of all together and accesses the DB directly (what a mess!)

dl18:09:18

for example... customer goes on a page and enters credit card data, the page is just an html file which accesses the PHP API for sales then in the Backend, but its all kind of in similar folders

dl18:09:24

in the same project

the2bears18:09:33

Just what I said, get a simple REST example working. Write a CLJ handler that reads something from your dB. That's a web-based API you'll create. Then, call that from CLJS in your browser and display the result.

dl18:09:59

thank you so much guys! I will study some more getting clojure and then do my first steps in the project

dl18:09:17

but its probably not possible to run the clj backend in the same project with the PHP code...

dl18:09:34

so I will have to deploy the clj backend code on the same server to be able to access the DBs

dl18:09:51

or does anyone have migrated from PHP to CLJ/CLJS before?

the2bears18:09:53

Not sure what you mean by "same project"

the2bears18:09:13

Write your CLJ separately, deploy on the machine you need to

the2bears18:09:31

it will of course run in its own process

dl18:09:47

I mean the php frontend file which displays the order form is actually directly using the DB and PHP session as the API script which runs in the backend

dl18:09:52

thats what I mean with mess

dl18:09:56

and it contains PHP and HTML code lol

dl18:09:02

and DB access code

the2bears18:09:15

The "front end file"? That is a back end file that generates the html that the browser displays if I understand. Not sure I do, as we're talking circles here wrt definitions. Front end is the browser in your case. Not the file running on the server that generates the html returned to the browser.

dl18:09:34

its the same in this case....

john18:09:48

JDBC I believe grabs a handle to your locally running db. If you have access to the local box and can install java and clojure, etc, you should be good

dl18:09:56

yeah cool man

dl18:09:05

I will do my first steps now thank you so much!

john18:09:16

You'll need the db creds I believe

dl18:09:25

got root

the2bears18:09:49

What could go wrong? 😂

john18:09:27

You sound pretty unhappy with the whole setup. Maybe look into a more datomic ions solution sooner rather than later.

dl18:09:42

I am really unhappy as its a mess

dl18:09:07

the result of hiring and firing a bunch of PHP devs

the2bears18:09:08

Yeah, you should figure out the architecture you want first, before you spend time changing anything in the current setup.

dl18:09:21

but it works

dl18:09:24

and its the core of my business

john18:09:42

And it sounds like you're not happy with the security around the db. Might want to square that away sooner rather than later, or migrate to a cleaner setup.

dl18:09:02

so first step is getting my feet wet in CLJ and CLJS by creating an interface for the existing DB model

dl18:09:17

then I will have more experience

the2bears18:09:45

Yes, CLJ talks to the dB, CLJS talks to the CLJ back-end.

dl18:09:51

cool! now I got it 🙂

the2bears18:09:55

No other communication! 🙂

dl18:09:00

I thought I can access the DB directly from CLJS lol

the2bears18:09:18

Especially between the browser and the dB

john18:09:23

"access" is a relative term 😉

the2bears18:09:25

Just because you can...

dl18:09:38

should not because of security

the2bears18:09:15

It's the core of your business, definitely not due to security and SLA of the interface.

dl18:09:26

:rolling_on_the_floor_laughing:

john18:09:28

So Mike Fikes has been doing all these performance tests on the clojurescript compiler using a large corpus of problems from the 4clojure website. A quarter million lines of clojure code. Pretty cool stuff. But it got me thinking, what if you put all that code into a word2vec? Would you be able to query for semantically similar code?

john18:09:56

So I whipped this up this morning: clojure -Sdeps '{:deps {johnmn3/coal-mine2vec {:git/url "" :sha "46af3670c16b9a3b827c1e144b76c116dc45a4ce"}}}' "-m" "coal-mine2vec.is-to" map reduce for

john18:09:41

"map" is to "reduce" as "for" is probably to "loop"
 ... but may also be one of these: "&" "c]" "a]" "["

john18:09:44

So you pass it a pair of functions and a third that you want to find the analogy of

john18:09:51

like, "thing A is to thing B, as thing C is to what?"

😮 4
john18:09:15

Right? There's probably some interesting applications. Maybe some code gen thing, for testing.

john18:09:48

Or code analytics

lilactown18:09:19

might be a basis for a kind of styleguide hint/suggestion algorithm

john18:09:35

yeah, an assistant of some sort

john18:09:40

completions

lilactown18:09:16

I think one of the hardest things about clojure’s core library is that it’s so vast, and relatively unorganized

lilactown18:09:49

you might have a task that you think might already be solved (or would be surprised to find out!), but not know how to search for what you want

john18:09:55

Yeah, it's a wide and flat first class environment, in that regard

lilactown18:09:52

so being able to draw relationships between fns and forms that are used on similar data structures or similar uses could be really valuable, actually!

john18:09:05

Yeah, it's not very accurate though, at the moment

john18:09:16

might need to dump a few million more lines of code in it 🙂

john18:09:03

Another good inference:

"inc" is to "dec" as "max" is probably to "min"
 ... but may also be one of these: "loop" "a]" "[b" ":else"

john18:09:26

half the time the result is way off though

john18:09:33

Also, you could take spec.gen and produce billions of valid functions, and then train the word2vec on that, to see if it can heuristically detect invalid forms

john18:09:54

maybe...

punit-naik18:09:10

Hi All, had a small question. How do I set the order of execution of my unit tests? How do I make tests from one namespace run before tests from some other namespace?

dpsutton18:09:16

hate to x-y you but unit test order should be opaque and meaningless

8
dpsutton18:09:38

but you can check out https://clojuredocs.org/clojure.test/run-tests to specify an order of namespaces

seancorfield18:09:16

@punit-naik I'll second @dpsutton’s comment: you really should not have test order dependencies -- each test should be self-contained and should be able to run before or after any other test. Otherwise your tests are not repeatable on their own.

dpsutton18:09:34

including notes about ordering

punit-naik18:09:20

@seancorfield @dpsutton Thanks for your suggestions!

foobar21:09:49

How do I use spec to match exactly a keyword? E.g If I have [ [:foo "a"] [:bar "b"]] but I need to apply different specs to "a" and "b"

punit-naik12:09:35

If you have (def m {:foo "a" :bar "b"}), then you could do:

(s/def ::foo string?)
(s/def ::bar string?)
(s/def ::map-spec (s/keys :req-un [::foo ::bar]))
Does that answer your question?

foobar21:09:06

I know I can write a function, but that seems hard work

andy.fingerhut21:09:18

@punit-naik If you really want a sequence like set up, run some tests, teardown, best to do that inside one deftest form.

👍 4