Fork me on GitHub
#beginners
<
2019-01-12
>
Artemo11:01:49

привет от медоед

bartuka14:01:18

hi ppl, I am trying to use stuart's component to setup my compojure/ring webapp and inject the database to be available to any incoming request

bartuka14:01:16

(defn create-new-system []
  (component/system-map
   :database (new-mysql-db)
   :platform-http (component/using (new-platform-http)
                                   {:db :database})))

bartuka14:01:53

is it right? if so, how can I have access to the :db at the endpoints now.

madstap15:01:53

@iagwanderson That looks right, when you start the system you should have access to the db inside the platform-http component.

Chase15:01:26

so I'm following the simple instructions here: https://www.reddit.com/r/Clojure/comments/abcd5a/new_clojurians_ask_anything/ed0zfg2/ to explore cljs and figwheel, etc. I always get to this part in the figwheel processing: Prompt will show when Figwheel connects to your application and then nothing happens. I've had this happen when exploring other tools like shadow-cljs too. My localhost:3449 says site can't be reached either. what am I doing wrong?

dpsutton16:01:31

can you try instead of localhost?

dpsutton16:01:03

I just ran it and it works for me. Are you on windows by any chance?

dpsutton16:01:53

figwheel had the following message for me: > Figwheel: Starting server at http://0.0.0.0:3449 does your output include this? it should tell you where the app is being served

Chase16:01:18

That doesn't work either. Here is my full terminal output. I remember the same thing happening when trying out shadow-cljs using a beginner tutorial. It just never connected. Here is my full terminal output, not sure if the warnings are relevant:

