This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-13
Channels
- # beginners (78)
- # boot (27)
- # cider (13)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (216)
- # clojure-android (1)
- # clojure-conj (6)
- # clojure-greece (1)
- # clojure-italy (11)
- # clojure-russia (127)
- # clojure-spec (63)
- # clojure-uk (34)
- # clojurescript (68)
- # core-async (5)
- # cursive (5)
- # data-science (1)
- # datomic (4)
- # dirac (11)
- # editors (7)
- # events (1)
- # graphql (12)
- # hoplon (39)
- # jobs (1)
- # liberator (3)
- # lumo (101)
- # off-topic (14)
- # om (3)
- # onyx (3)
- # parinfer (14)
- # re-frame (10)
- # reagent (2)
- # remote-jobs (1)
- # ring-swagger (17)
- # sql (21)
- # untangled (38)
- # vim (3)
- # yada (23)
I mean. I don't want to use a high-level framework like luminus, I really just need straight-up 1 post and 1 get - there should be a way to do that without going into 50 different files, no?
you could use raw lein new, but then you would need to edit project.clj to add all the right deps for ring
@eslachance then don't use luminus, us compojure
lein just gives you clojure by default, ring doesn't come with clojure, no web server comes with clojure
yeah but I could have just added the dependencies to project.clj, which I did of course
well you did it wrong
Probably. Let me try this again, in case I really was that dumb, there.
apparently, I was, both times. Welp.
I swear I'm not an idiot, I just play one on TV
the proliferation of nested dependencies is an issue with clojure (and with the java ecosystem in general), but our dep management is actually pretty good once you get to know it
I actually have worked with clojure enough that this was just a derpy moment. TBH I'm just slowly getting back into it after 9 months of not touching it. https://github.com/eslachance/dithcord is proof that I'm usually not that empty-headed.
¯\(ツ)/¯
Hello guys! What is the easiest way to build a RESTful application with clojure? Or best API
Check out compojure-api as a starting point @victora
If you want something simpler, with less magic, and you don’t mind rolling it yourself, just basic Compojure could get you going (and you’ll need to understand Ring and Compojure somewhat to use compojure-api anyway).
I started a lein project with a compojure template and it was just what I needed. Simple also!
I have another task, though. I need to build a simple database myself. (Not use any API). To be fair, it's not even a database, but a map from int's to lists. Very simple. How can I accomplish state in clojure, though?
an in-memory store? I'd use an atom
a thread safe mutable data storage for immutable data
you can update it via swap!
So basically I'll have an atom with an empty map, and whenever a request occurs, I'll do something with it and swap
pretty much, yeah, but the ! is part of the name, swap!
Need a tiny bit of help, probably just a very quick spoonfeding... I just need to open an H2 database inside my file, and there isn't a flurry of examples online. Luminous uses conman
, and that's the closest I've been to actually finding code that uses h2 in clojure.
That is unless anyone else has an idea of just... a very simple persistent string-based key-value
system that doesn't require any setup, that'd be super awesome. (I used LevelUp/LevelDown with node if that's any indication)
as low-level as possible, no server, no auth, no queries. Just set/get, is all I need.
@eslachance Try connecting with https://github.com/clojure/java.jdbc and don't forget to add the H2 driver to your project.clj
Actually, that looks like a good resource! Thank you 😄
@eslachance Happy to answer any of your Qs around java.jdbc
as I maintain it. It's fully tested against H2.
I'll see if I can figure it out first, this is a seemingly very easy project made difficult by my necessity to learn new things 😉
But I'll keep that in mind 😄
i've defined a lein alias to seed a database, however when i call it via lein run seed
it instead just runs (-main)
, and the function i'm trying to call doesn't run at all. any ideas?
aliases {"seed" ["run" "-m" "my.seed/setup"]}
but for some reasons I get exceptions like
No matching ctor found for class com.amazonaws.services.s3.model.PartETag
@joshkh: I think the way aliases work is that you define the namespace they start with, but they will always call a function (-main)
inside that namespace
So you'd want something more like aliases {"seed" ["run" "-m" "my.seed"]}
and then rename your setup
function to -main
...just keep it distinct from the namespace you specify in the :main
key of your project.clj, which has the version of (-main)
that gets run if you just do lein run
by itself
hmm okay i'll give it a shot. any idea why it's running the myapp.core/main regardless?
Not really sure, I'd expect an error
@4n5u: your syntax for the constructor there looks incorrect to me, instead of (new Tag)
you'd want (Tag.)
, so more like (map #(.setTag (Tag.) %) tags)
new
is valid, but not recommended - (Tag.)
actually expands to (new Tag)
@timgilbert thanks for the advice but no luck. renamed setup to -main, changed the alias, but lein run seed
still just runs core/main and the seed main is never called
Oh! You want just lein seed
, not lein run seed
lein seed
'seed' is not a task. See 'lein help'.
Did you mean this?
new
repl
deps
less
help
test
that did the trick. thanks a lot, @timgilbert !
Sweet, glad to hear it
@4n5u - based on your error and @noisesmith's correction, I think the problem is that you are trying to call a no-arg constructor that doesn't exist for your class
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/PartETag.html
You'd need something like (map #(Tag. partNumber %) tags)
Not sure where you get partNumber
though
use map-indexed, they should be in order
A sorted-set
isn’t strictly a red-black tree, but it should have similar performance characteristics if that’s what you’re after.
Eh, not 100% sure but I think it uses the Comparable
interface
@victora any arity-2 function is a comparator (clojure.core/compare being the default one). Use clojure.core/sorted-set-by to make a set with a custom comparator
Most clojure json libraries will convert an arbitrary seq into a json vector
There is no json type which unambiguously preserves the clojure set type, to say nothing of a sorted set. Converting from a sorted-set is free, but you’ll have to explicitly convert back to a sorted-set if you need to consume this json from clojure.
@victora it's already a seq 🙂
In your repl, you can do e.g. (cheshire.core/generate-string (sorted-set [3 2 1]))
and see
there’s a lot of options - we have threads and schedulers and such, quasar makes sense if you need to track scheduled things across multiple hosts and / or restarts
ring itself doesn’t have anything for scheduling, but iirc pedestal does