Fork me on GitHub
#clojure
<
2016-04-20
>
mikekap00:04:44

thanks for the explanation simple_smile

jethroksy01:04:27

Hello clojurians!

jethroksy01:04:45

just wanted to generate some discussion here

jethroksy01:04:26

specifically on nil-punning

jethroksy01:04:40

am I the only one who hasn't really faced a problem with that?

jethroksy01:04:59

I want to see simple examples where it works against you

amashi05:04:09

I think better is not the right term, but...

amashi05:04:43

One thing you should ask yourslef first is, are there already operations that achieve what I want?

d-t-w05:04:52

Jetty based, http/websocket server/client. Not sure about the exact option you are after, but I have enjoyed contributing to Max's https://github.com/mpenet/alia on occasion. He's very responsive, code quality is top notch.

amashi05:04:20

I think most of the time you'll find that there are.

moizsj05:04:58

@d-t-w: thats a nice reference. But unfortunately, this too does not appear to support the 'permessage-deflate' extension. I am looking at -- https://github.com/mpenet/jet/blob/master/src/clj/qbits/jet/client/websocket.clj#L15 As you can see, its not amongst the options in the options map.

mpenet06:04:23

@moizsj I ll glady take a PR for that, it s seems quite straightforward

moizsj06:04:11

@mpenet: thank you. I am trying another approach atm (pure java interop code with the undertow websocket client lib), If i get a chance i'll make the PR.

moizsj07:04:34