chaselambert@penguin:~/projects/cljs-demo$ lein figwheel
Warning: implicit middleware found: cider-nrepl.plugin/middleware 
Please declare all middleware in :middleware as implicit loading is deprecated.
Warning: implicit middleware found: refactor-nrepl.plugin/middleware 
Please declare all middleware in :middleware as implicit loading is deprecated.
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Figwheel: Cutting some fruit, just a sec ...
Figwheel: Validating the configuration found in project.clj
Figwheel: Configuration Valid ;)
Figwheel: Starting server at 
Figwheel: Watching build - app
Compiling build :app to "target/cljsbuild/public/js/app.js" from ["src/cljs" "src/cljc" "env/dev/cljs"]...
Successfully compiled build :app to "target/cljsbuild/public/js/app.js" in 0.867 seconds.
Figwheel: Starting CSS Watcher for paths  ["resources/public/css"]
Figwheel: Starting nREPL server on port: 7002
Launching ClojureScript REPL for build: app
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild id ...)        ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once id ...)             ;; builds source one time
          (clean-builds id ..)            ;; deletes compiled cljs target files
          (print-config id ...)           ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
          (figwheel.client/set-autoload false)    ;; will turn autoloading off
          (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application
[Rebel readline] Type :repl/help for online help info
 

Chase16:01:34

I'm on debian stretch

dpsutton16:01:37

couple things. check your profiles.clj for outdated stuff. probably remove everything in there to be honest. Then, what is your lein version

Chase16:01:13

Leiningen 2.8.3 on Java 1.8.0_181 OpenJDK 64-Bit Server VM

dpsutton16:01:33

can you remove the cider-refactor stuff?

dpsutton16:01:58

> Warning: implicit middleware found: refactor-nrepl.plugin/middleware

Chase16:01:20

probably. this profiles.clj seems pretty advanced for me

dpsutton16:01:28

and get rid of this as well > Warning: implicit hook found: lein-environ.plugin/hooks

dpsutton16:01:38

you don't need anything in your profiles.clj file

dpsutton16:01:44

probably best served by deleting it

Chase16:01:35

hmmm? so i created this using lein new reagent cljs-demo +cider like those beginner instructions said. it created the project.clj file for me. I should just delete the whole thing?

dpsutton16:01:46

there's a file ~/.lein/profiles.clj that i'm talking about

dpsutton16:01:53

you probably have some old junk in there

Chase16:01:53

Yeah, this is a completely fresh install of everything because I haven't figured this out. I don't even have a .lein/profiles.clj file

Chase16:01:12

I thought you were saying delete the profiles.clj file in the cljs-demo project

dpsutton16:01:35

oh no. i'm sorry

dpsutton16:01:47

that project.clj not profiles.clj

dpsutton16:01:52

project vs profiles

dpsutton16:01:57

gets confusing sorry 🙂

Chase16:01:13

my fault. yeah, but no profiles.clj either

Chase16:01:40

it's been a frustrating problem. As I said, a similar thing happened when trying to use shadow-cljs. Not sure what I'm doing wrong. I just want to interact with these things with my sweet emacs/cider goodness!

dpsutton16:01:23

i hear you. i can't replicate your experience though. it sounds like something is funky with your machine

thheller16:01:42

what is the actual problem though? what happens when you curl -I for example?

Chase16:01:14

HTTP/1.1 405 Method Not Allowed Cache-Control: no-cache Content-Length: 0 Server: http-kit Date: Sat, 12 Jan 2019 16:28:00 GMT

thheller16:01:28

ok so that is replying

thheller16:01:41

what does the browser say when you open http://localhost:3449?

Chase16:01:19

This site can't be reached. localhost refused to connect

thheller16:01:12

do you have a proxy configured? or some browser extension that may be blocking local connections?

Chase16:01:00

Doesn't work. What is weird is figwheel is saying things are successful, it just never completes that final step.

Chase16:01:29

I've tried the luminus tutorial and that connects to my localhost just fine. Could it be a cljs specific thing?

thheller16:01:34

something seems to prevent you from loading that page. so CLJS isn't even loaded yet.

dpsutton16:01:22

just crazy question, but you're not using docker or anything like that right?

Chase16:01:30

interesting question actually. i'm on a pixelbook (chromebook) running their crostini linux capability which is sort of containerized I think. It's debian stretch.

Chase16:01:08

But I've had other things connect to my localhost fine. Things like luminus and things like Rust's rocket web framework.

Chase16:01:51

This figwheel runs smoothly right until the very last part and just hangs there. But it gives me no errors or anything during the build process

dpsutton16:01:44

right. it is waiting for a browser to connect to it to serve as the js engine of the app. What is happening is that a simple webserver is not seeing any connections on 3449. that's the fundamental problem

dpsutton16:01:57

and with the confusion of the crostini stuff i have no idea what is going on

Chase16:01:06

let me try something. I'll put a standalone browser inside crostini.

Chase16:01:27

and we have lift off! Yay! Ok. so usually things inside crostini can jump out to my chromeos chrome browser. but i installed firefox inside the linux distribution and tried the localhost there and it connected!

Chase16:01:59

thank you so much folks. My apologies for not being clear on my os setup. this has been killing me! To the point where I was blaming clojure and it's "brittle" tools and questioning my sanity. of course it was user error the whole time.

dpsutton16:01:56

yeah you just have multiple computers in your computer. so localhost is a bit ambiguous

Chase16:01:49

yup. it's weird how clojure (not clojurescript) and rust and others use my chromeos localhost and cljs uses the debian one.

Chase16:01:20

that was a super smart question about docker though. I couldn't have done it without you! Awesome tech communities are awesome!

athomasoriginal17:01:35

Hey all, looking for suggestions on a better way to my data structure. I am updating columns in my db. Normally, all columns (in my case) that require updating are pk or fk columns. So I can safely do an update-map like:

{1 5 55 68 8 47}
However, one table i have is "polymorphic" in that there is 1 column on the table telling you the type of resource it refers to and another column telling you the specific id of the resource. Think: https://hashrocket.com/blog/posts/modeling-polymorphic-associations-in-a-relational-database This poses a problem because unlike an fk column, for the plymorphic table if multiple columns have 1 as a value, it does not not mean that they are all referring to the same resource. So now, my update-map above won't work for all tables. I am trying to think of alternative way to handle this. some thoughts:
{:file/1 5 :folder/55 68 :other-resource/8 47}
Another thought is maybe attaching meta_data? Thoughts?

lilactown22:01:56

I don’t understand your first example {1 5 55 68 8 47}

lilactown22:01:04

is 1 the name of a column?

lilactown22:01:32

and 55 another?

lilactown22:01:51

and is pk/`fk` referring to primary key / foreign key?

lilactown22:01:15

your second example is not so clear what you’re trying to do either. what are the namespaces supposed to help with?

peter-kehl22:01:20

Hi @lilactown, it's a map. The odd items are keys, even items are respective values.

peter-kehl22:01:06

Some people put a comma after each pair. Comma is optional (it's a whitespace). {1 5, 55 68, 8 47}

lilactown22:01:29

Lol @peter.kehl I appreciate the info but I'm asking him about the semantics of the problem

peter-kehl22:01:50

Access by key: ({1 5, 55 68, 8 47} 55) ;=> 68

lilactown22:01:57

I'm well aware of how clojure data structures work 😉

peter-kehl22:01:31

Ah, I see, you followed up on a previous question...

peter-kehl22:01:22

Hi team. Imagine you have a macro that would be run at the top level only. It doesn't seem to be able to inject (def ...). Can it somehow create new def variables in the consumer's namespace, please?