thanks for the curl
tip. more head scratching
In my server.clj I have (route/resources "public")
in my non-authenticated routes
folders img
and js
both live there... img will load assets, js will give me the login page to the site o_O
I figured route/files
ought to help serve js
assets as well... maybe I need to add a specific line for that?
You mentioned a CDN above?
Can you try curl
directly against the server (without the CDN) and compare the results against the same calls through the CDN?
yeah, I stopped using the CDN for now, to debug this...
It just gives me the application login page, which is text/html of course
so that makes sense, but why is it not serving /js/ files and instead acting like i'm in authenticated territory
And your JS and image folders are both under that public
resources folder?
How are you applying the auth check in your code? Is it perhaps allowing various image file extensions through but not .js
?
good time for a sanity check as any.. š
yeah they are both under resources/public/
img | js
hmm let me double check i actually uploaded them to the server d'oh
omg i'm a fruitcake
the assets weren't there! xD
thanks Sean
Haha sorry for the mixup. I appreciate you and your helpful nature! š
:duckie:
i plugged the plug into itself.. why is nothing turning on
I've rich programming experience and getting started with Clojure. From the age we were taught Math, our brain is wired to write adding two numbers as (a+b). Now come to clojure it asks people to write (+ a b). Just imagine the strain people have to go through just to add two numbers. I have few queries below and would like your suggestion. 1) The learning curve seems to be too steep for people with prior programming experience, because programmer has to unlearn and re-learn. Could you pl let me know what business benefit Clojure is bringing to the organization? 2) Lets say a particular team in an organization choose to develop a system on Clojure. Team starts to see attritions due to higher pay package. Business wants to enhance the application. There is no resource in the market with Clojure. How can we deliver the project? 3) Is there any benchmark in run time comparison on the memory, cpu, disk io's etc that Clojure beats Java? 4) For people with prior programming experience and are frequently switching between Clojure and Java, what is your recommendation for them to be productive with both the language? 5) By adopting Clojure is there any benchmark that the time to market for bringing a new project has significantly improved when compared to other languages?
To comment on the use of prefix over infix in Clojure. While it is a bit strange, to write (+ 1 2)
instead ofĀ `(1 + 2)`, it is actually not as foreign as one might think.
When we use a method in Java we usually call it using prefix notation. For example if we put a value into a map map.put("level", 3)
the method put
is prefix. Moreover, when we define a function in math we also write it is a prefix: plus(x,y)=x + y
. To apply this function we would then write plus(1,2)
.
Recognizing this, one does not need to relearn anything. One just needs to think of +
like a function (or a method in Java), which it conveniently is.
This became a lot longer than I meant it to be. While it didn't really answer any of your questions You can consider it an argument against the steep learning curve of Clojure.
I agree, i don't think (+ a b)
is that hard to learn for an experienced programmer. Tons of math libraries use stuff like Math.pow(a,b)
or Matrix.add(a,b)
. I often find s-expression based math expressions easier to read, because the syntax is very clear and regular compared to the traditional notation with its precedence rules
also i prefer (+ a b c d e)
to a + b + c + d + e
1. There is no all round 'best' language, so it really depends on you business. Clojure is IMO really good for wrangling data, connecting services together, and exploratory programming. 2. The same could be said for any language i suppose. 3. In my experience Clojure is a little slower an memory hungry than Java, but faster to develop in, so it's worth the trade off to me. Usually bottlenecks can be fixed with interop, or writing parts in java 4. I didn't have any problem with switching. Knowing Java well helps my understanding of Clojure, knowing Clojure helps with programming in an immutable functional style in Java. 5. Hard to say, really depends on the type of project. As I said there is no all round 'best' language.
1. The "business benefit" of Clojure is that I can look at code 6+ months later and quickly decipher or immediately know what it does. I cannot say the same for any other language.
" The learning curve seems to be too steep for people with prior programming experience, because programmer has to unlearn and re-learn." Really? So when I moved from Fortran to COBOL I was supposed to unlearn FORTRAN? Pro tip: don't hire these people you have in your imagination.
1. Depends on the programmer. Weāve successfully cross-trained ColdFusion programmers to Clojure, but some really experienced Java developers seem to fail to learn Clojure. The more steeped you are in (Java-style) OOP, the harder I think FP in general is. The business benefits are many, however, and include a) ability to do more with fewer developers (because Clojure is a higher-level language) b) immutability and (mostly) pure functional approach means far fewer bugs around state or concurrency c) the language attracts a lot of really smart people who have produced some very advanced (open source) tech so you can āstand on the shoulders of giantsā
2. Not sure what youāre basing that on. Do Clojure devs get paid more than the āaverageā XYZ dev? Maybe. But you can do more with less so a small team can do more than a large Java team (in general). Training up new developers in Clojure ā by which I mean genuinely junior folk ā seems to be a very productive approach for many companies.
3. Clojure is āfast enoughā and is āokā with memory so unless you are heavily resource-constrained and/or extremely performance-constrained, Clojure is a perfectly acceptable alternative to Java (and you can always drop down to raw interop for performance-sensitive code).
(the benefits of immutability often mean that you can get more throughput, more easily with Clojure than you might be able to achieve with Java based on reliability š )
4. No idea. I havenāt used Java ādailyā for a very long time. I went from Java to Groovy in the mid-ā00s and then to Scala and finally to Clojure a decade ago. And Iāve never wanted to go back to Java.
5. The ādo more with lessā has meant ā for us, at least ā that we can add/change features much faster than with previous tech (we have a small team of experienced Clojure devs so YMMY).
I hope thatās useful feedback @esakki.sundar? Iām sure other Clojure devs will have other opinions.
Certainly, Clojure is very āalienā for dyed-in-the-wool Java developers, especially those of mediocre background/skill level ā Java provides a lot of guardrails and checksānābalances that allow low-skill developers to be āsuccessfulā writing large codebases in Javaā¦
@esakki.sundar As someone who was (still is) quite heavily into Java, mostly due to its massive ecosystem, learning Clojure has been quite a ride. Indeed switching from (a + b)
to (+ a b)
will trip lots of people (myself included for quite some time), but now that Iām used to Clojure, I actually prefer Clojureās syntax over Java because it makes things so much cleaner and more straightforward. Though I wouldnāt classify my experience as āunlearn and relearnā because itās just me looking at a different way to programming. There is no law or rule to stop me from using what Iāve learnt in Java in Clojure and vice versa. Itās just that people who have learnt āthe Clojure wayā like it enough to stick to it.
Hello, I was wondering how I could add the mathematical operators symbol to a list. Something like '('\ '+ '*) ? Then I could keep track of the operations I made on an initial number (for instance get the numbers of operations by using count on this list).
What are the main things someone switching from Clojure to ClojureScript should know? What are the main differences and key similarities?
pr-str
and read-string
are pretty important in cljs and were non-obvious starting out...
I'm trying to send messages to a datadog instance. I've proven that if from my shell I echo a well-formed message to >/dev/udp/localhost/8125
the message ends up where expected. But in a repl, something like (sh/sh "echo" (event {:title title, :text text, :tags tags}) ">/dev/udp/localhost/8125")
has no effect (`event` is just a string in the expected datagram format), and when I tried to follow https://github.com/clojure-cookbook/clojure-cookbook/blob/master/05_network-io/5-11_udp.asciidoc#sec_network_io_tcp_client I must be misunderstanding what a 'socket' is, because when I try to connect one to localhost:8125 I get the message that it's already in use
can you share what worked in the end?
it was pretty much exactly your doto
suggestion
(import [<http://java.net|java.net> DatagramSocket
DatagramPacket
InetSocketAddress]))
(def dd-socket-address (InetSocketAddress. "localhost" 8125))
(def dd-conn (doto (DatagramSocket.) (.connect dd-socket-address)))
(defn send
"Send a short textual message over a DatagramSocket to the specified
host and port. If the string is over 512 bytes long, it will be
truncated."
[^DatagramSocket msg]
(let [payload (.getBytes msg)
length (min (alength payload) 512)
address (InetSocketAddress. "localhost" 8125)
packet (DatagramPacket. payload length address)]
(.send dd-conn packet)))
#_(send (event {:title "e2e observability"
:text "pulse check"
:tags ["e2e" "test"]}))
shell/sh, despite the name, does not use a shell
so that ">" redirect is just a random input string to echo, and not actually a redirect
try (sh/sh "sh" "-c" (str "echo " ...)))
but it sounds like you could do this with spit
(spit "/dev/udp/localhost/8125" (event ...))
ā¢ (fixed arg order)
hm, elegant but no response
oh I flipped the arg order
what error did you get from the socket send?
I don't see how any of the objects/methods in the send example above could try to allocate an address (unlike TCP it's stateless and single ended)
the error from spitting (fixing argument order) is /dev/udp/localhost/8125 (No such file or directory)
so the shell knows how to interact with the device file but spit doesn't I guess?
oh I meant what error from the cookbook udp example
I tried
(def socket-address
(InetSocketAddress. "localhost" 8125))
(DatagramSocket. socket-address)
and got
1. Unhandled java.net.BindException
Address already in use (Bind failed)
i don't THINK i have state lying around but I'll restart the repl b/c why not
hmm...
nah, it's the same
I started datadog with some docker invocation and hence it's listening on that port. I assumed that "creating" a socket would mean making a Java class that was like, my end of that socket. I guess not!
that's kind of it, but the problem is that a socket isn't just an object that knows how to send or receive data, it also has a lot of ceremony and state, and that's the part that makes using it correctly difficult
maybe i need to 'connect' rather than making a new one with DatagramSocket.
?
oh right, I tried this but due to a little thing called "I have no idea what I'm doing" my connection is nil:
(def conn
(.connect (DatagramSocket.) socket-address))
(type conn) => nil
connect returns nil, you need to retain a handle to the socket object
or use doto
as a shorthand - (def conn (doto (DatagramSocket.) (.connect socket-address)))
the world of objects is kind of topsy-turvy isn't it
ohhhhh ok
huzzah!
I want to make a simple graphical game in cljs using the canvas ... are there any good projects I can use as a template?