Fork me on GitHub
#beginners
<
2016-02-11
>
stig00:02:07

I’ve got a little toy duct app with one endpoint that accepts parameters when I run it in the repl & browser, but the handler doesn’t get any parameters when I try to test it with kerodon. code is here: https://github.com/stig/accounts/pull/1 - I would be very grateful for some assistance as I’ve spent all evening getting nowhere :-(

stig00:02:25

I’m not actually sure if it makes sense to call kerodon’s session with a handler that I lift out of a component… that may very well be my problem.

Chris O’Donnell02:02:59

@sooheon: I'm not familiar with that library, but I think you should use get.

sooheon02:02:33

Hm reading more, I guess map.controls is an array? so the square brackets are accessign the array, and putting input into that place?

Chris O’Donnell02:02:19

Your last line would look like (.push (get (.controls map) js/google.maps.ControlPosition.TOP_LEFT) input))

sooheon02:02:34

Ah I see thanks :)

sooheon02:02:23

codonnell: I’m getting map.controls is not a function, even though it’s clearly an instance of js/google.maps.Map. any idea what could be wrong?

sooheon02:02:53

Hm, actually, .SearcBox above is not working either, Uncaught TypeError: Cannot read property 'SearchBox' of undefined

Chris O’Donnell02:02:58

I think controls is a property of map, not a method.

sooheon02:02:05

The let binding is inside :component-did-mount in a reagent/react class

Chris O’Donnell02:02:05

So you would access it with .- instead of .

sooheon02:02:23

Ah right .- for properties

Chris O’Donnell02:02:12

I'm not sure why you would get your searchbox error message.

sooheon06:02:40

^^ the error was because I had not loaded the places library (it’s not included in the maps api by default)

stig09:02:26

It turned out I had neglected to include an app component in my test-system, so none of the middleware was wrapping my handler.

stig09:02:49

that’s why my param never reached my handler

naomarik09:02:10

I found this: http://www.mattgreer.org/articles/embedding-svg-into-a-reagent-component/ and i'm trying to figure out how this would work.. form what I understand the tagsoup dependency is clojure whereas reagent is clojurescript

martinklepsch10:02:13

@roberto: if working on the filesystem directly: (file-seq (io/file "resources"))

ordnungswidrig10:02:54

naomarik: in the example, tagsoup is used in a macro which means it’s executed as clojure when clojurescript is compiled.

ordnungswidrig10:02:28

naomarik: you can use reagent’s hiccup syntax to create svg elements for rendering.

ordnungswidrig10:02:50

naomarik: the point of the article is, that you typically do not want to create an SVG from scratch so this code parses the SVG during clojurescript compile time to a hiccup datasctructure.

naomarik10:02:41

@ordnungswidrig: to give some background of my project: it's a rails application with some reagent baked in. i've got some SVG files that I'd like to inline

naomarik10:02:49

but i'm unsure how this would work since i'm only including javascript in the project (no clojure backend)

naomarik10:02:12

so i would love to be able to parse the SVG data structure and include it in a reagent component

naomarik10:02:30

but not sure how to do this in the context of my project

doddenino11:02:53

I'm starting to look into om.next, and I have a doubt: is it worth to use it with a db like mongo? It seems it's made to be used with datomic/datascript mainly

ordnungswidrig11:02:44

@naomarik: with a clojurescript macro, as in the article, the parsed SVG would be embedded into the js as a clojurescript value.

naomarik11:02:12

but it would do it once right on js complilation time?

ordnungswidrig11:02:42

@naomarik: yes, clojurescrupt macros are actually clojure code executed at compiliation time. Do the SVGs change over time?

naomarik11:02:28

they're just images from a design, so once it's compiled it's fine, i just want to be able to style and animate them easily

ordnungswidrig11:02:01

in that case, the svg will end up as a „value“ in the js. you can manipulate that in clojurescript as you need.

naomarik11:02:35

so in order to get this to actually work, i add [clj-tagsoup "0.3.0"] as a dependency to my project then include the snippet he has for the macro in src/clj/embed/svg.clj right?

naomarik11:02:57

okay, i've attempted this already and failed.. will try again

ordnungswidrig11:02:58

