This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-16
Channels
- # beginners (176)
- # boot (11)
- # cider (12)
- # cljs-dev (65)
- # cljsrn (54)
- # clojars (18)
- # clojure (195)
- # clojure-austin (1)
- # clojure-dev (2)
- # clojure-italy (8)
- # clojure-quebec (1)
- # clojure-russia (51)
- # clojure-serbia (3)
- # clojure-spec (24)
- # clojure-uk (28)
- # clojurescript (41)
- # cursive (14)
- # data-science (60)
- # datascript (2)
- # datomic (111)
- # emacs (6)
- # figwheel (1)
- # graphql (16)
- # hoplon (26)
- # juxt (2)
- # lein-figwheel (3)
- # lumo (12)
- # off-topic (8)
- # om (14)
- # pedestal (22)
- # perun (2)
- # proton (1)
- # re-frame (29)
- # reagent (27)
- # ring (17)
- # ring-swagger (2)
- # rum (3)
- # spacemacs (3)
- # unrepl (155)
- # untangled (28)
- # vim (4)
Anyone knowwhere I can find examples of create-table-ddl useage? https://clojure.github.io/java.jdbc/#clojure.java.jdbc/create-table-ddl Googling around, I get all forms of java examples, but not clojure examples.
Is there a library (Clojure or otherwise) that could be used to alter an existing PDF? For instance put a signature on it, dates etc. I already have experience with clj-pdf (https://github.com/yogthos/clj-pdf), but I'm pretty sure that it (and iText, which it depends on) is only for generating pdfs from scratch.
cjmurphy: Java interop? https://pdfbox.apache.org/
Thanks @U2J7JRTDX - that should be just what I'm looking for.
There's even a wrapper! https://github.com/dotemacs/pdfboxing
I was mainly looking for an example that shows putting an image at a [x y] location on a PDF. The image being a signature.
@U0D5RN0S1 see this: https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.java?view=markup it shows you how to do just that. Aaaand when you do it, please consider creating a PR so that the functionality can be in pdfboxing
. 🙂
The reason it isn’t there yet, is because I never needed to do this so I never ported it. Hope it helps
Didn’t port entirety of massive Java library? That’s a :table_tennis_paddle_and_ball:
I know how to write a buffered iamg (name ans) out to a file as png via
(ImageIO/write ans "png" ( "output/test.png"))
no, my question: how can I write this to a in memory string instead of output/test.png ?ByteArrayOutputStream
and only C would call it a string
@noisesmith : right, it's not a string, it's a ByteArray
I mean, it's trivial to get a string from the ByteArray, but that probably won't do anything at all useful
write it to a ByteArrayOutputStream and then copy the bytes over? maybe there's a way to get it to write to the array...
wait, do you have an array already and want to put the image in there too, or do you mean you just need an array? for the latter, there's a method on ByteArrayOutputStream to get its contents as an array
I need to insert triplests of the form (font-name :: string, unicode :: int, image :: 32x32 png file)
OK - so I would hope it would accept a bytearray for the third arg...
but I don't know jdbc enough to know that for sure
but what I would try, is telling ImagIO to write to the ByteArrayOutputStream then get its byte array and pass it to jdbc - that seems intuitive (sorry to say I haven't tried so I can make no promises...)
another option is to derive a ByteArrayInputStream from the ByteArrayOutputStream (this is an input that gives you the bytes the imagio wrote) and try passing that as the last arg
this document makes it look like jdbc expects an inputstream (if it works with a File object, that's your ticket), so what you want is to make a ByteArrayInputStream out of the ByteArrayOutputStream's array
+user=> (import ( ByteArrayInputStream ByteArrayOutputStream))
java.io.ByteArrayOutputStream
+user=> (def b (ByteArrayOutputStream.))
#'user/b
+user=> (.write b (.getBytes "hello, world"))
nil
+user=> (def b-in (ByteArrayInputStream. (.toByteArray b)))
#'user/b-in
+user=> (slurp b-in)
"hello, world"
using a string because that's easier to demonstrate in a repl, but the concept is sound
(let [f (first (filter #(.canDisplay % \a) all-fonts))
ans (draw-text f "yg" 4 22)
ba (ByteArrayOutputStream.)]
(ImageIO/write ans "png" ba)
(j/with-db-connection [conn db-spec]
(j/insert-multi!
conn :letters
[{:unicode 20 :font_name "foo" :png (.toByteArray ba)}])))
got it working; thanks!awesome!
Lets say I have a function which has some data as its params and then inside that function I have an anonymous function (with a specific signature (not defined by me)) that closes over that first functions params. Lets say I want to make the anon function a real named function. In javascript, I would have to make a function that returns a function that closes over the param. In clojure I am betting there is a macro that lets me say "call this defined function, and close over this variable" Perhaps the best way to do it is partial so that way I can turn the anon function into a named function that takes one extra param at the begining of its list and then use partial to "close over" the variable I want.
I guess, I solved my own problem. I didn't know to use partial until I started writing.
@slightlycyborg: Also you don't have to have a partial function - you can instead have a defn
that returns a fn
. This 'inner' function is not usually given a name.
Calling all Singaporean clojurians or anyone who might be traveling to this part of the world, we have a dedicated clojurians slack channel #clojure-sg, please join to this channel if wants to share or wondering what we do over Singapore Clojure.
Hi Everyone! I am following a book on web development with clojure and Stumbled on this bit of code:
(ns
(:require [compojure.core :refer [GET defroutes]]
[clojure.tools.loging :as log]
[immutant.web.async :as async]
[cognitect.transit :as transit]
[bouncer.core :as b]
[bouncer.validators :as v]
[guestbook.db.core :as db]))
(defonce channels (atom #{}))
(defn connect! [channel]
(log/info "channel open")
(swap! channels conj channel))
(defn disconnect! [channel {:keys [code reason]}]
(log/info "close code:" code "reason:" reason)
(swap! channels clojure.set/difference #{channel}))
(defn ws-handler [request]
(async/as-channel
request
{:on-open connect!
:on-close disconnect!}))
For me it feels like the channels atom is used in a very OOP like fashion. Beeing global in the namespace and changed in the connect! and disconnect! functions
@nadejde you're absolutely right. This is probably to keep the example small. If you're looking to manage state in your application you might want to check out https://github.com/stuartsierra/component
alternatives are https://github.com/tolitius/mount and https://github.com/weavejester/integrant
i have two projects, so I have:
foo/build.boot
foo/src
bar/build.boot
bar/src
now, I want to have some code src/shared, which is in both foor/src and bar/src -- is a symlink my best approach ?oh, I also need this to play nicely with boot.watch, so when I update src/shared, I need foo and bar to both recompile
Hi I am from Java background having 4 yrs experience. I am planning to learn Clojure & ClojureScript. I do not have any knowledge on functional programming 1. How easy or difficult it is learn and create competency. 2. How long would it take to learn for our JAVA resources 3. Where is this predominantly used
1. most importantly it's fun, especially for a java programmer; 2. depends; 3. many of the areas where Java is used
@nadejde that code is pretty idiomatic. reference types are usually stored at the top level of a namespace so other functions in that namespace have direct access. You can choose to fully purify those functions, by passing in the channels
atom and having them work on the passed in ref, but that may or may not be the best idea. Depends on the purpose of the namespace and how it relates to the other namespaces in your application and the outside world. But with regard to state management for your whole app, I agree with stijn. A component sort of lifecycle management system for your state is smart.
@ramamurthi_k 1. What d'you mean with easy? Check https://www.youtube.com/watch?v=cidchWg74Y4 and https://www.infoq.com/presentations/Simple-Made-Easy . These talks will give you an idea of why - it's all about motivation and eagerness to learn new stuff (you know 'Beating the Averages' of Paul Graham?), so it may be 'easier' when you have a good motivation. 2. Are they willingly to learn or not? (if not, well, I wouldn't want them as devs - that's what you mean with 'JAVA resources', right?) 3. Where d'you want it to be used. It's not limited to 'one specific area'. It can do what Java can do, but usually in a simpler way. Where is Java predominantly used 😛?
Certainly check https://www.youtube.com/watch?v=cidchWg74Y4#t=2m16s about easiness to learn etc.
Just to add more subjective context: 1. Clojure is the easiest language out there. 2. Knowing Java makes programming Clojure even easier. 3 Mostly web apps and data manipulation. Not yet much in the embedded, memory constrained platforms, like IOT.
> 1. Clojure is the easiest language out there. I like that one 🙂.
well, it's one of the languages that I picked up pretty fast, but I'm not sure if it's because of the language, or just because having background in different other languages makes you pick up languages faster 🙂
Any opinions on hugsql vs honeysql vs korma? I'm using hugsql right now, but I'm tempted to switch to honeysql due to its composability features looking nicer than hugsql snippets
Korma has fallen a bit out of favor, I think. Honeysql is definitely more amenable since it's plain old data structures. Can I ask what specific parts of queries you're looking to compose?
@mikeb The example I'm thinking about right now is a WHERE
clause where I can dynamically add more AND
s
@curlyfry Haven't use hugsql, but I've used honeysql a lot, am mostly happy with it and strongly prefer it over korma.
@evo @bpiel Definitely prefer the "helpers" route over ORMs. Thanks for the pointers!
It depends on the SQL queries that you need - if you need complex queries, you should definitely avoid ORM for these.
When you need to write complex SQL, hugsql/yesql/jeesql approach is better imo, but you can always mix and match
tatut: specql looks really cool! I might wait until the "EXPERIMENTAL" is gone from the readme, though 🙂
Here's a fun topic: failure The kickstarter for Sayid Pro is solidly on track to fail. My hopes for reversing that trend are not high, but I would like to at least come away from this feeling like I've learned something. Over the past few months, even since the launch, I've gotten a lot of positive feedback and direction from many people. If everyone who has expressed interest in purchasing sayid pro were to back the campaign, while success would still be far from guaranteed, things would be going much better. I don't think it's a problem of exposure. The kickstarter page has seen over 1k visitors, with a significant portion watching the video in its entirety. So, my question is: Why hasn't this perceived interest translated into backing? Any thoughts and feedback are appreciated. I'm available through email (see https://github.com/bpiel), twitter @bpiel or you can DM me here. thanks!
bpiel: I watched the whole video, and thought that it looked very cool (the video and the tech), but ultimately couldn’t see that it would fit my workflow
I want Sayid Pro to succeed but kind of feel bad that theres all these big companies who use Clojure and yet none of them are pitching in
So I’m thinking what tooling are they using that they don’t need to support your attempt
I remember seeing the first announcement for sayid
and though “very cool I’ll have to try it someday”. But I haven’t got to (yet).
And then I saw the sayid pro kickstarter and thought “that’s great but way too early for me, since I still haven’t tried it”. I remember thinking that this could fail for this reason.
So in my case there is interest, and I use to back up clojure projects that I use (there was a core.typed campaign I contributed to for instance - even if I don’t use it anymore). It was just too early for sayid in my case.
To give you a timescale, I know it took me months before being comfortable with my emacs bindings, then some months more to introduce plugins (like clj-refactor, some linters that I dropped later on etc.).
Another possibility: it could also be that the first reward at $10 is too low (I seem to recall that at $10 core.typed gave you your name on the github or something like that).
@bpiel I’ve used Sayid once or twice but think it’s unlikely I would have need for the Pro version currently
I quite like the idea for what it is worth. I could see it used on our integration servers at some point.
@U0ALP2929 Thanks for the feedback. You really don't need to use (or know anything about) sayid to get value from sayid pro. If you ever do use sayid, please let me know how it goes.
@U064X3EF3 I believe anyone who deploys bugs to servers could get value from sayid pro. Maybe I'm wrong about that, or maybe I just didn't give a convincing demonstration of the potential.
Yeah, I don't deploy Clojure code, I deploy code to Clojure. :)
@U064X3EF3 mind blown
And to be clear, I'm all for more tools
The question is, when do you cut your losses and move on? It's a tough one. Congrats on being honest with yourself 🙂 I'm def not the target audience, but I liked your campaign.
In general, people will be much more supportive in words. So it's difficult to gauge intrinsic interest. It's probably a good idea to take yourself out of the equation as much as possible when doing your market research. If your personality tends to sell the product up front, their positive response may be more a reflection of your positivity than their real interest in the project. Super hard to know.
Is there something like reify
but with a base instance? I know I can refer to the surrounding local scope, but I don't want to reimplement all the interfaces, but the once I care about.
@branch14 I'm pretty sure reify will fill in any not implemented methods with "throw new NotImplemented..."
I'm new to Clojure and having an odd issue, anyone got a minute? Pretty sure it's an easy one
@marcusf sure, just ask 🙂 or perhaps in #beginners if it's a super simple question.
@tbaldridge Allright. Not sure if it fits in Beginner or not, I'll ask here in case. I'm trying to output the current time. I found this snippet online, which works when I do println
(.format (new java.text.SimpleDateFormat "hh:mm") (java.util.Date.))
But when I stick if in a function, it prints object info instead of the time:
(defn currTime[]
(.format (new java.text.SimpleDateFormat "hh:mm") (java.util.Date.)))
(def awesomebutton (button :text "Sometext"))
(listen awesomebutton :action (fn [e] (println currTime)))
This works
(listen awesomebutton :action (fn [e] (println (.format (new java.text.SimpleDateFormat "hh:mm") (java.util.Date.)))))
But not the one above.@tbaldridge I would like the the result of reify to "behave" like a given base instance, except for the reified interfaces.
@branch14 base instance? So you mean you want to inherit a abstract class?
it lets you give a class or interface and definitions for methods. if any are missing it uses that from the super class
so you're looking for what cljs implements as specify!
, which doesn't exist in clojure
yes, you can't do that on the JVM
well, you kinda can do that if you can restrict yourself in dealing just with interfaces and not concrete classes
These two ways of accessing a value in a nested map seem equivalent
(def mymap {:a {:b 1}})
(get-in mymap [:a :b])
(-> mymap :a :b)
which one is the preferred form?
@gigasquid plz ignore me if you're busy, but running your cool kaggle-cats-dogs and getting a 'No such var: loss/max-index, compiling:(kaggle_cats_dogs/core.clj:174:43)' after 'lein run to train'... any clues about what might be wrong?
(-> mymap :a :b)
is the most performant, I believe.
but I wouldn't say one is preferred, the both have tradeoffs
the get-in
one is more flexible and works with other types of keys rather than just keywords
(just as an FYI)
@gigasquid I coudn't find cortex 4.0 and am using 5.0 if that's a possible factor.
get-in
also allows for a not-found
if you need that. e.g. (get-in mymap [:a :b] "not-found")
I am very new to programming and am currently learning Racket. I have fallen in love with the syntax, or lack there of. So, Clojure feels like the natural next place to go,. Are there any good video series on Clojure?
For instance, there are a plethora of tutorial video series on Python, I am simply asking for a recommendation for a Coursera course or edX course or YT series .
@whitwulf @arthur has a http://lynda.com series on Clojure https://www.lynda.com/Clojure-tutorials/Up-Running-Clojure/413127-2.html ; there are also tons of various videos on Youtube you can hunt for, though quality may vary
@gigasquid for what's it's worth, adding [cortex.util :refer [generate-id max-index]] to core.clj fixed the error.
@macrobartfast - I can't dig into it right now - but cortex has been changing really rapidly lately approaching 1.0. Not surprised if my stuff broke. I'll have to revisit sometime
I've found this: http://cljwamp.us
But the client part (which is what I need) is JavaScript using http://autobahn.ws/js
I've found some Java libraries that I could use, but wondered if there's a better way. I've found a WebSocket client for Clojure (https://github.com/stylefruits/gniazdo-jsr356), but not sure if it's suitable.
@gigasquid all good... I'll submit patches as I can. I got everything working... great tutorial, and thanks!
Hello! I searched clojure lib for workflow managment, like airflow
or luigi
, with schedule tasks, ui and so on.
The only result by me — https://github.com/Factual/drake
But it seems kind of unusual.
Anyone know any alternatives?
for people determined to use clojure.java.jdbc -- is there a bunch of examples somewhere? all the docs here https://clojure.github.io/java.jdbc/#clojure.java.jdbc/db-query-with-resultset show params, but not examples
@qqq honeysql renders to the vector that you pass in for sql-params
, so https://github.com/jkk/honeysql has a lot of examples of what those might look like
@rustam.gilaztdinov Netflix has an amazing tool called Dagobah, but unfortunately they haven't finished opensourcing it. They described it at the Conj a couple years ago: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwji7cveqvXTAhWHESwKHfKvDCIQtwIILDAB&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV2E1PdboYLk&usg=AFQjCNE_uWfxaHqUVxAWLOhRyb1PM6SGtw
@ghadi this is sad 😞 but thx!
Unrelated to above. I can't believe we only get any? in clojure 1.9 🙂 Things like checking if a value is contained in a list are so miserable as is without it
matan: https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L538 how is that useful?
that looks to me like it’s just (constantly true)
?
am I misreading something?
from the name, I would’ve guessed it was something along the lines of (bool (some even? '(1 2 3 4)))
, but it looks like just always returns true
no matter what you pass in?
@matan any?
doesn't do what you think it does. Use some
if you want to check for membership in a list, or use a set and use set membership operations.
@rustam.gilaztdinov you can view it as sad -- or you can be inspired by how extremely well thought-out it is
@ghadi after the some
I have to translate to true or false, in order to follow with more logic. that is cumbersome.
unless I play with the language's truthiness rules all along the logic I perform downstream. I don't like the latter option, it obfuscates what the code is doing and is just bizarre
(some #(= % value-i-want) collection)
doesn’t seem terrible, right? you get true or false, works for nil
What wiseman said. Or what you said @matan: (boolean (some #{value-you-want} collection))
Take a monetary analogy to the clojure core functions: It's not designed to have an $42.37 bill, but rather a $20, a $1, 10c, some pennies, etc.
most practical cases in clojure you don't have to coerce to true or false, because truthiness in clojure is not insane like other languages
it doesn’t work for all values; specifically, it doesn’t work if the value you’re looking for is nil:
user> (if (some #{nil} [1 2 nil 3]) :works :broken)
:broken
I am hard to see the gain in alienating most programmers with this idiosyncratic way of handling logic though...
user=> (.indexOf '[a b c d e f g] 'b)
1
Why does transduce
calls the transformed reducing function on the final result? https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L6602
reduce
doesn’t do that.
it's the "completion" function. A lot of times you want to run reduce then 'fixup' the result at the end. A good example is transient/persistent:
(transduce (map inc) (fn ([c] (persistent! c)) ([c input] (conj! c input))) (transient []) coll)
ghadi: Cool, but you’d want to do that w/ reduce
as well, no? Yet reduce
doesn’t do that. I’m just puzzled by the asymmetry b/c AFAIK transduce
is supposed to be like reduce
w/ a transformation of the reducing fn.
transduce was made many years after reduce, and it handles stateful reducing functions.
But back to the heart of your question, the completing function also "flushes" some stateful transducers
Like partition-all
https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L6965-L6971
if a project has a dependency on a particular library that (for whatever reason I haven’t quite figured out) is incompatible with clojure.spec.alpha/1.9, is there anything one can do to remedy the incompatibility? Or is it left to patching the old lib to be 1.9+ compatible?
For example, I’m writing a proxy server that uses 1.9+, but has a dependency on clj-http
.. trying to bring that library into my project fails with a whole series of foo fails spec clojure.core/import ... clojure.core/quotable-import-list ... package-list
etc.
Which seems to be pretty clear: a bunch of forms in the library aren’t conforming to the defined specs. (though this seems quite strange .. would import and import-lists change between 1.8 and 1.9?). Or I’m doing the dependency-pull-in process incorrectly and I need a clojure adult to hold my hand.
@lwhorton it’s not that import changed, it’s that import used to accept all kinds of garbage that is no longer silently ignored
ah so that form validation in 1.9 is now conditional on whether spec’s on your classpath?