Fork me on GitHub
#clojure
<
2017-04-28
>
tbaldridge00:04:12

run! is probably what you want there

cfleming00:04:45

Oh nice, thanks - TIL

cfleming00:04:53

Thanks for the advice!

arthur00:04:04

I'm using clojure/java.jdb quite a lot and I'm pondering how to cancel abandoned requests. I don't see a place to do this, or a way to extract the jdbc statement to do it directly, anyone know if this is something that already exists? Of if there is somewhere else I should be asking about this?

romain01:04:21

I'm sure there is a better way to achieve that, someone has an idea ? (def pos ["zero" "one" "two"]) (for [i (range (count pos))] (print i " - " (get pos i))) I don't like to call get each time

tbaldridge01:04:49

Vectors are associative, so this works:

tbaldridge01:04:21

(reduce-kv
  (fn [_ k v]
    (println k " - " v))
  nil
  pos)

romain01:04:17

Thanks! I'm going to dig it

romain01:04:48

@tbaldridge and if I want to return something instead, for example a map {:i k 😛 v}, reduce isn't helpful here ?

noisesmith01:04:11

a reduce can return any type you like

romain01:04:57

Sorry, I meant if I want to return a map for each element in the vector

noisesmith01:04:33

yes, reduce can do that

noisesmith01:04:03

+user=> (reduce-kv (fn [acc k v] (conj acc {:i k :p v})) [] ["zero" "one" "two"])
[{:i 0, :p "zero"} {:i 1, :p "one"} {:i 2, :p "two"}]

romain01:04:07

I'm so tired xD

romain01:04:27

I forgot about the acc, thanks!

romain02:04:23

I should bench them for fun 😛

romain02:04:42

Even if my collection is less than 20 elements... ><

qqq04:04:11

Is WhaleSong the only Racket -> JS compiler, or is Carmark using something else to do Racket -> JS ?

dominicm09:04:05

Just getting started with Apache Spark. I'm wondering if there's a best™ library to interact with it?

dominicm14:04:12

viesti: powerkeg's No AOT goal ❤️ That's amazing

dominicm14:04:44

ooh, and transducer support

dominicm14:04:48

blowing my mind right now

Niclas11:04:45

Do we have anyone here who’s using Clojure and AWS Lambdas in production? Opinions on it?

viesti11:04:30

have been using Clojure based Lambdas for more than a year now

viesti11:04:34

been quite happy

viesti11:04:07

but the really neat thing is this: https://github.com/cgrand/portkey

viesti11:04:15

Portkey will really shake things up 🙂

viesti11:04:02

think live coding Lambdas, not in the AWS GUI, but in your familiar repl

robert-stuttaford11:04:23

just picked my jaw up off the table.

viesti11:04:42

not yet ready, but let’s see 🙂

cgrand11:04:49

if we start to talk about it in public, let’s create a channel #portkey

not-raspberry12:04:04

How should I name: - A function that finds the closest date of a given weekday in the past or today - A function that finds the closest date of a given weekday in the future or today ?

rauh12:04:38

Presumable accept the given date as the first param to make it pure 🙂

not-raspberry12:04:09

It doesn't need to be impure, it can accept now as an argument.

not-raspberry12:04:01

The actual problem is that while 'last' may imply that today is accepted, 'next' doesn't.

not-raspberry12:04:39

so next-weekday-date is an iffy name

rauh12:04:39

I'd stick close to the new java time api. previous-or-same. See java.time.temporal

dergutemoritz13:04:29

how about most-recent-weekday-date?

not-raspberry13:04:12

I changed the code to assume a week range from the current week, so I don't need those functions 🙂

not-raspberry13:04:11

Developing code intended to be primarily used from the REPL exhibits an interesting conflict between user-friendliness and consistency.

brycecovert15:04:01

@coltonoscopy I used play-clj to produce a commercial point-and-click adventure (tick’s tales)

sveri15:04:59

Hi, I have immutant in project as a dependency which adds wunderboss-core as dependency which comes with a logback-default.xml in its jar. When starting my server the logback-default.xml takes precedence over my own log4j.xml that I have in my resources folder. The same happens when creating an uberjar. Is there a way to configure the priority of the log configurations?

sveri15:04:40

@jcrossley3 Thanks, I will be trying this, should have checked the docs first

curlyfry15:04:36

@coltonoscopy @brycecovert I'm taking the freedom to link @brycecoverts dev blog: http://www.tickstales.com/dev-blog/ It's pretty awesome!

curlyfry15:04:54

(and I just bought the game 🎮 )

brycecovert15:04:21

@curlyfry - thanks! wow! Blogging is really hard, it means a ton to have someone say it’s insightful!

brycecovert15:04:22

and I hope you like the game! Probably more relevant to folks here might be my talk at clojurewest last year: https://www.youtube.com/watch?v=lql2yFXzKUs

