Fork me on GitHub
#clojure
<
2015-12-08
>
meow01:12:24

(defn skeletonize-test-01 []
  (let [mesh (-> (cu/cuboid -5 10)
                 (op/seed->mesh))
        original-faces (:faces mesh)
        mesh (-> mesh
                 (op/skeletonize :thickness 5
                                 :get-f-factor (fn [{:keys [faces]} face]
                                                 (when (= face (last faces)) 0.5)))
                 (op/skeletonize :thickness 3
                                 :get-f-factor (fn [_ face]
                                                 (when (original-faces face) 0.25)))
                 (op/rep op/catmull-clark 4)
                 (g/tessellate)
                 (op/colorize))]
    mesh))

kurtlazarus03:12:20

@meow: What lib are you using?

meow05:12:33

@kurtlazarus: thanks. I'm using http://thi.ng for the mesh datastructure and then my own mesh operators and X3D output from here: https://github.com/pkobrien/cad

meow05:12:21

I was using OpenSCAD for a while but am focusing on mesh manipulations for now.

meow05:12:57

You can get a better feel for that last model using the 3D tool here: https://www.shapeways.com/model/3dtools/4125821/1/26?key=bc7a8e9cd83b2179a5b9aff42e3ca96b

andrewboltachev06:12:07

Hi. How do I install projects via maven? E.g. JDBC MySQL driver?

andrewboltachev06:12:15

Nevermind, I just had to add [mysql/mysql-connector-java "5.1.6"] to my build.boot file (and no manipulations with maven)

firinne06:12:13

Recently came across this book — Quantum Physics and the Philosophy of Alfred North Whitehead. Since I only became interested in Whitehead after seeing “Are we there yet?” figured some people on this list might also appreciate https://muse.jhu.edu/books/9780823250219

firinne06:12:19

* Mechanics

roelof08:12:50

someone a tip for this challenge : http://www.4clojure.com/problem/166

txus09:12:38

I understand that core.async/chan takes a transducer optionally, but is there a function to map over the values of a channel and transform them? or apply a transducer ex post facto?

txus09:12:27

hm I’ve tried map but I think I’m holding it wrong

txus09:12:25

admittedly I’m on ClojureScript. Should I ask there?

txus09:12:42

basically this code causes an error:

clojure
(let [ch (chan)]
  (go (>! ch 100)
      (close! ch))
  (go (println (<! (async/map inc ch)))))

txus09:12:08

Uncaught Error: [object Object] is not ISeqable

txus09:12:17

gonna bring it over to #C03S1L9DN. thanks!

d-t-w09:12:23

map is deprecated

d-t-w09:12:11

take a look at pipeline, pipeline-async

txus09:12:15

but not map :S

d-t-w09:12:39

ah you're correct, sorry my mistake. The pipeline variants are mostly to do with doing things in parallel so maybe map is fine in your case.

d-t-w09:12:47

there's only one error in your example (above)

d-t-w09:12:50

(let [ch (async/chan)]
  (async/go (async/>! ch 100)
    (async/close! ch))
  (async/go (println (async/<! (async/map inc [ch])))))

d-t-w09:12:11

async/map takes a collection of source channels, not just the one.

niwinz10:12:10

@txus: the map function receives a collection of channels instead of one channel

txus10:12:46

yeah, @d-t-w mentioned it… it’s probably just nitpicking but I’m surprised its signature is not variadic like clojure.core/map.

txus10:12:55

is there a reason for that?

niwinz10:12:03

I don't know but seems that clojure.core.async/map does not corresponds to the default map semantics

niwinz10:12:21

its doc says that it applies the function to the first value of each channel in the collection of channels that you can provide...

hoopes11:12:09

@niwinz yeah, i was looking at octet and buffy, but couldn't find a "takes a byte array, returns a map based on the spec" function (unless i'm blind)

niwinz11:12:39

this is just that octed does...

hoopes11:12:54

ha, all right then. i must have missed something awfully obvious - i'll keep working. thanks very much for the note!

niwinz11:12:34

(def spec (buf/spec :field1 (buf/int32)
                    :field2 (buf/int64)))
(buf/read buffer spec)
;; => {:field1 2 :field2 3}

hoopes11:12:18

buffer is the byte-array in that example?

niwinz11:12:23

buffer should be bytebuffer, and if you have byte array, you can create byte buffer from it just using (ByteBuffer/wrap yourbytearray)

hoopes11:12:57

awesome, thanks so much

niwinz11:12:26

You are welcome!

niwinz11:12:13

it explaines the same thing that I have put in example 😄

hoopes11:12:37

yeah, i could see how to put data in as map/vector, and read it back out, but the byte-array part was the hurdle i couldn't clear - just getting started, so i really appreciate your help (if there's a different channel for the embarrassingly simple questions, i'll happily go there instead)

niwinz11:12:36

this is a funcool project so you can join in #C093UFM4M channel and ask any question about any funcool project 😉

chedgren11:12:49

async/map is deprecated, regular 'ol map you'll have to pry from my cold, dead, hands

crankyadmin12:12:01

I suspect this is going to be a stupid question but... I have a vector of maps` [{:yada "foo" :name "bar"} {:yada "foz" :name "baz"}]` and I'd like to dissoc :name from each map. Whats the best approach?

martinklepsch12:12:48

