workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | ```
Integer var10002 = Numbers.unchecked_int_inc(RT.intCast(0L));
var10000.field = RT.intCast((Number)var10002);
``` | 2017-12-07T10:36:31.000157 | Rosia |
clojurians | clojure | `(set! *unchecked-math* true)` and `(unchecked-inc-int (int 0))` | 2017-12-07T10:40:08.000594 | Kareen |
clojurians | clojure | ```
Integer var10002 = Numbers.unchecked_int_inc((int)0L);
var10000.field =
RT.uncheckedIntCast((Number)var10002);
``` | 2017-12-07T10:42:10.000423 | Rosia |
clojurians | clojure | no warnings | 2017-12-07T10:42:18.000350 | Rosia |
clojurians | clojure | that's not the code in your gist | 2017-12-07T10:43:26.000903 | Kareen |
clojurians | clojure | `(def ^:const your-var (unchecked-inc-int (int 0)))` is the closest you'll get | 2017-12-07T10:44:24.000624 | Kareen |
clojurians | clojure | you can't store primitive values in a var | 2017-12-07T10:44:54.000796 | Kareen |
clojurians | clojure | so that will box to Integer and unbox | 2017-12-07T10:45:06.000593 | Kareen |
clojurians | clojure | that's not what I want to do | 2017-12-07T10:45:26.000604 | Rosia |
clojurians | clojure | what I want is to perform arithmetic operations on a primitive instance field and avoid boxing. Local bindings only, no vars involved | 2017-12-07T10:46:18.000113 | Rosia |
clojurians | clojure | right I see what you mean | 2017-12-07T10:51:41.000478 | Kareen |
clojurians | clojure | doesn't seem to be possible ATM. I'll take a look at the compiler this evening, should be an easy fix | 2017-12-07T10:52:01.000570 | Kareen |
clojurians | clojure | great | 2017-12-07T10:53:04.000594 | Rosia |
clojurians | clojure | thank you for your time anyway | 2017-12-07T10:53:14.000401 | Rosia |
clojurians | clojure | I suspect this might be a regression since I assumed it would work | 2017-12-07T10:53:41.000377 | Kareen |
clojurians | clojure | I've been using HugSQL lately, <https://www.hugsql.org/> | 2017-12-07T11:39:30.000832 | Sandy |
clojurians | clojure | Kindof the best of all worlds, imo. The more you try to make SQL act like Clojure or any other languge, the more pain you're going to have | 2017-12-07T11:39:56.000466 | Sandy |
clojurians | clojure | better to use SQL for what its good for (Querying data) and Clojure for what it's good for. | 2017-12-07T11:40:11.000428 | Sandy |
clojurians | clojure | I have a directory of files from a jar I'm using and I want to do some filtering before reading them. I would like to do:
```
(file-seq (io/resource "com/thejar/foo-directory"))
```
but I cannot because of a `ClassCastException java.net.URL cannot be cast to java.io.File` | 2017-12-07T12:55:49.000300 | Shavonda |
clojurians | clojure | things inside jars are not files | 2017-12-07T12:57:47.000392 | Margaret |
clojurians | clojure | but io/resource should be returning a file url if the jar was extracted to disk | 2017-12-07T12:58:03.000709 | Margaret |
clojurians | clojure | you can get a seq on the resources inside a jar if you prefer not to extract - just remember that File is never the general or abstract thing in the jvm - it’s specifically and only for entries in file systems | 2017-12-07T12:59:15.000244 | Margaret |
clojurians | clojure | <@Margaret> it looks like i can do something like `(io/file (.getPath (io/resource ...)))`, yeah? | 2017-12-07T13:02:55.000513 | Shavonda |
clojurians | clojure | if it’s a file - but only if that file has been extracted to disk | 2017-12-07T13:03:10.000723 | Margaret |
clojurians | clojure | indeed it is | 2017-12-07T13:03:18.000717 | Shavonda |
clojurians | clojure | :thumbsup: | 2017-12-07T13:03:24.000411 | Margaret |
clojurians | clojure | otherwise i would need to openConnection or something on it right? | 2017-12-07T13:03:24.000833 | Shavonda |
clojurians | clojure | <@Shavonda> I don’t know how you’d get that error if it was on disk though | 2017-12-07T13:05:02.000426 | Margaret |
clojurians | clojure | no, resource returns resource urls inside jars for things that are not extracted | 2017-12-07T13:05:23.000519 | Margaret |
clojurians | clojure | ```user=> (<http://clojure.java.io/resource|clojure.java.io/resource> "config/development.clj")
#object[java.net.URL 0x74a744e9 "file:/Users/justin/sprinklr/peregrine/resources/config/development.clj"]
user=> (<http://clojure.java.io/file|clojure.java.io/file> (<http://clojure.java.io/resource|clojure.java.io/resource> "config/development.clj"))
#object[java.io.File 0x6cb513bc "/Users/justin/sprinklr/peregrine/resources/config/development.clj"]``` - no error, because it is actually on disk | 2017-12-07T13:05:42.000414 | Margaret |
clojurians | clojure | that error should mean that the url points to a thing inside a jar, which you can’t make a File out of | 2017-12-07T13:06:22.000016 | Margaret |
clojurians | clojure | ```
user=> (io/resource "models")
#object[java.net.URL 0x7f165eee "jar:file:/Users/me/.m2/repository/com/amazonaws/aws-java-sdk-models/1.11.244/aws-java-sdk-models-1.11.244.jar!/models"]
``` | 2017-12-07T13:06:49.000593 | Shavonda |
clojurians | clojure | This is a directory containing a bunch of model files which I would like to iterate over | 2017-12-07T13:07:03.000481 | Shavonda |
clojurians | clojure | see, that’s something inside a jar | 2017-12-07T13:07:07.000028 | Margaret |
clojurians | clojure | ah my bad, i saw `file:` and missed the `jar:file:` | 2017-12-07T13:07:34.000160 | Shavonda |
clojurians | clojure | that’s what the ! there means | 2017-12-07T13:07:34.000499 | Margaret |
clojurians | clojure | replicating your error: ```user=> (<http://clojure.java.io/resource|clojure.java.io/resource> "clojure/core.clj")
#object[java.net.URL 0x3d6b1a48 "jar:file:/Users/justin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar!/clojure/core.clj"]
user=> (<http://clojure.java.io/file|clojure.java.io/file> (<http://clojure.java.io/resource|clojure.java.io/resource> "clojure/core.clj"))
IllegalArgumentException Not a file: jar:file:/Users/justin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar!/clojure/core.clj <http://clojure.java.io/fn--9416|clojure.java.io/fn--9416> (io.clj:61)``` | 2017-12-07T13:07:45.000575 | Margaret |
clojurians | clojure | so, question is: how can I extract that stuff so I can work with it like a collection of files? | 2017-12-07T13:08:11.000433 | Shavonda |
clojurians | clojure | by unzipping the jar (it’s a zip file) or iterating resources instead of files | 2017-12-07T13:08:27.000122 | Margaret |
clojurians | clojure | you can do everything you want on resources, you just can’t tell the jvm they are files, because they aren’t | 2017-12-07T13:08:55.000197 | Margaret |
clojurians | clojure | What do you mean by iterate resources? | 2017-12-07T13:09:45.000674 | Shavonda |
clojurians | clojure | I mean, instead of using file-seq get an iterator on the resources | 2017-12-07T13:10:18.000322 | Margaret |
clojurians | clojure | <@Shavonda> - this should be a decent start ```user=> (.getResources (.getContextClassLoader (Thread/currentThread)) "clojure")
#object[sun.misc.CompoundEnumeration 0x77c12409 "sun.misc.CompoundEnumeration@77c12409"]
user=> (def es (enumeration-seq *1))
#'user/es
user=> (count es)
22
user=> (first es)
#object[java.net.URL 0x6be8723d "jar:file:/Users/justin/.m2/repository/org/clojure/tools.logging/0.3.1/tools.logging-0.3.1.jar!/clojure"]``` | 2017-12-07T13:12:40.000469 | Margaret |
clojurians | clojure | this is based on some quick googling about java, plus looking at the source for <http://clojure.java.io/resource|clojure.java.io/resource> | 2017-12-07T13:13:04.000306 | Margaret |
clojurians | clojure | <@Margaret> much obliged. i've been using clojure for a good long while and never have used `enumeration-seq` | 2017-12-07T13:15:04.000505 | Shavonda |
clojurians | clojure | thanks! | 2017-12-07T13:15:10.000375 | Shavonda |
clojurians | clojure | unfortunately there looks to be no way to do what i actually want to do, however, which is iterate over the files found in the directory named "clojure" without knowing their names | 2017-12-07T13:20:29.000366 | Shavonda |
clojurians | clojure | so i suspect ill need to find the jarfile on disk, unzip it to a temp dir, and read from there | 2017-12-07T13:21:00.000158 | Shavonda |
clojurians | clojure | hmm… I know there’s a way to do it. I’ll check if I can make a simple example. | 2017-12-07T13:27:35.000679 | Margaret |
clojurians | clojure | <@Margaret> I was just peeking at <https://docs.oracle.com/javase/7/docs/api/java/net/JarURLConnection.html#getManifest()> but no dice so far | 2017-12-07T13:29:20.000760 | Shavonda |
clojurians | clojure | <@Shavonda> I decided I need to know how to do this - here’s the result ```user=> (ir/zip-seq "/Users/justin/.m2/repository/org/clojure/tools.logging/0.3.1/tools.logging-0.3.1.jar")
(#object[java.util.zip.ZipEntry 0x78ffe63f "META-INF/"] #object[java.util.zip.ZipEntry 0x49f430fe "META-INF/MANIFEST.MF"] #object[java.util.zip.ZipEntry 0x5c01b068 "clojure/"] #object[java.util.zip.ZipEntry 0x1b63e89b "clojure/tools/"] #object[java.util.zip.ZipEntry 0x1c2a3bd6 "clojure/tools/logging/"] #object[java.util.zip.ZipEntry 0x74b19b6d "clojure/tools/logging.clj"] #object[java.util.zip.ZipEntry 0x25e2e763 "clojure/tools/logging/impl.clj"] #object[java.util.zip.ZipEntry 0x21c1e474 "META-INF/maven/"] #object[java.util.zip.ZipEntry 0x6cf88f11 "META-INF/maven/org.clojure/"] #object[java.util.zip.ZipEntry 0x146a1b10 "META-INF/maven/org.clojure/tools.logging/"] #object[java.util.zip.ZipEntry 0x26012f01 "META-INF/maven/org.clojure/tools.logging/pom.xml"] #object[java.util.zip.ZipEntry 0x84d8df1 "META-INF/maven/org.clojure/tools.logging/pom.properties"])``` | 2017-12-07T13:49:51.000456 | Margaret |
clojurians | clojure | <@Shavonda> code : ```(ns org.noisesmith.iterate-resources
(:import (java.util.zip ZipFile)))
(defn zip-seq
[file]
(let [zip (ZipFile. file)
entries (enumeration-seq (.entries zip))]
(mapv #(.getInputStream zip %) entries)))``` | 2017-12-07T13:50:21.000347 | Margaret |
clojurians | clojure | <@Margaret> i was trying to get clever by resolving the jarfile through the resource and opening it with openStream, then using ZipInputStream to getNextEntry, but that failed :disappointed: | 2017-12-07T13:53:54.000509 | Shavonda |
clojurians | clojure | gonna try yours out | 2017-12-07T13:54:07.000287 | Shavonda |
clojurians | clojure | I just changed it to return input-streams… but really the best might be a hash-map from entry name to function that returns input stream(?) | 2017-12-07T13:54:50.000795 | Margaret |
clojurians | clojure | are you trying to use ~ ? | 2017-12-07T13:55:43.000007 | Margaret |
clojurians | clojure | no, i was still trying to grab the path to the jar via the resource and there must be something off with that path | 2017-12-07T13:56:22.000838 | Shavonda |
clojurians | clojure | gonna compare them | 2017-12-07T13:56:31.000111 | Shavonda |
clojurians | clojure | ha! there was a trailing `$1` OOPS | 2017-12-07T13:56:49.000245 | Shavonda |
clojurians | clojure | <@Shavonda> this was fun to play with from first principles, but this might just do what you want <https://stackoverflow.com/a/5419767> - it’s better than my example above in a few ways | 2017-12-07T14:03:32.000268 | Margaret |
clojurians | clojure | that link is to a specific answer | 2017-12-07T14:03:40.000697 | Margaret |
clojurians | clojure | This is not correct. The docstring says “Blocks the current thread (indefinitely!) until all actions dispatched thus far, **from this thread or agent**, to the agent(s) have occurred.” | 2017-12-07T14:14:42.000318 | Sonny |
clojurians | clojure | unless you really want this single task | 2017-12-07T14:15:13.000071 | Sonny |
clojurians | clojure | in which case, agents are probably not a great solution. Just use a `future` and wait for it to finish. | 2017-12-07T14:16:31.000459 | Sonny |
clojurians | clojure | FileSystem is an abstraction and you could create one that worked directly on a zip/jar file as if it were files (like the demo at <https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html>). Not sure that helps you here though… :) | 2017-12-07T14:22:42.000131 | Sonny |
clojurians | clojure | ha, fair enough | 2017-12-07T14:28:48.000072 | Margaret |
clojurians | clojure | Using schema, is it possible to validate against 2 keys, that one of those keys is valid?
For example validate that password-confirm is the same as password, and if they're not, error password-confirm. | 2017-12-07T14:50:04.000310 | Jodie |
clojurians | clojure | The key thing is really the error location. | 2017-12-07T14:50:22.000318 | Jodie |
clojurians | clojure | if you mean plumatic/schema yeah I typically use schema/conditional for that - or more specifically constrained eg. `(s/constrained {:pw String :pw-c String} #(= (:pw %) (:pw-c %)))` | 2017-12-07T14:51:03.000438 | Margaret |
clojurians | clojure | that way if the keys are missing, you get a simple error - also, if you use a named function the error will show the name of the function if the function is what fails | 2017-12-07T14:53:44.000118 | Margaret |
clojurians | clojure | does anyone know of a good datomic docker image? first foray fo rme | 2017-12-07T16:34:27.000386 | Willow |
clojurians | clojure | yeah, agents are not ideal, but i need to execute the tasks sequentially, one at a time, so futures will not do | 2017-12-07T16:37:09.000056 | Jena |
clojurians | clojure | if you’re only executing tasks one at a time and waiting for them to finish, then why are you using concurrency features at all? | 2017-12-07T16:54:44.000670 | Sonny |
clojurians | clojure | <@Margaret> but where does the error message end up in the resulting map? The locations are being used programmatically to communicate error messages. So I would want to result to be: `{:pw-c (not (…))}` | 2017-12-07T17:02:32.000229 | Jodie |
clojurians | clojure | <@Jodie> I like how it does it ```user=> (require '[schema.core :as s])
nil
user=> (defn a=b [x] (= (:a x) (:b x)))
#'user/a=b
user=> (def a=b-schema (s/constrained {:a Number :b Number} a=b))
#'user/a=b-schema
user=> (s/check a=b-schema {:a 1 :b 1})
nil
user=> (s/check a=b-schema {:a 1 :b 0})
(not (user/a=b {:a 1, :b 0}))
user=> (s/check a=b-schema {:a 1})
{:b missing-required-key}
user=> (s/check a=b-schema {})
{:a missing-required-key, :b missing-required-key}``` | 2017-12-07T17:06:47.000466 | Margaret |
clojurians | clojure | `(not (user/a=b {:a 1, :b 0}))` is as direct as it can get - since the arg was an arbitrary function | 2017-12-07T17:07:40.000296 | Margaret |
clojurians | clojure | and without an arbitrary function I don’t know how to check two keys at once | 2017-12-07T17:08:39.000189 | Margaret |
clojurians | clojure | <@Margaret> Yeah, I explicitly need it to be under `:b` unfortunately, just due to a downstream consumer. | 2017-12-07T17:08:42.000397 | Jodie |
clojurians | clojure | a custom reify of the apropriate schema protocol just to generate the message / return value it wants? | 2017-12-07T17:09:10.000154 | Margaret |
clojurians | clojure | Hi ! I'm starting a bunch of futures and I'd like to block the main thread until all of them are finished. Is there a way to do that cleanly ? | 2017-12-07T17:09:44.000543 | Ezequiel |
clojurians | clojure | or something that checks :b explicitly, using the value under :a as a second input? | 2017-12-07T17:09:52.000295 | Margaret |
clojurians | clojure | <@Ezequiel> (doseq [f futures] @f) will do that | 2017-12-07T17:10:31.000189 | Margaret |
clojurians | clojure | (and return nil once all have returned) | 2017-12-07T17:10:48.000239 | Margaret |
clojurians | clojure | I started poking around the protocol, but I couldn't see how to do it unfortunately. Maybe I need to look at that more closely. | 2017-12-07T17:10:53.000225 | Jodie |
clojurians | clojure | I was hoping somebody might have figured it out. | 2017-12-07T17:11:03.000312 | Jodie |
clojurians | clojure | <@Jodie> what about something like `(let [to-check m] (s/check {:b (s/pred (fn [b] (= b (:a m))))} m))` | 2017-12-07T17:13:05.000256 | Margaret |
clojurians | clojure | the error message isn’t as nice, but it shows up under the b key | 2017-12-07T17:13:22.000525 | Margaret |
clojurians | clojure | I could hack it with a dynamic var or something :joy: Which is not a style I'm usually keen on. | 2017-12-07T17:14:32.000124 | Jodie |
clojurians | clojure | to have the choice to wait for task completion, or to fire-and-forget | 2017-12-07T17:33:44.000310 | Jena |
clojurians | clojure | to give you some context, i'm trying to solve this issue <https://github.com/vvvvalvalval/datomock/issues/2> | 2017-12-07T17:35:01.000248 | Jena |
clojurians | clojure | I suppose with a custom schema on the parent, the dynamic var becomes far more isolated. | 2017-12-07T17:37:31.000119 | Jodie |
clojurians | clojure | what's the best way to select a couple values from a sorted-map in the order that they're stored in the map? (i.e. `(unknown-fn (sorted-map :1 "1" :2 "2" :3 "3") [:2 :1]) ==> ["1" "2"])`) | 2017-12-07T17:53:33.000462 | Raul |
clojurians | clojure | <@Raul> as an aside, the reader in clj lets you create the keyword `:1` but it’s evil and the docs say it isn’t valid and some readers reject it | 2017-12-07T17:54:36.000097 | Margaret |
clojurians | clojure | you are allowed to use `1` as a key | 2017-12-07T17:54:48.000279 | Margaret |
clojurians | clojure | good to know. Those aren't my real keys or values, just something I could use as an example to help people see the ordering | 2017-12-07T17:55:23.000553 | Raul |
clojurians | clojure | <@Raul> wouldn’t select-keys do that? | 2017-12-07T17:55:27.000221 | Margaret |
clojurians | clojure | OK | 2017-12-07T17:55:30.000358 | Margaret |
clojurians | clojure | select-keys uses `ret {}` to put it's values into, so I don't think it keeps the order of a sorted map? | 2017-12-07T17:55:57.000011 | Raul |
clojurians | clojure | oh, right | 2017-12-07T17:56:06.000063 | Margaret |
clojurians | clojure | `(fn [m ks] (into (empty m) (select-keys m ks))` - I’ll leave the fancy name up to you | 2017-12-07T17:56:45.000168 | Margaret |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.