juliobarros16:04:07

Is there a good/common way to (centrally) throttle/rate limit outgoing http requests? I need to call an API many times (from different parts of my app) but am being rate limited on their end and want to control my request rate. Thanks.

val_waeselynck16:04:00

@juliobarros core.async is good for doing this, essentially you can use pipeline-async or pipeline-blocking to explicitly set you parallelism.

val_waeselynck16:04:30

You can complement this by implementing exponential backoff, which again is fairly easy to implement with core.async

juliobarros16:04:18

Thanks @val_waeselynck do you know of a gist, example or library that takes care of all the details? Btw, you are vvvvalvalval aren’t you? Great name 🙂 and I’ve used your libraries! Thanks.

val_waeselynck16:04:39

wow thanks 🙂

val_waeselynck16:04:05

exponential backoff:

dergutemoritz16:04:37

Beware that the parallelism at least for pipeline-async (not sure about pipeline-blocking) is not precise. See https://dev.clojure.org/jira/browse/ASYNC-163 for some details.

lvh16:04:31

is there a style preference for t/testingmacros? I feel like writing a bunch of prose is appropriate but Clojure doesn’t really have an applicable multiline string literal, right

val_waeselynck16:04:48

@juliobarros as for http req throttling, here's the basic idea:

juliobarros16:04:52

Thanks @val_waeselynck I’ll check out the gists.

val_waeselynck16:04:51

> Clojure doesn’t really have an applicable multiline string literal

val_waeselynck16:04:06

@lvh What do you mean? What's wrong with clj string literals ?

lvh16:04:57