@crankyadmin: (map #(dissoc % :name) vecs)

crankyadmin12:12:54

thanks I just got the exact something on the repl.

martinklepsch13:12:24

@crankyadmin: 👍 repl is always good to work out this kind of stuff simple_smile

derwolfe14:12:21

in clojure, if someone has placed there implementation inside of a`lib.impl` and is exposing it through lib, should the lib.impl namespace be treated as private?

cjmurphy15:12:41

lib.impl and lib are not related to each other, any more than any other namespaces would be.

cjmurphy15:12:31

So impl is just as related to lib as lib.impl is - which is to say not at all.

meow15:12:05

@derwolfe: I believe you are correct that it is a convention to treat the impl namespace as sort of a private matter, though Clojure doesn't enforce any privacy.

cjmurphy15:12:08

By convention (from Java libraries anyway) you know you are doing the wrong thing if you are making a call to a lib.impl function/method, but there is no actual way to make the namespace private.

Alex Miller (Clojure team)15:12:08

in the future (Java 9) with modules, that may actually be possible. but that's a long, long way off for Clojure (if ever)

meow18:12:06

Here's a tip if you are relatively new to Clojure, like me. I do my "debugging" using (prn) statements and was wondering how I might do them inside some threading and came up with something that works. Here is an example:

(->> (d/value-set :f vertices v)
                             ((fn [x] (prn "Faces: " x) x))
                             (map fnormals)
                             ((fn [x] (prn "N-all: " x) x))
                             (set)
                             ((fn [x] (prn "N-set: " x) x))
                             (transduce identity g/+ v/V3)
                             (g/normalize)
                             ((fn [x] (prn "Fnorm: " x) x))
                             (d/index! norms))

meow18:12:45

So the trick is the ((fn [x] (prn "N-all: " x) x)) function

meow18:12:42

Anyone know if there is a way to simplify that or use a function literal thingie #() instead?

exupero18:12:42

@meow: I usually define a macro to do that.

(defmacro spy [x]
  `(let [x# ~x]
     (println '~x "=>" x#)
     x#))

dmitrig0118:12:44

@meow: i do the same, often just define a function for it

roberto18:12:12

(partial prn “N-Set “)

dmitrig0118:12:13

(defn spy [name x]
  (prn name x) x)
...
(->> stuff
     (spy "test"))

dmitrig0118:12:25

@roberto: that won't return the value though

roberto18:12:34

ohhhh, I see

rantingbob18:12:21

It would be really useful to be able to send stuff to a gist...I wonder if theres an alfred workflow for that

exupero18:12:23

@meow: The advantage of using a macro for spy is that you can print out the form rather than manually giving a name.

exupero18:12:57

Also, a single argument function/macro is nice as it works with both -> and ->>.

meow18:12:39

@dmitrig01: Great suggestion, thanks.

meow18:12:55

@exupero: Ah, yes. I like that. Thanks.

meow19:12:32

@exupero: I made it a bit more vertical for my situation, and it works great. Much appreciated.

(defmacro spy [x]
  `(let [x# ~x]
     (println "<=" '~x "=>")
     (println x#)
     x#))

exupero19:12:15

No problem.

rantingbob19:12:11

I know this probably a dumb question, but do people keep ther eown little utils namespaces with these kind of tools?

cab19:12:03

if using leiningen, you can set a :dev profile

noisesmith19:12:10

there's also user.clj

gtrak20:12:55

@rantingbob: yes, I have a namespace that's pretty much required in every other namespace for every project i've worked on

gtrak20:12:06

and I tend to copy-paste from flatland/useful but I refuse to depend on that entire project simple_smile

gtrak20:12:22

it sucks, but we can't monkey-patch core in a modular way simple_smile

simax9920:12:58

@meow @exupero spy also exists in this handy toolkit of utils https://github.com/cloojure/tupelo

exupero20:12:13

@simax99: I knew I had seen it somewhere long ago, but couldn’t find the repo. Thanks for digging it up for me.

meow20:12:24

I've avoided depending on one of these grab-bag libraries but I may have to revisit that, or create my own, like @gtrak and others do

Tim20:12:36

where you you save a namespace that is required in all your projects?

simax9920:12:18

@meow @exupero No problem, it was mentioned on the clojure gazette (http://www.clojuregazette.com/) recently.

crankyadmin20:12:20

Hi, I'd like to execute a query on Hive h

crankyadmin20:12:49

via JDBC. But I need to set autoCommit to false. I think I wo

crankyadmin20:12:26

* grrrr safari is bad.... I think I want execute! but can't work out how to use it with autoCommit set to false.

donaldball20:12:31

You need to specify the :transaction false option, IIRC

crankyadmin20:12:49

That throws a java.lang.Boolean cannot be cast to java.lang.String exception.

(defn run-hive-query!
  [file-path message]
  (println message)
  (let [q  (string/split (slurp ( file-path))  #"\n")
        db  {:subprotocol "hive2"
             :classname "org.apache.hive.jdbc.HiveDriver"
             ;; :subname "//host:10000"
             :subname "//localhost:10000"
             :user “username”
             :password “password”}]
    (j/db-do-commands db :transaction? false q)))

donaldball20:12:17

The q needs to be a vector, doesn’t it?

donaldball20:12:39

I can’t recall the semantics of db-do-commands offhand tho, pretty sure I used execute!

crankyadmin20:12:25

doesn't split return a vector?

cab20:12:43

it should

noisesmith21:12:38

donaldball: I'd say the set of things that truly need a vector is small enough that they are mostly either a) things that are specifically vector tools like subvec or b) mistakes that should have supported other sequential types

Pablo Fernandez23:12:14

What’s the best way to have one or more example programs that exercise my library in my library’s project? Should they be full leiningen projects on their own?

rantingbob23:12:00

I really wish there was a faster way to switch between active panels in Cursive...and a shortcut to jump to the repl window. I miss that from Sublime.

Pablo Fernandez23:12:34

@rantingbob there’s a Cursive channel and @cfleming hangs out here. You can ask for that directly from him 😉

rantingbob23:12:48

Sorry, I'm new to slack