This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-26
Channels
- # aws-lambda (1)
- # beginners (71)
- # boot (70)
- # bristol-clojurians (1)
- # cider (2)
- # clara (13)
- # cljs-dev (96)
- # cljsjs (6)
- # cljsrn (5)
- # clojure (74)
- # clojure-android (3)
- # clojure-austin (4)
- # clojure-dev (10)
- # clojure-russia (6)
- # clojure-spec (28)
- # clojure-uk (128)
- # clojurescript (64)
- # cursive (2)
- # datascript (18)
- # datomic (116)
- # dirac (1)
- # emacs (12)
- # events (10)
- # hoplon (109)
- # jobs (1)
- # jobs-discuss (21)
- # leiningen (2)
- # luminus (6)
- # off-topic (19)
- # om (21)
- # om-next (5)
- # onyx (4)
- # parinfer (29)
- # perun (20)
- # re-frame (53)
- # reagent (21)
- # remote-jobs (5)
- # ring-swagger (2)
- # spacemacs (6)
- # untangled (42)
- # vim (5)
Welp, I am back after 2 months of not touching any clojure code.
This is going to be fun
So, I have an atom in which I have a :handler
key, which contains the following:
{:MESSAGE_CREATE [#object[dtbot.core$handle_message 0x6f8ac246 "dtbot.core$handle_message@6f8ac246"]],
:READY [#object[dtbot.core$on_ready 0xe8edfc6 "dtbot.core$on_ready@e8edfc6"]]}
I'm trying to dynamically call one of these functions
(get-in @session [:handlers :MESSAGE_CREATE])
works fine
But this does not: (get-in @session [:handlers (:t msg)])
(assume the :t
key contains the string MESSAGE_CREATE
)
what am I missing?
And yes @7h3kk1d I'm super happy to come back to it after months of mucking around with node.js ugh
I'm sure it's a super simple answer I'm looking for but my usual one-on-one expert is probably raiding right now 😞
yes, it's nil
so, string
so how do I convert a string to a symbol
But you're typecasting it to a str there so maybe try just removing the str function.
yes sorry that was just a test
hmm
(get-in @session [:handlers (symbol (:t msg))])
=> nil
wait it's a keyword I need no?
EUREKA
I'm still missing some of that terminology. You did help with that, thank you 😄
Alright quick question. I can do a condition like (nil? func)
but how do I "invert" it? in JS I would do if(!null)
for example
Clojure docs are always confusing >.<
so (not (nil? func) ; do stuff)
?
(if-not (nil? func) func(argument))
then.
err yes
excuse my JS leftovers
darn I'm getting an Arity exception... that function is defined as accepting 2 arguments
(defn handle-message [session message]
(if (= (get message :content) "ping")
(dithcord/send-message session "pong!" (get message :channel_id))
)
)
It's being printed as [#object[dtbot.core$handle_message 0x7f29d7f3 "dtbot.core$handle_message@7f29d7f3"]]
in the repl so it looks like the right one
hmm. wait... that's an object.
NEVERMIND
Sometimes I'm smarter than my own good - I prepared for having more than one handler for incoming events and forgot ^_^
Sure I'm missing something here, but this isn't the behaviour I'm after...
user=> (instance? com.blah.evt.Events$Foo foo)
(instance? com.blah.evt.Events$Foo foo)
true
user=> (instance? com.blah.evt.Events foo)
(instance? com.blah.evt.Events foo)
false
@poooogles Because of class nesting, they aren't really related (other than sharing a hierarchy). No idea if there's a way to find the outer class for something.
I mean (supers foo) might tell you something interesting
You can probably ask those questions via reflection but they're probably not good questions to ask :)
Reflection answer seems to be this one: http://stackoverflow.com/a/15265900
Hi, I have an 800Mb XML file that could contain illegal characters and needs to be sanitized. So I can (filter #(<= 32 (int %) 256) file-contents)
but slurping the file gives me a heap space error…am I stuck writing the sanitized file back out, then reading it back in to parse as XML, or are there other options?
jcronk: perhaps this would be useful for this: https://github.com/thebusby/iota
Sorry, I’m a little stuck on 800Mb XML file
You probably want to work the bytes using good ol’ http://java.io InputStream and OutputStream
Read a buffer, write the good bytes, rinse, repeat until finished
You may yet have heap problems actually holding the parse tree in memory tho
data.xml is pretty good, though. I was able to use it to process a clean file that was almost 1Gb, and it does great. I’m just having problems here because of the invalid characters and not knowing Clojure or Java especially well.
@jcronk Are you trying to clean out all the characters outside the legal range or only if they appear as text elements inside xml tags?
If you don’t need to know whether the character is inside an xml tag, maybe just treat it like a raw binary file for filtering purposes: read a block, filter it, write a block.