2015-10-15
| 00:00 | TEttinger | ,(map #(for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))]) (range (count (apply max-key count (vals rhg-data))))) |
| 00:00 | clojurebot | (([:a 1] [:b 2] [:c 4]) ([:a 1] [:b 3] [:c 5]) ([:a 1] [:b 2] [:c 6])) |
| 00:00 | TEttinger | phew, rhg135 |
| 00:00 | TEttinger | ,(map #(into {} (for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))])) (range (count (apply max-key count (vals rhg-data))))) |
| 00:00 | clojurebot | ({:a 1, :b 2, :c 4} {:a 1, :b 3, :c 5} {:a 1, :b 2, :c 6}) |
| 00:01 | TEttinger | I'm guessing you wanted all permutations or something |
| 00:01 | rhg135 | that's some gnarly code |
| 00:01 | TEttinger | now that I read the question |
| 00:01 | rhg135 | maybe I need to rethink my approach |
| 00:12 | Jayhost | Hey! Are you coffee or tea people here? |
| 00:21 | l1x | hey guys |
| 00:22 | l1x | is there an easy way to have only positive values from a hash function like murmur3? |
| 00:22 | l1x | https://gist.github.com/l1x/7c9cae8070c3e84a0f0e |
| 00:37 | TEttinger | l1x: sure |
| 00:37 | l1x | converting it to binary and shifting it? |
| 00:37 | TEttinger | ,(unsigned-bit-shift-right (hash -1) 1) |
| 00:37 | clojurebot | 825930356 |
| 00:37 | TEttinger | ,(hash -1) |
| 00:37 | clojurebot | 1651860712 |
| 00:37 | TEttinger | hm |
| 00:37 | TEttinger | that's odd |
| 00:38 | TEttinger | hash used to hash numbers as themselves, I thought... |
| 00:38 | TEttinger | ,(map hash (rang -10 10)) |
| 00:38 | clojurebot | #error {\n :cause "Unable to resolve symbol: rang in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: rang in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: rang in this co... |
| 00:38 | TEttinger | ,(map hash (range -10 10)) |
| 00:38 | clojurebot | (-1675778087 -714281095 -1517383352 -1703207563 522362154 ...) |
| 00:38 | TEttinger | ,(unsigned-bit-shift-right (hash -10) 1) |
| 00:38 | clojurebot | 9223372036016886764 |
| 00:39 | TEttinger | that does discard the least significant bit, overwriting it with the one more significant |
| 00:39 | TEttinger | so you're twice as likely to have hash collisions, maybe |
| 00:39 | l1x | that does not matter |
| 00:39 | TEttinger | if hash returns a 32-bit int, you're golden though |
| 00:40 | l1x | what is the hash defn? |
| 00:41 | TEttinger | to clojure.core! |
| 00:41 | TEttinger | https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L4937 |
| 00:42 | l1x | i see |
| 00:42 | TEttinger | it's calling something defined in the java source of the clojure lib |
| 00:42 | l1x | (murmur-int "a3a") |
| 00:42 | l1x | -161652959486184562448573335884646282847 |
| 00:43 | l1x | IllegalArgumentException bit operation not supported for: class java.math.BigInteger clojure.lang.Numbers.bitOpsCast (Numbers.java:1097) |
| 00:43 | TEttinger | ,(unsigned-bit-shift-right -161652959486184562448573335884646282847 1) |
| 00:43 | clojurebot | #error {\n :cause "bit operation not supported for: class clojure.lang.BigInt"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "bit operation not supported for: class clojure.lang.BigInt"\n :at [clojure.lang.Numbers bitOpsCast "Numbers.java" 1097]}]\n :trace\n [[clojure.lang.Numbers bitOpsCast "Numbers.java" 1097]\n [clojure.lang.Numbers unsignedShiftRight "Numbers.java" 408]\n... |
| 00:43 | TEttinger | oh |
| 00:43 | TEttinger | well that's going to throw a wrench in things, but! |
| 00:43 | l1x | :D |
| 00:45 | TEttinger | ,(,abs -161652959486184562448573335884646282847N) |
| 00:45 | clojurebot | #error {\n :cause "Unable to resolve symbol: abs in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: abs in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: abs in this conte... |
| 00:45 | TEttinger | ,(.abs -161652959486184562448573335884646282847N) |
| 00:45 | clojurebot | #error {\n :cause "No matching field found: abs for class clojure.lang.BigInt"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: abs for class clojure.lang.BigInt"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceM... |
| 00:46 | l1x | (.shiftRight (murmur-int "a3a") 1) |
| 00:46 | l1x | -80826479743092281224286667942323141424 |
| 00:47 | l1x | what is x >>> 1 in Java? |
| 00:48 | TEttinger | shiftRight won't work here, and BigInteger doesn't have a >>> equivalent |
| 00:48 | TEttinger | so |
| 00:48 | l1x | damn |
| 00:48 | TEttinger | shiftRight (or >> in Java) moves all the bits except for the sign bit to the right by the second arg |
| 00:48 | l1x | right |
| 00:49 | TEttinger | >>> is a logical or unsigned shift, and it will shift the sign bit over, replacing it with 0 |
| 00:49 | TEttinger | ,(.abs (biginteger -161652959486184562448573335884646282847N)) |
| 00:49 | clojurebot | 161652959486184562448573335884646282847 |
| 00:50 | TEttinger | so that's one way to ensure they're positive |
| 00:51 | TEttinger | ,(defn big-positive [n] (.abs (biginteger n))) |
| 00:51 | clojurebot | #'sandbox/big-positive |
| 00:51 | TEttinger | ,(big-positive -1) |
| 00:51 | clojurebot | 1 |
| 00:51 | l1x | well yes |
| 00:52 | l1x | but i need this to determine the location of something in a BitSet |
| 00:52 | TEttinger | ,(.xor (biginteger -161652959486184562448573335884646282847N) (biginteger -161652959486184562448573335884646282847N)) |
| 00:52 | clojurebot | 0 |
| 00:52 | TEttinger | hm |
| 00:52 | l1x | worst case i can check abs |
| 00:53 | TEttinger | ,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftLeft (biginteger -161652959486184562448573335884646282847N) 16)) |
| 00:53 | clojurebot | 10594100828800902576314882703235656096516513 |
| 00:53 | TEttinger | not sure if that actually works |
| 00:53 | TEttinger | ,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftRight (biginteger -161652959486184562448573335884646282847N) 1)) |
| 00:53 | clojurebot | 92151082097685838618080676853663321457 |
| 00:53 | TEttinger | the second should actually sorta do the trick |
| 00:54 | TEttinger | I'm not sure what you mean about the bitset |
| 00:54 | TEttinger | I'm familiar, somewhat with BitSet as a class |
| 00:54 | TEttinger | I don't think storing 92151082097685838618080676853663321457 bits will be possible |
| 00:57 | TEttinger | l1x: can you describe what you're trying to do with this from a more "broad goals" perspective? |
| 00:58 | l1x | i am trying to set the bit for a certain location in the BitSet |
| 00:58 | l1x | i see |
| 00:58 | l1x | i can use the 32 bit version in that case |
| 00:59 | TEttinger | yeah, I don't think BitSet takes a BigInteger for a location, heh |
| 00:59 | l1x | good point! |
| 01:00 | l1x | BigInteger() has an implementation where you can pass in the output of this -> Bytes/toArray |
| 01:01 | l1x | i am wondering what is the same for Integer |
| 01:01 | TEttinger | err |
| 01:01 | TEttinger | l1x do you want to turns a byte[4] into a single 32-bit int? |
| 01:02 | l1x | yes |
| 01:02 | l1x | (BigInteger. (Bytes/toArray b)) works |
| 01:04 | l1x | but not sure what is the same for integers |
| 01:05 | l1x | https://gist.github.com/pingles/1235344 |
| 01:05 | l1x | maybe this |
| 01:07 | TEttinger | ,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 0 255 255])) 0) |
| 01:07 | clojurebot | 65535 |
| 01:08 | TEttinger | what is Bytes/toArray ? is it a standard Java class, Bytes? |
| 01:10 | TEttinger | ,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 255 255])) 0) ; I suspect it needs a full 4 bytes |
| 01:10 | clojurebot | #error {\n :cause nil\n :via\n [{:type java.lang.IndexOutOfBoundsException\n :message nil\n :at [java.nio.Buffer checkIndex "Buffer.java" 538]}]\n :trace\n [[java.nio.Buffer checkIndex "Buffer.java" 538]\n [java.nio.HeapByteBuffer getInt "HeapByteBuffer.java" 359]\n [sandbox$eval49 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval49 invoke "NO_SOURCE_FILE" -1]\n [clojure.lang.Compiler eval ... |
| 01:52 | keep_learning | Hello everyone. |
| 01:52 | keep_learning | Any idea how to resolve this error http://lpaste.net/143057 |
| 02:08 | Kneiva | keep_learning: https://github.com/dakrone/clojure-opennlp/issues/2 |
| 02:08 | keep_learning | Kneiva: Thank you very much. |
| 02:10 | Kneiva | keep_learning: np |
| 03:19 | vrdhn | #nikola |
| 03:32 | Seylerius | Okay, so, I was following the readme (https://github.com/josephwilk/image-resizer) for image-resizer, and the section about lazy helpers uses "file" a lot, as does the section on making BufferedImage useful. I tried writing my cropped image out, realized I had to require file from clojure.java.io, and now it's complaining about "NullPointerException javax.imageio.ImageIO.write (ImageIO.java:1538)". What's the problem here? |
| 03:44 | Seylerius | Fixed it. It just didn't want bare filenames for paths ("test.jpg"), and preferred slightly more proper paths ("./test.jpg"). |
| 04:44 | Seylerius | Okay, I've got a png barcode, and I want to add an annotation to the png, below the barcode, with the barcode's content and the price of the item. How would y'all go about such a thing? |
| 05:14 | skoude | /join #saltstack |
| 06:01 | noncom | Seylerius: do you have to recognize what the barcode says or do you simply need to put some image next to it? |
| 06:11 | WickedShell | I've got to be an idiot, I'm attempting to set a byte array in a java class member via interop, and for some reason it keeps getting the passed byte array's toString. The line of clojure is (set! (.param_id paramSet) (.getBytes s)) the java field is specified as: public byte param_id[] = new byte[16]; |
| 06:11 | WickedShell | This has to be easy but apparently I can't figure it out |
| 06:24 | WickedShell | The anwser apparently is a weird mangled expression of java interop code, oh well I guess it works. For posterity the best I found was this: (System/arraycopy (.getBytes s) 0 (.param_id paramSet) 0 (count s)) |
| 07:49 | ashwink005 | does anyone know how to get data out of a Class HttpInput object? |
| 07:50 | ashwink005 | slurp is giving an empty string |
| 07:51 | Kneiva | ashwink005: org.eclipse.jetty.server.HttpInput ? |
| 07:51 | ashwink005 | Kneiva, yes |
| 07:51 | puredanger | WickedShell: I'd be careful about count there depending what s is |
| 07:51 | ashwink005 | I'm getting that object in my request body. I needed to parse its contents |
| 07:53 | Kneiva | ashwink005: Well, that is a InputStream so you'll need some kind of StreamReader. |
| 07:54 | ashwink005 | Kneiva, yeah saw that. How do you reckon I read it? the java way? |
| 07:55 | Kneiva | Oh, wait... let me check something. |
| 07:59 | Kneiva | ashwink005: Hmm, I have some vague memory about ring or compojure or something closing the stream before it is handed out to your code. But I couldn't find anything related in the project where I run into that. |
| 08:04 | necronian | Can anyone explain to me what happens when I extend a java type? I extended java.lang.Number. But I don't understand why I can't call (.method 1) and instead need to call (method 1)? |
| 08:09 | noncom | necronian: i'm not sure, but you can always look at clojure source. my explanation would be that a multimethod or a protocol dispatch is created for that type |
| 08:23 | necronian | noncom: Yea... I just took a quick look. The amount I understand is only enough that figuring anything out will be a major project. For the time being I've decided the answer is magic and put a big fat ;;TODO: in there. |
| 08:23 | noncom | necronian: that's ok. you mean extend java type like with (proxy) ? |
| 08:28 | necronian | noncom: No I never knew about proxy before now. I created a Unit record that implements a UnitConversion protocol. Then I decided it would be nice for numbers to be dimensionless units for math purposes so I have (extend java.lang.Number UnitConversion {etc}) |
| 08:28 | noncom | ah i see |
| 08:31 | noncom | necronian: well, looking at it - it generates a java interface |
| 08:31 | noncom | necronian: really, i cannot say much more too, without some thorough reading into the code |
| 08:32 | noncom | but some folks here could tell. probably they're just not here |
| 08:33 | necronian | noncom: Yea, thank you. It isn't a huge deal, it just makes my code less pretty when I use it in another namespace. |
| 08:33 | noncom | necronian: you mean you then need to qualify it like (namespace/method obj ...) ? |
| 08:34 | noncom | if this is the problem, maybe :refer could help |
| 08:34 | noncom | interesting topic all in all. i'd like to hear someone on this |
| 08:35 | noncom | never used protocols, actually :) |
| 08:36 | WickedShell | puredanger, it's a string, is that still unsafe? |
| 08:37 | necronian | noncom: Exactly. I could use refer but I would prefer to prefix it. I just thought it was strange that I get java methods when I create my own type but not when I extend a java type. |
| 08:40 | noncom | necronian: from what i see in the code, it looks like that these are simple clojure functions, not any kind of java method generation... :/ that's why... surely there is a reason for that, but idk :) |
| 08:42 | ashwink005 | I have an inputstream object and it has already been read |
| 08:42 | ashwink005 | can I set its read pointer back to the beginning? |
| 08:44 | noncom | ashwink005: (.reset input-stream) ? |
| 08:45 | noncom | ashwink005: but first you have to call (.mark input-stream) |
| 08:45 | noncom | to put the mark where to return to |
| 08:46 | ashwink005 | noncom, why do I need to put a mark. |
| 08:46 | noncom | does not work on all streams though |
| 08:46 | ashwink005 | the stream has been read completely. Slurp returns an empty string. |
| 08:46 | noncom | ashwink005: idk. propbably because various implementations must somehow play together... |
| 08:46 | noncom | no, i don't think it is possible |
| 08:46 | noncom | what is the underlying object? |
| 08:47 | ashwink005 | HttpInput |
| 08:47 | noncom | ashwink005: http://stackoverflow.com/questions/9501237/read-stream-twice |
| 08:47 | noncom | ashwink005: http://stackoverflow.com/questions/13196742/java-inputstream-mark-reset |
| 08:48 | noncom | ashwink005: this can also be useful: http://stackoverflow.com/questions/6716777/inputstream-will-not-reset-to-beginning |
| 08:49 | ashwink005 | noncom, turns out HttpInput doesn't support reset/mark. |
| 08:50 | noncom | ashwink005: then try the first link, where they copy it into a bytearray |
| 08:50 | ashwink005 | compojure api is reading my request's body. I don't have a control over that. I just have an already read HttpInput |
| 08:51 | ashwink005 | is there a way I could reuse that? or should I hack compojure-api? |
| 08:59 | Kneiva | ashwink005: Have you seen this? http://ujihisa.blogspot.fi/2011/12/read-raw-post-request-body-in-compojure.html |
| 09:00 | puredanger | WickedShell: yeah, the number of characters in a string != number of bytes |
| 09:02 | ashwink005 | Kneiva, I'm using compojure-api. Its a framework built on top of compojure |
| 09:02 | ashwink005 | it does request validation and web-api doc generation |
| 09:04 | Kneiva | ok, I'm not familiar with that |
| 09:04 | Deraen | ashwink005: Compojure-api just uses ring-middleware-format |
| 09:06 | ashwink005 | Deraen, yeah I guess |
| 09:08 | Deraen | ashwink005: Also, might be a bug because I think that r-m-f is trying to recreate new inputstream if it reads the body |
| 09:09 | Deraen | ashwink005: https://github.com/ngrunwald/ring-middleware-format/blob/master/src/ring/middleware/format_params.clj#L104-L118 perhaps it should create new inputs stream on line 118 |
| 09:12 | ashwink005 | Deraen, hmm.. so what should I do. No way I could reuse the HTTPInput? |
| 09:12 | Deraen | ashwink005: HTTPInput is an InputStream |
| 09:12 | ashwink005 | Deraen, yes |
| 09:17 | WickedShell | puredanger: I thought it is given that the string was build by reading a cstring and I know that the encoding is ascii (or at least started in ascii). I'm a bit taken aback at how frustrating I'm finding it to be using libraries that need cstrings in clojure/java |
| 09:22 | WickedShell | puredanger, I guess you're right in that to be truly safe/future proof I need to use getBytes where I provide the expected encoding, then cache the result, calculate the size of the resultant byte array, then do the copy while being careful not to exceed destination length. (Apparently I dont mind doing this at all in C normally but I resent the need to do it in clojure/java for some reason). But you're right, my stuff is only worki |
| 09:22 | WickedShell | ng there as I've controlled the inputs pretty carefully at the moment |
| 09:24 | Deraen | ashwink005: R-m-f doesn't have support for using InputStream mark/reset and I don't that HttpInput does support mark/reset either (it doesn't implement the necessary methods) |
| 09:26 | ashwink005 | Deraen, yeah I saw that. I tried wrapping it in a BufferedInputStream but it keeps saying invalid mark |
| 09:27 | justin_smith | for non streaming / websocket purproses I have had good luck capturing the HTTPInput via slurp into a string, and recreating via a new InputStream created from the String. This is great for turning a request that exposes a bug into a unit test |
| 09:27 | justin_smith | make that non-streaming and non-websocket purposes |
| 09:27 | Deraen | ashwink005: If you don't need r-m-f middleware you can mostly disable it by setting compojure-api :format :formats to empty vector |
| 09:28 | ashwink005 | Deraen, hmm.. will try that. |
| 09:30 | ashwink005 | justin_smith, I actually don't have any control over the HttpInput object. It is read by the compojure-api and is then rendered useless. |
| 09:31 | justin_smith | ashwink005: you can hijack it with another middleware before compojure-api sees it |
| 09:31 | justin_smith | I have done weirder things |
| 09:31 | justin_smith | eg, grab it clone it, replace it with the clone, do what you want with the original |
| 09:31 | justin_smith | the clone being a new inputstream so the other apis work, of course |
| 09:32 | justin_smith | every middleware problem can be solved with yet more middleware :P |
| 09:53 | Seylerius | Hrm. How would one best turn a png barcode into a png with the barcode above the barcode ID number and the product's price? |
| 09:53 | xemdetia | I was stuck on this at like some weird hour this morning but was there ever a fix for nrepl opening an ipv6 socket instead of an ipv4 socket on java 8 without just going back to java 7 |
| 09:55 | justin_smith | what's wrong with ipv6? |
| 09:55 | xemdetia | nothing really, I just can't get other stuff to connect to it |
| 09:55 | justin_smith | ahh, that suskcs |
| 09:55 | xemdetia | well monroe was what Iw as trying to use |
| 09:55 | justin_smith | oh, so no ipv6 for emacs? that's surprising actually |
| 09:56 | xemdetia | I did compile it myself because I wanted svg support |
| 09:56 | xemdetia | so I could have just did something wrong |
| 09:56 | xemdetia | oh well, I'll have to play with it more now that coffee has re-entered my life |
| 09:57 | justin_smith | xemdetia: my guess is if the right dev headers for compiling ipv6 support had been present, emacs would have built support for ipv6 - not sure of that though |
| 09:58 | justin_smith | xemdetia: in emacs, "make-network-process" requires an explicit arg to use ipv6 - it might be as simple as hacking the elisp for monroe to try the ipv6 option |
| 09:59 | xemdetia | interesting |
| 09:59 | xemdetia | I will have to play with that leter |
| 10:01 | justin_smith | xemdetia: aha! monroe uses a higher level function, open-network-stream maybe this is relevant? https://lists.gnu.org/archive/html/emacs-devel/2004-10/msg01378.html |
| 10:03 | justin_smith | also, you really should only be connecting to nrepl from localhost, so can't you use /etc/hosts to make sure localhost is ipv4? |
| 10:04 | xemdetia | It is sadly |
| 10:04 | xemdetia | my /etc/hosts does resolve appropriately with 127.0.0.1, but the 127.0.0.1 appears on the tcp6 stack and not on the tcp stack |
| 10:04 | xemdetia | which is funky in general |
| 10:04 | justin_smith | that's super weird |
| 10:05 | xemdetia | there was an envvar I didn't get to try I found before I went to bed last night where there was a java 8 property to bias the ipv4 stack |
| 10:05 | xemdetia | It just looks like I have to do a little wrenching over lunch to figure it out |
| 10:11 | jonathanj | is there a shorter spelling of (every? true? ...)? |
| 10:12 | justin_smith | (= (set c) #{true}) |
| 10:12 | jonathanj | that's not terribly obvious though |
| 10:13 | jonathanj | i guess worst case: (def all? (partial every? true?)) |
| 10:13 | justin_smith | jonathanj: wait... |
| 10:13 | justin_smith | ,(every true? [true true true]) |
| 10:13 | clojurebot | #error {\n :cause "Unable to resolve symbol: every in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: every in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: every in this... |
| 10:13 | justin_smith | ,(every? true? [true true true]) |
| 10:13 | clojurebot | true |
| 10:14 | justin_smith | is that really the function you want? |
| 10:14 | justin_smith | ,(every? true? [true true true :truthy]) |
| 10:14 | clojurebot | false |
| 10:14 | justin_smith | just asking because it's extremely limited, not that it's never useful |
| 10:14 | luma | ,(every? identity [true true :truthy]) |
| 10:14 | clojurebot | true |
| 10:14 | jonathanj | the code in question is something like (every? true? (map verify-x xs)) |
| 10:15 | justin_smith | OK |
| 10:15 | jonathanj | where verify-x returns a boolean |
| 10:15 | jonathanj | so i think it is what i want |
| 10:15 | justin_smith | cool |
| 10:15 | jonathanj | i guess (apply and (map verify-x xs)) would also work? |
| 10:15 | luma | then why not do (every? verify-x xs) |
| 10:15 | jonathanj | oh wait, and is a macro |
| 10:15 | justin_smith | jonathanj: no, because true? is only true for true itself |
| 10:16 | justin_smith | not for any other value |
| 10:16 | jonathanj | luma: good idea! |
| 10:16 | justin_smith | luma: that's the ticket, yeah |
| 10:18 | jonathanj | thanks |
| 10:34 | justin_smith | (every? #(= Double/NaN %) nil) |
| 10:34 | justin_smith | ,(every? #(= Double/NaN %) nil) |
| 10:35 | clojurebot | true |
| 10:42 | jonathanj | is there a library for constructing URIs in idiomatic Clojure? |
| 10:42 | jonathanj | (and deconstructing them) |
| 10:43 | bordeltabernacle | (+ 2 2) |
| 10:43 | clojurebot | 4 |
| 10:46 | puredanger | jonathanj: |
| 10:46 | puredanger | jonathanj: https://github.com/cemerick/url if you're specifically working with urls |
| 10:47 | jonathanj | hrm |
| 10:47 | jonathanj | if something returns (url ...) and you want to add to the path, what are your options? |
| 10:48 | jonathanj | there is an example there (url base child) but that's not generally very useful if you have a url not a string |
| 10:48 | jonathanj | (url (str returned-url) child) seems a bit gratuitous |
| 11:51 | timvisher | well i'm feeling quite senile right now. isn't here a boolean predicate? |
| 11:54 | justin_smith | ,(boolean? true) |
| 11:54 | clojurebot | #error {\n :cause "Unable to resolve symbol: boolean? in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: boolean? in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: boolean... |
| 11:54 | justin_smith | ,(contains? #{true false} true) |
| 11:54 | clojurebot | true |
| 11:54 | justin_smith | timvisher: I was equally senile |
| 11:56 | timvisher | ,(map (partial instance? Boolean) [true false nil 0 1 "true" "false"]) |
| 11:56 | clojurebot | (true true false false false ...) |
| 11:56 | timvisher | justin_smith: any danger there? |
| 11:56 | timvisher | other than it not being portable |
| 11:56 | justin_smith | but you can have things that are instances of boolean that are not true or false (it's degenerate, and not what you want, but possible) |
| 11:56 | justin_smith | ,(Boolean. "false") |
| 11:56 | clojurebot | false |
| 11:57 | justin_smith | ,(= false (Boolean. "false")) |
| 11:57 | clojurebot | true |
| 11:57 | timvisher | justin_smith: oh that's interesting. how hard would you have to work for that to happen? |
| 11:57 | justin_smith | timvisher: I'm trying to remember the trick... |
| 11:57 | timvisher | yeah, but once you reify the Boolean it's for reelz a boolean right? |
| 11:57 | justin_smith | ,(if (Boolean. "false") :huh? :OK) |
| 11:57 | clojurebot | :huh? |
| 11:57 | timvisher | ,(Boolean. "ohai") |
| 11:57 | clojurebot | false |
| 11:57 | timvisher | heh. that's fun. |
| 11:57 | justin_smith | timvisher: see the if above |
| 11:58 | justin_smith | so that returns true for "is it a boolean", but isn't anything useful, and isn't anything you want |
| 11:58 | justin_smith | timvisher: that might be enough of a corner case for the instance? Boolean to be OK, but I like testing against true and false explicitly anyway |
| 11:59 | timvisher | justin_smith: yeah. not a bad point :) |
| 13:20 | pilne | am i missing a good reason for get to take the map and then the key? |
| 13:21 | danlarkin | pilne: composition |
| 13:21 | pilne | i guess it would be worded "take this data and find this value" and not "find this value in this data" |
| 13:29 | mavbozo | pilne, consistency: function that works on collection takes a collection as its first argument |
| 13:29 | mavbozo | ,(assoc {:a 1 :b 2} :c 3) |
| 13:30 | clojurebot | {:a 1, :b 2, :c 3} |
| 13:30 | mavbozo | ,(assoc [1 2 76] 2 3) |
| 13:30 | clojurebot | [1 2 3] |
| 13:32 | pilne | i am sure that i will grow to love the consistency (: it's just a learning process, is there a "clojure user's guide to java" that I could use to brush up without having to get balls-deep in java again? |
| 13:38 | mavbozo | pilne, well, considering you already have previous experience with java, this tutorial should be a nice quickstart => http://clojure-doc.org/articles/language/interop.html |
| 13:39 | pilne | awesome (: thanks |
| 13:40 | spacepluk | any clojure-clr users around? |
| 13:48 | timvisher | justin_smith: so it just you here now? |
| 13:49 | timvisher | slack has eaten t3h world? :'( |
| 13:49 | jln_ | \q |
| 13:49 | timvisher | heh |
| 13:49 | timvisher | better than when i typed my password by mistake |
| 13:49 | timvisher | msg NickServ is so easy to mistype |
| 13:54 | mavbozo | what? justin_smith has moved to slack? |
| 13:54 | justin_smith | I'm here, but also busy |
| 13:57 | justin_smith | mavbozo: also regarding "function that works on collection takes a collection as its first argument" - associative is the first argument, sequential the last |
| 13:57 | justin_smith | kind of, most of the time :P |
| 13:59 | timvisher | justin_smith: :'( 🍻 |
| 14:36 | timvisher | anyone familiar with a util function that prints a value in the context of a threading macro? |
| 14:37 | timvisher | ,(-> 1 inc #(do (println %) %) inc) |
| 14:37 | clojurebot | #error {\n :cause "clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.ClassCastException\n ... |
| 14:37 | luma | ,(-> 1 inc (doto println) inc) |
| 14:37 | Wojciech_K | ,(->> 1 inc #(do (println %) %) inc) |
| 14:37 | clojurebot | 2\n3 |
| 14:37 | timvisher | ,(-> 1 inc (#(do (println %) %)) inc) |
| 14:37 | clojurebot | #error {\n :cause "sandbox$eval76$fn__77 cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "sandbox$eval76$fn__77 cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers inc "Numbers.java" 112]}]\n :trace\n [[clojure.lang.Numbers inc "Numbers.java" 112]\n [sandbox$eval76 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval76 invoke "NO_SOURCE_FI... |
| 14:37 | clojurebot | 2\n3 |
| 14:38 | timvisher | luma: nice. |
| 14:38 | justin_smith | ,(-> 1 inc (doto println) inc) |
| 14:39 | clojurebot | 2\n3 |
| 14:39 | justin_smith | timvisher: ^ |
| 14:39 | timvisher | yeah that's nice |
| 14:39 | TEttinger | that was luma's , justin_smith |
| 14:39 | timvisher | i don't think i've used doto before |
| 14:39 | justin_smith | heh, oops |
| 14:39 | timvisher | hey, how do i implement fizzbuzz in clojure? |
| 14:43 | timvisher | akkad is surrounded by a dark forest but notices what may have been an animal trail years ago winding off into the foliage |
| 14:46 | justin_smith | akkad: as in s3-wagon-private? |
| 14:46 | akkad | justin_smith: yes |
| 14:47 | justin_smith | yeah we use that |
| 14:47 | akkad | ok so it's recommended. cool. |
| 14:47 | akkad | using makefile to precache in s3 |
| 14:47 | justin_smith | the chef script uses s3cmd to grab the latest version |
| 14:47 | justin_smith | when building the server (or just updating a server to use a new jar) |
| 14:47 | TEttinger | (map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" true %) (range 101)) |
| 15:22 | zexperiment | TEttinger: new favorite fizzbuzz |
| 15:23 | timvisher | heh. there are always those who cannot resist the siren call |
| 15:34 | justin_smith | ,(map #(condp (comp zero? (comp (partial apply mod) reverse list)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101)) |
| 15:34 | clojurebot | ("FizzBuzz" 1 2 "Fizz" 4 ...) |
| 15:36 | oddcully | points, there are none |
| 15:36 | justin_smith | well, very few at least |
| 15:37 | justin_smith | if we had flip I could have done (flip mod) instead of (comp (partial apply mod) reverse list) |
| 15:37 | justin_smith | and flip mod almost sounds like flip mode, you know, busta rymes |
| 15:38 | oddcully | ah there they are |
| 15:38 | pilne | one could write their own flip function though if something like that ends up being needed frequently? |
| 15:38 | oddcully | you hid your points well |
| 15:38 | justin_smith | pilne: indeed, but it would not have made my example more succinct |
| 15:38 | pilne | k |
| 15:39 | justin_smith | or would it have? |
| 15:40 | pilne | not really |
| 15:40 | justin_smith | ,(defn flip [f] #(apply f (reverse %&))) |
| 15:40 | clojurebot | #'sandbox/flip |
| 15:40 | justin_smith | ,(map #(condp (comp zero? (flip mod)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101)) |
| 15:40 | clojurebot | ("FizzBuzz" 1 2 "Fizz" 4 ...) |
| 15:47 | timvisher | how would you go about def a var instead of printing? |
| 15:47 | timvisher | assuming either -> or ->>? |
| 15:47 | timvisher | ->> is easy (def var) would do it |
| 15:47 | justin_smith | you can use ->> inside -> |
| 15:47 | timvisher | justin_smith: ah. interesting. |
| 15:48 | justin_smith | ,(-> * #(%) (->> (def a))) |
| 15:48 | clojurebot | #'sandbox/a |
| 15:48 | justin_smith | ,a |
| 15:48 | clojurebot | #object[sandbox$_STAR___26 0x7570782d "sandbox$_STAR___26@7570782d"] |
| 15:48 | timvisher | ,(-> 1 inc (->> (def foo)) inc) |
| 15:48 | clojurebot | #error {\n :cause "clojure.lang.Var cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.Var cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers inc "Numbers.java" 112]}]\n :trace\n [[clojure.lang.Numbers inc "Numbers.java" 112]\n [sandbox$eval72 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval72 invoke "NO_SOURCE_FILE" -1]\n ... |
| 15:48 | justin_smith | well, you need doto still if you want to inc again after |
| 15:49 | timvisher | right. the idea here is mainly that you can, at any point in the thread, capture the value |
| 15:49 | justin_smith | ,(-> * (#(%)) inc (doto (->> (def foo))) inc) |
| 15:49 | clojurebot | 3 |
| 15:49 | justin_smith | ,foo |
| 15:49 | clojurebot | 2 |
| 15:49 | justin_smith | worked! |
| 15:50 | justin_smith | and it also looks super weird :P |
| 15:51 | justin_smith | there should be a doto> |
| 15:51 | justin_smith | which would be to doto as ->> is to -> |
| 15:53 | justin_smith | ,(-> * (#(%)) inc (as-> x (do (def foo x) x)) inc) |
| 15:53 | clojurebot | 3 |
| 15:56 | amalloy | justin_smith: or without the doto, if you jsut deref the var in the -> chain |
| 15:56 | amalloy | ,(-> * (#(%)) inc (->> (def foo) deref) inc) |
| 15:56 | clojurebot | 3 |
| 15:58 | justin_smith | ahh, that's a nice trick |