@mpenet: For now, I have created two issues. One for support of extensions in the websocket client, and another for support of subprotocols. (Both I believe are supported by Jetty's ClientUpgradeRequest)

joenorman09:04:33

Hey guys, I’m relatively new to Clojure and am looking to throw myself into it by writing an executable command line application with it. Before I go into it, are there any clojars that you’d recommend I use for writing this kind of app?

joenorman09:04:43

I’m using Lein as my build tool and project builder

mpenet09:04:30

joenorman: https://github.com/clojure/tools.cli is useful for arg parsing, otherwise just uberjar your lib and you should be good to go

joenorman09:04:54

Awesome - I’ve seen that before but just wanted to check it was the best choice. Thanks @mpenet!

yatesj911:04:12

Hello All, has anybody had to sort a vector of maps with IP addresses? i have this but the sort-by does not know how to sort the addresses.

(def my-vec
      [{:id 1
        :ip "10.2.0.22"}
       {:id 2
        :ip "10.2.0.4"}
       {:id 3
        :ip "10.2.0.191"}])

(sort-by :ip my-vec) ;({:id3, :ip "10.2.0.191"} {:id 1, :ip "10.2.0.22"} {:id 2, :ip "10.2.0.4"})

manutter5111:04:43

@joenorman: also if you’re on a Mac you might be interested in planck https://github.com/mfikes/planck

manutter5111:04:22

You know, I have Replete on my iPhone, but I’ve never found anything I really want to use it for. Maybe it’s just because I’m an old geezer, but typing code on a mobile touch screen seems like way too much work for me. I wonder if I’m missing something though

sgerguri11:04:27

@yatesj9: It sorts them correctly, the problem is it will then compare the strings lexicographically (which is correct). To get around that, you need to convert the IP string to a number:

(require '[clojure.string :as s])

(let [strip-dots #(s/replace % #"\." "")
        to-int   #(Integer/parseInt %)
        ip-comp  (comp to-int strip-dots :ip)]
  (sort-by ip-comp my-vec))

(sort-by my-vec) ;=> ({:id 2, :ip "10.2.0.4"} {:id 1, :ip "10.2.0.22"} {:id 3, :ip "10.2.0.191"})

telent11:04:56

into what order does that sort "90.9.1.1" and "9.09.1.1"?

telent11:04:15

seems like the dots are important, you can't just strip them out

telent11:04:34

maybe you want something more like

telent11:04:44

(defn ip-addr-sort-key [a] (reduce (fn [m s] (+ (* m 256) (Integer/parseInt s))) (clojure.string/split a #"\.")))

telent11:04:42

which turns each address back into (more or less) the 32 bit number it represents. Handwaving slightly as the IP stack was defined by C/assembly programmers who were somewhat cavalier about punning integers and bytes

sgerguri12:04:05

Ah, good catch @telent!

martinklepsch13:04:41

I'm trying to model the flow of a conversation as a FSM using: https://github.com/ztellman/automat — now there are situations where a transition should move to a previous state (eg. "is this correct?" - "no" - "ok enter again") — does anyone have some pointers how to achieve something like that with automat?

loganmhb13:04:30

@sgerguri @telent you can also sort vectors of integers, which might be a little simpler and acts as desired here, I think

yatesj913:04:00

Sorry, i'm still having troubles, @sgerguri function works but as @telent says it will not sort correctly when stripping the dots. I can't seem to get @telent function working for me

telent13:04:29

loganmhb: yep, good point.

telent13:04:07

user=> (defn ip-address-sort-key [a] (reduce (fn [m s] (+ (* m 256) (Integer/parseInt s))) 0 (clojure.string/split a #"\."))) #'user/ip-address-sort-key user=> (sort-by (comp ip-address-sort-key :ip) my-vec) ({:id 2, :ip "10.2.0.4"} {:id 1, :ip "10.2.0.22"} {:id 3, :ip "10.2.0.191"})

telent13:04:29

yatesj9: sorry., i missed out a 0 when pasting from my repl

yatesj913:04:33

@telent: that is working perfectly, now i just need to break it down to see what it's doing and try to understand it simple_smile

martinklepsch13:04:09

;; automat with loop
(view [1 2 3 (a/* ['a 2 3]) 4])

telent13:04:22

or as loganmhb suggests you could compare vectors of integers instead of doing all that multiplying

telent13:04:24

user=> (defn ip-address-sort-key [a] (mapv #(Integer/parseInt %) (clojure.string/split a #"\.")))

loganmhb13:04:13

interestingly it only works with vectors, not seqs

loganmhb13:04:25

i.e. you need mapv

telent13:04:31

(there is some function that turns a java method into a proper function so you don't have to write #(Integer/parseInt %) , but I can't remember the name)

telent13:04:53

yes, I tried it with a plain map first, and it is as you say

amonks18:04:43

does anyone have any experience with automated dead code elimination in css?

bvulpes18:04:23

that's some dark shit, amonks

amonks18:04:27

https://github.com/giakki/uncss uses a phantom js browser, runs javascript, and extracts the set of rules that are used

amonks18:04:08

but I can’t help but wonder whether clojurepower could do something static

amonks18:04:32

would that even be “better" ?

amonks18:04:35

I do not know.

bvulpes18:04:24

1. throw out css

bvulpes18:04:26

2. hire intern

bvulpes18:04:37

3. make intern use something slightly higher-level

amonks18:04:54

^ cheating 😉

bvulpes18:04:54

eventually it'll work, provided you have something to compare the intern's work to

bvulpes18:04:03

not at alllllllll cheating!

amonks18:04:07

perhaps the best approach though ...

bvulpes18:04:14

effective capital deployment.

beppu18:04:45

Why does the Scala repl start up so much faster than the Clojure repl?

ag18:04:55

whenever I do “jack-in” in CIDER to boot.clj driven project - Java Cup icon shows up on OS X Dock. It’s driving me nuts. has anyone have this problem? Setting export JAVA_TOOL_OPTIONS="-Dapple.awt.UIElement=true” fixed that for me in terminal, but “jacking in” in Emacs still pops up foreground Java process. I can’t close it - it kills the repl.

hiredman18:04:56

you can set that same environment variable in emacs and it should take care of it

hiredman18:04:23

the way gui apps are launched in osx means they don't get environment as setup by .profile or whatever

hiredman18:04:49

if you google around you can find ways to setup the environment for gui apps by editting some plists

robincarlo8419:04:51

hi guys, do you recommend using an authentication library (e.g. Friend or Buddy) instead of using your own auth middleware?

bvulpes19:04:58

robincarlo84: nah, roll your own

bvulpes19:04:07

basic auth is just b64

bvulpes19:04:18

middlewares are simple

fasiha20:04:07

@robincarlo84: I've always heard use a library, and so I've always used passport on Node.js and will use Buddy on Clojure

dpsutton20:04:31

anytime you have this question, the answer is invariably: roll your own. This especially applies to date/time libraries and encryption

fasiha20:04:26

That feeling when you've entered Bizarro opposite-world

dpsutton20:04:14

also, definitely joking. Often libraries do whatever you need right away. And I would never write any library that deals with date times or encryption

fasiha20:04:02

@dpsutton: don't do that to noobs like us…

robincarlo8420:04:45

@dpsutton: sorry, do you mean that you prefer using an auth library?

dpsutton20:04:02

I actually have no first hand knowledge of it. But i have seen some people recommend it highly. Seems like a de facto standard

bvulpes20:04:08

question is also pretty weakly defined

bvulpes20:04:17

are you building an SPA or a postback app?

bvulpes20:04:19

do you need roles?

bvulpes20:04:35

note that none of the "auth frameworks" provide for password resets or anything else useful iirc

robincarlo8420:04:46

@bvulpes sorry for my question, and yes I will need roles too

bvulpes20:04:19

while > often libraries do whatever you need right away frequently you get three months down the road before realizing that you've bought into an authentication model that's woefully inadequate for your needs

dpsutton20:04:31

valid point as well

bvulpes20:04:35

and every project and every client is different

bvulpes20:04:49

i just shipped a client an app that has one (1) (!!!!) username and password.

bvulpes20:04:53

and this is fine.

robincarlo8420:04:23

it won't be a SPA, but it will only have a 5-7 users

robincarlo8420:04:30

1 admin and the rest are users

bvulpes20:04:57

for other, more complex work, i do different things. my SPA toolchain checks username and password at login, and returns a one-time-use token for the next request. which returns another one-time-use token.

bvulpes20:04:25

tokens which are trivially reworked to be valid for some amount of time to support UI's that make calls in parallel.

bvulpes20:04:10

the point i'm trying to make is that unless you're slamming out rails or django apps, when working in a lib-centric environment like clojure, it's frequently both more expedient and better for the codebases in question to write the auth logic for each app seperately.

bvulpes20:04:18

"but that's so sloooowwwww"!

bvulpes20:04:25

code faster, and make abstractions for yourself.

robincarlo8420:04:49

@bvulpes right, make sense.

fasiha20:04:54

@bvulpes: “my SPA toolchain checks username and password at login, and returns a one-time-use token for the next request. which returns another one-time-use token” this is cool! Can you make this into a library 😄?

robincarlo8420:04:01

thanks for your time, appreciate it

bvulpes20:04:17

i wrote that code for myself and my clients.

alanforr22:04:59

I’m trying to use codox to write documentation. It generates an index that has a heading called “Topics" on the right hand side, and under that it says “Introduction to mylibrary”. If I click the “introduction to mylibrary” heading, I get to a page with that heading and under it is written “TODO: write great documentation”. Some other libraries using codox don’t have that “Topics” heading. Does anyone know how to get rid of the “Topic” heading, or where I can put some documentation to take the place of “TODO: write great documentation”?

d-t-w22:04:09

When you create a new project with Leiningen: lein new test-project

d-t-w22:04:49

It creates a basic project structure for you, under ./test-project/docs/ you will find a generated intro.md

d-t-w22:04:03

# Introduction to test-project

TODO: write [great documentation]()

alanforr22:04:15

Ok, thanks.