Back
mod (clj)
(source)function
(mod num div)
Modulus of num and div. Truncates toward negative infinity.
Examples
nextjournal/clerk
(ns nextjournal.clerk.atom
"Demo of Clerk's two-way bindings."
{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(:require [clojure.core :as core]
[nextjournal.clerk :as clerk]))
;; changing my-state on the JVM and running clerk/show! will update the slider
;; and counter accordingly:
(comment
(do
(swap! my-state update :counter #(mod (+ % 33) 100))
(clerk/recompute!)))
PrecursorApp/precursor
(ns pc.http.routes.api
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clojure.core.memoize :as memo]
[clojure.string :as str]
[clojure.tools.reader.edn :as edn]
[crypto.equality :as crypto]
[defpage.core :as defpage :refer (defpage)]
[pc.auth :as auth]
[pc.crm :as crm]
[pc.datomic :as pcd]
[pc.early-access]
[pc.http.doc :as doc-http]
[pc.http.team :as team-http]
[pc.http.handlers.custom-domain :as custom-domain]
[pc.models.chat-bot :as chat-bot-model]
[pc.models.doc :as doc-model]
[pc.models.flag :as flag-model]
[pc.models.team :as team-model]
[pc.profile :as profile]
[ring.middleware.anti-forgery :as csrf]
[slingshot.slingshot :refer (try+ throw+)]))
(defpage new [:post "/api/v1/document/new"] [req]
(let [params (some-> req :body slurp edn/read-string)
read-only? (:read-only params)
doc-name (:document/name params)]
(if-not (:subdomain req)
(let [cust-uuid (get-in req [:auth :cust :cust/uuid])
intro-layers? (:intro-layers? params)
doc (doc-model/create-public-doc!
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when cust-uuid {:document/creator cust-uuid})
(when read-only? {:document/privacy :document.privacy/read-only})
(when doc-name {:document/name doc-name})))]
(when intro-layers?
(doc-http/add-intro-layers doc))
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
(if (and (:team req)
(auth/logged-in? req)
(auth/has-team-permission? (pcd/default-db) (:team req) (:auth req) :admin))
(let [doc (doc-model/create-team-doc!
(:team req)
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when-let [cust-uuid (get-in req [:cust :cust/uuid])]
{:document/creator cust-uuid})
(when read-only?
{:document/privacy :document.privacy/read-only})
(when doc-name
{:document/name doc-name})))]
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
{:status 400 :body (pr-str {:error :unauthorized-to-team
:redirect-url (str (url/map->URL {:host (profile/hostname)
:protocol (if (profile/force-ssl?)
"https"
(name (:scheme req)))
:port (if (profile/force-ssl?)
(profile/https-port)
(profile/http-port))
:path "/new"
:query (:query-string req)}))
:msg "You're unauthorized to make documents in this subdomain. Please request access."})}))))
(seq (team-model/find-by-subdomain (pcd/default-db) subdomain))
{:status 400 :body (pr-str {:error :subdomain-exists
:msg "Sorry, that subdomain is taken. Please try another."})}
:else
(try+
(let [team (team-http/setup-new-team subdomain cust coupon-code)]
{:status 200 :body (pr-str {:team (team-model/read-api team)})})
(catch [:error :subdomain-exists] e
{:status 400 :body (pr-str {:error :subdomain-exists
:msg "Sorry, that subdomain is taken. Please try another."})})))))
(defpage create-solo-trial [:post "/api/v1/create-solo-trial"] [req]
(if-let [cust (get-in req [:auth :cust])]
(do
(flag-model/add-flag cust :flags/private-docs)
{:status 200 :body (pr-str {:msg "Thanks!" :solo-plan-created? true})})
{:status 401 :body (pr-str {:error :not-logged-in
:msg "Please log in to request early access."})}))
hraberg/deuce
(ns deuce.emacs.fileio
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.string :as s]
[clojure.java.io :as io]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.eval :as eval]
[deuce.emacs.editfns :as editfns])
(:import [java.nio.file Files LinkOption
NoSuchFileException]
[deuce.emacs.data Buffer BufferText])
(:refer-clojure :exclude []))
(defun set-visited-file-modtime (&optional time-list)
"Update buffer's recorded modification time from the visited file's time.
Useful if the buffer was not read from the file normally
or if the file itself has been changed for some known benign reason.
An argument specifies the modification time value to use
(instead of that of the visited file), in the form of a list
(HIGH . LOW) or (HIGH LOW)."
)
(defun set-default-file-modes (mode)
"Set the file permission bits for newly created files.
The argument MODE should be an integer; only the low 9 bits are used.
This setting is inherited by subprocesses."
)
Optional fourth argument APPEND if non-nil means
append to existing file contents (if any). If it is an integer,
seek to that offset in the file before writing.
Optional fifth argument VISIT, if t or a string, means
set the last-save-file-modtime of buffer to this file's modtime
and mark buffer not modified.
If VISIT is a string, it is a second file name;
the output goes to FILENAME, but the buffer is marked as visiting VISIT.
VISIT is also the file name to lock and unlock for clash detection.
If VISIT is neither t nor nil nor a string,
that means do not display the \"Wrote file\" message.
The optional sixth arg LOCKNAME, if non-nil, specifies the name to
use for locking and unlocking, overriding FILENAME and VISIT.
The optional seventh arg MUSTBENEW, if non-nil, insists on a check
for an existing file with the same name. If MUSTBENEW is `excl',
that means to get an error if the file already exists; never overwrite.
If MUSTBENEW is neither nil nor `excl', that means ask for
confirmation before overwriting, but do go ahead and overwrite the file
if the user confirms.
(defun default-file-modes ()
"Return the default file protection for created files.
The value is an integer."
)
(defun clear-visited-file-modtime ()
"Clear out records of last mod time of visited file.
Next attempt to save will certainly not complain of a discrepancy."
)
(defun visited-file-modtime ()
"Return the current buffer's recorded visited file modification time.
The value is a list of the form (HIGH LOW), like the time values that
`file-attributes' returns. If the current buffer has no recorded file
modification time, this function returns 0. If the visited file
doesn't exist, HIGH will be -1.
See Info node `(elisp)Modification Time' for more details."
)
(defun verify-visited-file-modtime (&optional buf)
"Return t if last mod time of BUF's visited file matches what BUF records.
This means that the file has not been changed since it was visited or saved.
If BUF is omitted or nil, it defaults to the current buffer.
See Info node `(elisp)Modification Time' for more details."
)
(defun insert-file-contents (filename &optional visit beg end replace)
"Insert contents of file FILENAME after point.
Returns list of absolute file name and number of characters inserted.
If second argument VISIT is non-nil, the buffer's visited filename and
last save file modtime are set, and it is marked unmodified. If
visiting and the file does not exist, visiting is completed before the
error is signaled.
This function does code conversion according to the value of
`coding-system-for-read' or `file-coding-system-alist', and sets the
variable `last-coding-system-used' to the coding system actually used."
(let [file (let [file (io/file (expand-file-name filename))]
(if (.exists file)
(.toURL file)
(io/resource filename)))
contents (slurp file)
contents (if (and visit beg end)
(subs contents beg end)
contents)
path (.getPath file)
point (editfns/point)]
(editfns/insert contents)
(when visit
(reset! (.save-modiff ^BufferText (.text ^Buffer (buffer/current-buffer))) (System/currentTimeMillis))
;; These vars are buffer local.
(el/setq buffer-file-name path)
(el/setq buffer-file-truename filename) ; Might be correct, should be result of files/file-truename.
(el/setq buffer-saved-size (count contents)))
(doseq [f (data/symbol-value 'after-insert-file-functions)]
(editfns/goto-char 1)
(eval/funcall f (count contents)))
(editfns/goto-char point)
(list path (count contents))))
(defun set-file-times (filename &optional timestamp)
"Set times of file FILENAME to TIMESTAMP.
Set both access and modification times.
Return t on success, else nil.
Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
`current-time'."
)
(defun set-file-modes (filename mode)
"Set mode bits of file named FILENAME to MODE (an integer).
Only the 12 low bits of MODE are used.
Interactively, mode bits are read by `read-file-modes', which accepts
symbolic notation, like the `chmod' command from GNU Coreutils."
(interactive "(let ((file (read-file-name \"File: \"))) (list file (read-file-modes nil file)))"))
This function always sets the file modes of the output file to match
the input file.
Fourth arg KEEP-TIME non-nil means give the output file the same
last-modified time as the old one. (This works on only some systems.)
(defun file-modes (filename)
"Return mode bits of file named FILENAME, as an integer.
Return nil, if file does not exist or is not accessible."
)
hraberg/deuce
(ns deuce.emacs.composite
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c])
(:refer-clojure :exclude []))
(defvar auto-composition-mode nil
"Non-nil if Auto-Composition mode is enabled.
Use the command `auto-composition-mode' to change this variable.")
GSTRING is a template of a glyph-string to return. It is already
filled with a proper header for the characters to compose, and
glyphs corresponding to those characters one by one. The
function must return a new glyph-string with the same header as
GSTRING, or modify GSTRING itself and return it.
See also the documentation of `auto-composition-mode'.")
(defun compose-string-internal (string start end &optional components modification-func)
"Internal use only.
(defun compose-region-internal (start end &optional components modification-func)
"Internal use only.
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
#?@(:cljs [] :default [
clojure.java.shell/sh [t/Any :*
;would be nice (combine :* and kw args)
; t/Str :*
;& :optional {:in t/Any ;; any valid input to clojure.java.io/copy
; :inc-enc t/Str :out-env (t/U ':bytes t/Str)
; :env (t/U (Array t/Str) (t/Map t/Any t/Any))
; :dir (t/U t/Str java.io.File)}
:-> '{:exit t/Str
:out (t/U (Array byte) t/Str)
:err t/Str}]
clojure.java.browse/browse-url [t/Any :-> t/Any]
clojure.java.io/delete-file [clojure.java.io/Coercions (t/? t/Any) :-> t/Any]
clojure.java.io/make-parents [(t/+ clojure.java.io/Coercions) :-> t/Any]
clojure.java.io/file [(t/+ clojure.java.io/Coercions) :-> java.io.File]
clojure.java.io/as-relative-path [clojure.java.io/Coercions :-> t/Str]
;; TODO second arg is flattened IOFactoryOpts
clojure.java.io/reader [clojure.java.io/IOFactory :-> java.io.BufferedReader]
;; TODO second arg is flattened IOFactoryOpts
clojure.java.io/writer [clojure.java.io/IOFactory :-> java.io.BufferedWriter]
clojure.java.io/resource [t/Str (t/? ClassLoader) :-> (t/Nilable java.net.URL)]
clojure.stacktrace/e [:-> t/Any]
clojure.stacktrace/print-cause-trace [Throwable :-> t/Any]
clojure.stacktrace/print-stack-trace [Throwable :-> t/Any]
clojure.stacktrace/print-throwable [Throwable :-> t/Any]
clojure.stacktrace/root-cause [Throwable :-> Throwable]
;; FIXME keyword arguments
clojure.reflect/reflect [(t/+ t/Any) :-> (t/Map t/Any t/Any)]
clojure.inspector/atom? [t/Any :-> t/Bool]
clojure.inspector/collection-tag [t/Any :-> t/Keyword]
clojure.inspector/tree-model [t/Any :-> t/Any]
clojure.inspector/old-table-model [t/AnySeqable :-> t/Any]
clojure.inspector/inspect [t/Any :-> javax.swing.JFrame]
clojure.inspector/inspect-tree [t/Any :-> javax.swing.JFrame]
clojure.inspector/inspect-table [t/AnySeqable :-> javax.swing.JFrame]
])
cc/mod (t/IFn [t/AnyInteger t/AnyInteger :-> t/AnyInteger]
[t/Num t/Num :-> t/Num])
#?@(:cljs [] :default [
cc/get-thread-bindings [:-> (t/Map t/AnyVar t/Any)]
cc/bound-fn*
(t/All [r b :..]
[[b :.. b :-> r] :-> [b :.. b :-> r]])
cc/find-var
[t/Sym :-> (t/Nilable t/AnyVar)]
cc/agent
(t/All [x] [x & :optional {:validator (t/Nilable [x :-> t/Any]) :meta t/Any
:error-handler (t/Nilable [(t/Agent x) Throwable :-> t/Any])
:error-mode (t/U ':continue ':fail)}
:-> (t/Agent x)])
cc/set-agent-send-executor! [java.util.concurrent.ExecutorService :-> t/Any]
cc/set-agent-send-off-executor! [java.util.concurrent.ExecutorService :-> t/Any]
cc/send-via (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/send (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/send-off (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/await [t/AnyAgent :* :-> nil]
cc/await-for [t/AnyInteger t/AnyAgent :* :-> t/Bool]
cc/await1 (t/All [[a :< t/AnyAgent]] [a :-> (t/Nilable a)])
cc/release-pending-sends [:-> t/AnyInteger]
])
#?@(:cljs [] :default [
cc/agent-error [t/AnyAgent :-> (t/Nilable Throwable)]
cc/restart-agent (t/All [x] [(t/Agent x) x & :optional {:clear-actions t/Any} :-> t/Any])
cc/set-error-handler! (t/All [x] [(t/Agent x) [(t/Agent x) Throwable :-> t/Any] :-> t/Any])
cc/error-handler (t/All [[a :< t/AnyAgent]] [a :-> (t/Nilable [a Throwable :-> t/Any])])
cc/set-error-mode! [t/AnyAgent (t/U ':fail ':continue) :-> t/Any]
cc/error-mode [t/AnyAgent :-> t/Any]
cc/agent-errors [t/AnyAgent :-> (t/Nilable (t/ASeq Throwable))]
cc/clear-agent-errors [t/AnyAgent :-> t/Any]
cc/shutdown-agents [:-> t/Any]
])