clojure

Decompress zlib stream in Clojure

孤街醉人 提交于 2021-01-27 05:33:11
问题 I have a binary file with contents created by zlib.compress on Python, is there an easy way to open and decompress it in Clojure? import zlib import json with open('data.json.zlib', 'wb') as f: f.write(zlib.compress(json.dumps(data).encode('utf-8'))) Basicallly it isn't a gzip file, it is just bytes representing deflated data. I could only find these references but not quite what I'm looking for (I think first two are most relevant): deflateclj_hatemogi_clojure/deflate.clj funcool/buddy-core

ClojureScript split one namespace into multiple files

坚强是说给别人听的谎言 提交于 2021-01-27 04:43:51
问题 I've read this thread, but it seems like there are no load and load-file in ClojureScript. Is it possible to separate a single namespace over multiple files? The reason I want to do that is because I'm using Om and I want to separate components into different files. I can do it using separate namespaces, but then I will have to write the same requires in the beginning of each file and also the only way to call those components in the main file is like that: (:require [some-project.sidebar :as

Clojure getting highest value from zipmap

孤街浪徒 提交于 2021-01-24 07:34:51
问题 So I've got my proposed zip map here and it works perfectly. As you can see I've got the data loading. That is what it looks like in the repl which is perfect. And right here is the map :Year 2020, :Day 27, :January 59, :February 38 :Year 2020, :Day 28, :January 41, :February 57 :Year 2020, :Day 29, :January 56, :February 51 :Year 2020, :Day 31, :January 94, :February -999 :Year 2020, :Day 30, :January 76, :February -999 (map [:Day :Month Bear in mind this is just a snippet of the code I've

Clojure getting highest value from zipmap

天涯浪子 提交于 2021-01-24 07:34:29
问题 So I've got my proposed zip map here and it works perfectly. As you can see I've got the data loading. That is what it looks like in the repl which is perfect. And right here is the map :Year 2020, :Day 27, :January 59, :February 38 :Year 2020, :Day 28, :January 41, :February 57 :Year 2020, :Day 29, :January 56, :February 51 :Year 2020, :Day 31, :January 94, :February -999 :Year 2020, :Day 30, :January 76, :February -999 (map [:Day :Month Bear in mind this is just a snippet of the code I've

What's the correct way of providing a default value for *print-length* in profiles.clj?

余生颓废 提交于 2021-01-22 13:37:22
问题 For those that do not know what *print-length* stands for: If you (set! *print-length* 200) , and you evaluate (range) in a REPL, which normally causes an infinite list of numbers to get printed, only the first 200 numbers will get printed. I'm trying to set this as a default for all my REPLs in profiles.clj . Right now I got this, but it doesn't work: {:user {:plugins [[lein-swank "1.4.4"] [lein-catnip "0.5.0"]] :repl-options {*print-length* 200}} :dev {:dependencies [[clj-ns-browser "1.2.0"

How to get all the params of a POST request with Compojure

这一生的挚爱 提交于 2021-01-22 06:59:37
问题 According to the Compojure documentation on routes, I can easily get individual parameters like this: (POST "/my-app" [param1 param2] (str "<h1>Hello " param1 " and " param2 "</h1>")) How do I get all parameters, not just individual parameters? 回答1: compojure handlers receive the entire request map as their argument, so handler has also an access to all of the parameters. For example, to see entire request: (POST "/" request (str request)) or, to extract all form parameters: (POST "/" request

How to download a file and unzip it from memory in clojure?

感情迁移 提交于 2021-01-21 03:58:02
问题 I'm making a GET request using clj-http and the response is a zip file. The contents of this zip is always one CSV file. I want to save the CSV file to disk, but I can't figure out how. If I have the file on disk, (fs/unzip filename destination) from the Raynes/fs library works great, but I can't figure out how I can coerce the response from clj-http into something this can read. If possible, I'd like to unzip the file directly without The closest I've gotten (if this is even close) gets me

How to download a file and unzip it from memory in clojure?

烂漫一生 提交于 2021-01-21 03:57:30
问题 I'm making a GET request using clj-http and the response is a zip file. The contents of this zip is always one CSV file. I want to save the CSV file to disk, but I can't figure out how. If I have the file on disk, (fs/unzip filename destination) from the Raynes/fs library works great, but I can't figure out how I can coerce the response from clj-http into something this can read. If possible, I'd like to unzip the file directly without The closest I've gotten (if this is even close) gets me

Why are multi-methods not working as functions for Reagent/Re-frame?

旧时模样 提交于 2021-01-20 23:41:08
问题 In a small app I'm building that uses Reagent and Re-frame I'm using multi-methods to dispatch which page should be shown based on a value in the app state: (defmulti pages :name) (defn main-panel [] (let [current-route (re-frame/subscribe [:current-route])] (fn [] ;... (pages @current-route)))) and then I have methods such as: (defmethod layout/pages :register [_] [register-page]) where the register-page function would generate the actual view: (defn register-page [] (let [registration-form

How can one get a java.time DateTime using clojure.java-time from #inst Date literal?

自古美人都是妖i 提交于 2021-01-04 14:00:47
问题 Using clj-time it is possible to parse an #inst Date literal like so: (require '[clj-time.coerce :as c]) (c/from-date #inst "2012-12-12") ;; => #object[org.joda.time.DateTime 0x4a251269 "2012-12-12T00:00:00.000Z"] How would this be done using the new java.time wrapper clojure.java-time? 回答1: PLEASE NOTE: Joda Time and the clj-time library which wraps it are both deprecated. You should use java.time via Java interop for most tasks. There are also some helper functions here you may find useful.