there’s no multiline string literal like e.g. Python’s """/`'''` that editors know about

lvh16:04:15

so you can’t write long prose entries in t/testing without telling everyone to soft-wrap

val_waeselynck16:04:23

@lvh yes there is, unless we don't talk about the same thing

lvh16:04:37

(def(n) docstrings are a notable exception)

lvh16:04:55

OK; what does a long clojure.test/testing string look like?

val_waeselynck16:04:00

;; this is valid clojure "a multi line string"

lvh16:04:52

there’s a subtle difference there; Python’s docstrings (not strings in genearl) don’t carry that formatting data around with them, and IIRC cljfmt doesn’t really like what clojure-mode does with filling those by default (except for docstrings): the indendation matches the (t/testing ...) baseline, not testing + 2 or the opening quote for the string

lvh16:04:13

but mostly what I’m asking is: is there something of a style guide standard around this

val_waeselynck16:04:25

not that I know of

lvh16:04:53

(clojure-style-guide does not)

val_waeselynck16:04:50

Maybe you should write a (multiline s1 s2 s3 ...) macro 🙂

lvh16:04:45

that sounds like it’d make editor integration a lot worse than just fixing string-literal-with-newlines-in-it

val_waeselynck16:04:54

yeah you're right

val_waeselynck16:04:02

didn't think it through

lvh16:04:06

anyway, thanks for the soundboard, at least I’m not missing the obvious

matan17:04:20

as clojure is homoiconic, just wondering if there's any cool code refactoring library out there, I might not know how to google for that, or, nothing I found on my own looks quite stellar

matan17:04:09

e.g. I'm manually replacing one library with another across my source files in one project, and in a different universe I'd write a program that does it for me (go through all sources, find and replace under ns definitions in this one case, maybe make a backup.

matan17:04:39

I'm sure to write this one day, just wondering if there's already something out, possibly covering more useful concerns than I am thinking of

brycecovert17:04:13

@matan I’ve written a program that did some complex searching for certain patterns in a clojure program using slamhound’s asplode (https://github.com/technomancy/slamhound) - may be helpful

brycecovert17:04:48

I didn’t use it to manipulate any code, only to find certain patterns, but it seems like that might be half the problem for you

matan17:04:06

I thought slamhound was only for namespace stuff

matan17:04:14

so you just tore apart / borrowed that source for your use case?

brycecovert17:04:33

I didn’t need to change it at all; I just used asplode as is

brycecovert17:04:46

You can use it to read in a clojure file, and then tree walk

brycecovert17:04:21

It worked great for my use case; specifically finding all string arguments to any usage of a few functions within my program

coltonoscopy17:04:38

@brycecovert i watched your talk several weeks back and was inspired by the way you did your cutscenes 🙂

matan17:04:31

coltonoscopy: adding it to my watch list... curious what libraries were used there (e.g.. om and such). I was thinking of using om.next next week (pun not intended lol)

coltonoscopy17:04:50

i recommend it! he uses core.async for the cutscene stuff. im not super familiar with clojure just yet but core.async looks like an extremely powerful lib

matan17:04:53

yes I guess it is the natural choice. om is a fullstack/UI library btw, based on it I think

coltonoscopy17:04:49

hmm ill have to check it out, im actually not too familiar with it 🙂 he also uses play-clj, which is a wrapper around libGDX, a great Java game framework

zylox17:04:28

libGDX is great. I had performance problems when trying to use play-clj but it might be time for me to revisit that

coltonoscopy17:04:54

interesting, what kind of work were you doing?

zylox17:04:34

nothing terribly formal but it was around rending large amounts of sprites. It didnt seem to be batching in a way id expect it to, i had run the same kind of simple game in games where i had rolled my own game loop in java with libGDX with orders of magnitude higher amounts of things going on. Solid chance i was just doing something wrong though.

zylox17:04:49

rendering* not rending

matan18:04:21

good to know all of this!

matan18:04:48

why are some sample games libGDX here on this video https://libgdx.badlogicgames.com/ using pixels the size of cherries though? 🙂

coltonoscopy18:04:31

hm thats interesting. would be curious to see the cause, though im inclined to believe it wasnt an issue with the library, maybe just an incorrect paradigmatic usage, or something different you have to do in clojure like you suspect 🙂

coltonoscopy18:04:04

@matan talking about delver? 🙂 welcome to retro art!

zylox18:04:15

ive used fairly high res textures with little issue (in java though that shouldnt have a bearing on resolution rendering power). its not pure c++ levels of performance but its not bad

zylox18:04:41

setting up texture loading managers and pooling is as fun as it is in any language of course

coltonoscopy19:04:21

yeah high res textures shouldnt be a problem, i feel thats more dependent on your GPU than the framework, since its effectively just a wrapper around OpenGL

coltonoscopy19:04:40

i would say pooling is a little easier than say C++ 🙂

coltonoscopy19:04:47

although SFML makes texture loading not too bad

zylox21:04:53

not just the gpu, the way you do things with the shaders and interact with opengl can certainly screw it up but libgdx thankfully abstracts that away to a reasonable level.

zylox21:04:56

never used or heard of sfml actually

zylox21:04:17

ill have to check it out

coltonoscopy21:04:36

i guess, but shaders run on the GPU too 🙂 not sure what you're referring to

coltonoscopy21:04:44

and yeah if you do C++ game dev, SFML is great

zylox21:04:32

they do but i guess im saying the code can screw that up pretty easily. i find the state machine that is opengl highly fragile but maybe im just really good at screwing it up. Obviously the actual code runs on the graphics card but i tend to think of it more as coding to opengl as a "machine" than the graphics card

zylox21:04:30

but i learned opengl on the pipelining method not shaders so those characterizations arent as applicable if they ever even where

zylox21:04:03

wow grammar

zylox21:04:09

if it ever even was*

zylox21:04:25

clearly i need to stop languaging

zylox21:04:44

wait. no.

zylox21:04:54

ok im done for the day

coltonoscopy21:04:58

lol 😛 well opengl isnt particularly easy to program in. i much prefer using something higher-level

matan17:04:12

@brycecovert would that happen to be public code?

brycecovert17:04:36

@matan No, but I’d be happy to send it to you privately. 😉

matan17:04:10

brycecovert: how are these things typically done in slack these days? private channels?

matan17:04:38

just curious to see asplode in action, might use later and send back any useful stuff

brycecovert17:04:03

A very fun problem, cutscenes. I’d be interested in taking it further, which I’ve been experimenting with, lately 🙂

dominicm17:04:45

@matan look at refactor nrepl, it has features that will help

matan18:04:19

dominicm: thanks, this looks like something kind of generic that many people have invested into

dominicm18:04:56

@matan I know of an emacs and vim client

matan18:04:43

I try to avoid those, and either way the editor agnostic code (refactor nrepl) should be the best

matan18:04:52

thanks though!

dominicm19:04:37

I mean, they're both clients to that refactor nrepl

matan19:04:42

Thanks, yes I understand that.

matan19:04:53

I'm thankful enough for the refactor nrepl pointer though!

matan19:04:00

Not an emacs convert... 🙂

coltonoscopy17:04:18

@brycecovert yes and anything asynchronous, it applies well to turn-based games like the kinds i enjoy/want to write 🙂 (say, you want a character to walk to a tile in the battle grid, then cast a spell, etc.)

coltonoscopy17:04:25

to get it as concise as you did takes a lot of work though

brycecovert17:04:26

@coltonoscopy absolutely. There are many different approaches to those problems, like finite state machines, building your own scripting language, etc. core.async was a great answer - you get to write your game scripts in clojure, and it looks synchronous!

brycecovert17:04:37

Happy to take it offline for more brainstorming for your game. 🙂

coltonoscopy17:04:20

awesome, thanks! 🙂

bradford20:04:48

Are there opinions on ease of implementing component vs. integrant? I have a Ring app I need to iterate on and I'm too impatient to restart my REPL 😉

robert-stuttaford20:04:42

@bradford you’ve probably spent more time than you’ll likely save by not just grabbing one and starting 🙂

bradford20:04:59

@robert-stuttaford hahah story of my life

curlyfry20:04:03

@bradford For me personally, Integrant was a lot easier to understand

robert-stuttaford20:04:07

i like the look of integrant, personally, although i’ve never directly used either

bradford20:04:35

I used component a few years ago. Although my current design pattern is 'atoms errywhere'

curlyfry20:04:57

There are probably more resources for Component, but I think they generally apply to Integrant as well

bradford20:04:55

I could use some feedback on something I'm puzzling over. I'm building a HTTP proxy that needs to have a weird architecture. The client hits a /upload endpoint which takes a multipart-form and content-type. It then transforms that to a Ring-based HTTP response with the proper content-type. This works fine for text content. But binary content isn't quite right. An image/jpeg is corrupted, with the browser seeing it as a text blob with size of 0. I feel I'm not "casting" the data correctly, but I'm not sure how to fix it. Just setting the Response content = the content of the multipart-form isn't right.

bradford20:04:44

Maybe making the response body a input-stream is the key...

noisesmith20:04:28

how are you specifying it now? file or input-stream should work

noisesmith20:04:03

and anything that comes from a reader (like slurp) is likely broken

misha20:04:20

how do grownups merge maps of arbitrary depths?

(merge-with
  (partial merge-with merge)
  {:a {:b 1}
   :c 2}
  {:a {:d 3}})
=> {:a {:b 1, :d 3}, :c 2}
looks too specific: works for 2 levels only

tbaldridge20:04:30

There's about 10 different ways to merge keys that collide during a deep merge

tbaldridge21:04:21

So either you can write custom merge logic, or switch to a structure that doesn't require you to merge nested maps.

tbaldridge21:04:30

One of those two is what I normally end up doing ^^

misha21:04:36

thanks @tbaldridge, that's what I expected.

sashton21:04:14

with transit-clj, when reading multiple records from an InputStream, what’s the best way to detect the InputStream has no more records to read? (ie, the client can send a variable number of records, then close the socket) i see that when (transit/read) is called when there is nothing to read, a RuntimeException is thrown, but that’s not the normal use case, is it?

laujensen21:04:21

Whats the idiomatic way to make a list of a finite length which expels elements by fifo?

laujensen21:04:39

clojure.core.cache?

tanzoniteblack21:04:49

@laujensen if you’re trying to make a FIFO cache, then yeah. If you want a generic coll for that, you could probably use https://github.com/amalloy/ring-buffer , if you were trying to make a core.async buffer, you can use https://clojuredocs.org/clojure.core.async/sliding-buffer

laujensen22:04:50

Thanks @tanzoniteblack , I'll checm 'em out

laujensen22:04:12

Im just trying to make a really slim login-attempt logger which checks for high frequency attempts

noisesmith22:04:13

yeah, a ring-buffer sounds great for that (but a loop with a clojure.lang.PersistentQueue that does a pop and a conj on each iteration works too and doesn’t require a dep)

laujensen22:04:10

Just looking through ring-buffer it looks as lean as it gets, but thanks for the example

laujensen22:04:18

How did you activate the bot ?

noisesmith22:04:32

you can use /clj

laujensen22:04:02

Has anyone found a way to calculate the size of an object? I know its possible on .net now

noisesmith22:04:21

structural sharing makes that ambiguous no?

noisesmith22:04:13

a big percentage of live data in my app shares data with some other object also live in the app, it just has a few keys updated

noisesmith22:04:43

just measuring its size as a tree would be misleading about its actual heap usage

laujensen22:04:45

Well, actually you were right, it would be ambigious, but then its also a choice you have to make, regarding how you weigh the shared data. But in most cases, I figure you want the whole deal. But check out the efforts on .net

noisesmith22:04:31

yourkit lets you see the total size of referenced data in an object

noisesmith22:04:11

but my experience was that so much of the data was shared between multiple hash-maps and lazy-seqs and vectors that I still had to do a lot of work to know what the real memory culprits were

noisesmith22:04:45

one thing I found very useful was creating defrecords to replace hash-maps, just so the profiler would be able to look them up and summarize them quickly by name

noisesmith22:04:03

but not defining any keys or methods, just a defrecord used like a map

laujensen22:04:52

Ah, I havent made that distinction, but I'll try it out. Youre probably right

Drew Verlee22:04:43

Anyone want to give any software talk recommendations?

laujensen22:04:15

Any specific topic?

Drew Verlee23:04:24

@laujensen nope! Just looking for what someone else finds interesting.

laujensen23:04:31

That one was interesting re the js landscape

Drew Verlee23:04:42

great thanks!