with (def svg (embed-svg "cool-svg-image.svg“)) you will end up having the SVG as a „hiccup“ data structure in svg

naomarik11:02:14

yah this is what i'd like

ordnungswidrig11:02:24

i.e. [:svg {:x 0 :y 0 :width 50 :height 50} [:rect {:x 10 :y 10 :width 10 :height 10}]]

naomarik11:02:32

just attempting to get the macro working now

naomarik11:02:43

i have my reagent stuff in src/cljs

naomarik11:02:55

so i would make a src/clj and add it to my source paths in build.boot?

ordnungswidrig11:02:33

That looks sensible. I’m no expert with boot but you’d follow the general recommendation with clojurescript and boot, I think

naomarik11:02:41

okay so my confusion now is how to use this.. i've got the macro in src/clj/embed/svg.clj exactly as the author put it. in my cljs file when I attempt to refer to it, i get this error No such namespace: embed.svg,

naomarik11:02:55

it seems like it tries to look in cljs namespaces only so it fails

naomarik11:02:44

[embed.svg :refer [embed-svg]] is on top of my cljs file, this doesn't seem to work cause the macro is a clojure file not clojurescript

sooheon13:02:26

Using postgres hstores, the db expects a value string such as:

'"paperback" => "5",
"publisher" => "",
"language"  => "English",
"ISBN-13"   => "978-1449370001",
"weight"    => "1 ounces”’
What is the best way to write a query for this in Yesql? If my Yesql query looks like
UPDATE foo-table
SET hstore-field = :data :: hstore
WHERE id = :id: 
It’s not clear to me how :data should be shaped on the clojure end.

sooheon13:02:13

Specifically because clojure doesn’t have single and double quotes. I’ve tried escaping strings, which didn’t work.

sooheon14:02:13

decided to just go with serialization to text—much simpler

eggsyntax14:02:52

That sounds like much less of a pain in the neck 😉

eggsyntax14:02:53

But if you had to do it literally, I would expect "'\"paperback\" => \"5\", ..." to work.

sooheon14:02:26

Ah I must have been out of it I only thought to do "\"paperback\" => \"5\", …” … without the single quote in there. That might have worked.

meow17:02:58

@naomarik: also #C0F0V8DT5 for more SVG help

meow17:02:28

@eggsyntax: Hello, my friend.

naomarik17:02:40

@meow thanks but don't need specific SVG help - just basic config for setting this up simple_smile

feltnerm20:02:07

is :as the way to alias a required namespace? e.g. (require ‘overtone.inst.synth :as synth) would give let me type synth instead of overtone.inst.synth?

feltnerm20:02:13

hmm… what have I done?!??

live> (require 'overtone.inst.piano)
nil
live> (require 'overtone.inst.piano :as piano)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: piano in this context, compiling:(*cider-repl replovin*<2>:141:6)

akiva20:02:19

Although does that work? I’ve always done (require ‘[overtone.inst.synth :as synth]).

akiva20:02:08

Try putting it in a vector.

feltnerm20:02:40

ah, nice that works

feltnerm20:02:36

hmm… so that works fine in REPL-land, but when I require the file/namespace containing those piano/drum/etc requires I get a compilation error:

CompilerException java.lang.Exception: Found lib name 'overtone.inst.drum' containing period with prefix 'quote'.  lib names inside prefix lists must not contain periods, compiling:(live.clj:1:1)

feltnerm20:02:52

(ns live
  ;; (:use [overtone.inst.drum :as drum]
  ;;       [overtone.inst.synth :as synth])
  (:require '[overtone.inst.drum :as drum]
            '[overtone.inst.synth :as synth]
            '[overtone.inst.piano :as piano]
            [repl :refer [reset]]))

(println "WE'RE DOIN' IT LIVE!")

feltnerm20:02:16

require vs :require?

ghadi20:02:57

yeah, it's a common stumbling block. In a ns declaration, "libspecs" should have keywords :require

feltnerm20:02:58

had to remove the initial

ghadi20:02:04

and everything unquoted ^^

ghadi20:02:41

When mucking around in the REPL, the opposite: require and use are regular functions, and thus no keywords, and their arguments are quoted

ghadi20:02:44

the ns decl is just weird. it's worth memorizing that as a cheat ^

ghadi20:02:59

glad you got it sorted @feltnerm

olegakbarov22:02:09

with korma what’s the best way to create a record (if one with particular value not already exists in db)? i tried raw SQL but postgres 9.4.4 do not support ON CONFLICT

Drew Verlee23:02:25

can someone help me understand how this counts the elements in a list?

reduce (fn [c _] (inc c)) 0

Drew Verlee23:02:52

might only make sense with the rest of the code...

Drew Verlee23:02:51

(= ( reduce (fn [c _] (inc c)) 0 '(1 2 3 3 1)) 5)

Drew Verlee23:02:54

That's short but seems like a confusing use of reduce

Drew Verlee23:02:42

im working through 4clojure and i'm having trouble discerning good solutions and ones that are short.

bridget23:02:35

Are you talking about the solutions you see when following people in 4clojure?

feltnerm23:02:58

@drewverlee: reduce calls an accumulator function for each element in the list. Looks like each time it is called the accumulator is simply incrementing c.

Drew Verlee23:02:06

@bridget yea. Solutions from the ppl you can follow.