This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn spit-to-zip | |
"Put the content in filename and zip it into zip-filename. Accept | |
one or more filename/content." | |
[zip-filename filename content & others] | |
(with-open [zip (java.util.zip.ZipOutputStream. | |
(clojure.java.io/output-stream zip-filename))] | |
(let [add-entry (fn [name cont remain] | |
(-> zip (.putNextEntry (java.util.zip.ZipEntry. name))) | |
(doto (java.io.PrintStream. zip true) | |
(.println content)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun insert-in-last-ielm-eval (string) | |
(when (search-backward "ELISP>" nil t) | |
(backward-char 1) | |
(newline) | |
(insert string) | |
(goto-char (point-max)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-org-html-export () | |
"Export an org document to a .html file, without the preamble, | |
postamble and css. Also make sure the image path is compatible with Noir." | |
(interactive) | |
(let ((exported-html-file (concat (file-name-sans-extension (buffer-file-name)) ".html")) | |
(exported-html (org-export-as-html 3 nil nil 'string 'body-only))) | |
(with-temp-file exported-html-file | |
(insert exported-html) | |
(goto-char (point-min)) | |
(replace-string "./" "/")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global-set-key (kbd "C-c u") | |
(lambda()(interactive) | |
(save-excursion | |
(let (pt) | |
(skip-chars-backward "-_A-Za-z0-9") | |
(setq pt (point)) | |
(skip-chars-forward "-_A-Za-z0-9") | |
(upcase-region pt (point))) | |
(message "UPPERCASE!")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;---------------------------------------------------- | |
;;;==== Open command shows a list of recent file ==== | |
;---------------------------------------------------- | |
(require 'recentf) | |
;; enable recent files mode. | |
(recentf-mode t) | |
; 200 files ought to be enough. | |
(setq recentf-max-saved-items 200) | |
(defun ido-recentf-open () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun replace-string-in-rectangle (from-string to-string &optional delimited start end) | |
(interactive | |
(let ((common | |
(query-replace-read-args | |
"Replace string in rectangle" nil))) | |
(list (nth 0 common) (nth 1 common) (nth 2 common) | |
(region-beginning) | |
(region-end)))) | |
(let ((replacement-rectangle | |
(mapcar '(lambda (arg) (replace-in-string arg from-string to-string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn with-random | |
"Add a random geospatial queries to a fetch. Should be used with a | |
limit, otherwise default limit to 5 items." [fetch-fn coll & {:as args}] | |
(let [where (:where args) | |
new-args (vec (merge {:limit 5} ;security limit if none is provided | |
args {:where (merge where {:random_point {:$near [(rand) 0]}})}))] | |
(apply fetch-fn (concat [coll] (apply concat new-args))))) | |
(defn get-object-historic-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cea.buddy-token | |
"The token based authentication and authorization backends." | |
(:require [buddy.auth.protocols :as proto] | |
[buddy.auth.http :as http] | |
[buddy.auth :refer [authenticated?]] | |
[buddy.sign.jws :as jws] | |
[buddy.sign.jwe :as jwe] | |
[clojure.string :as s])) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn build-paths | |
"Given a tree (map), return all the paths leading to a value." | |
[m] | |
(->> (for [[k v] m] | |
(if (map? v) | |
(map #(cons k %) (build-paths v)) | |
[[k]])) | |
(apply concat))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; some speed tests of functions to access nested properties in JS objects. | |
(def test-data (->> (into {} (for [k1 (range 10)] | |
[k1 (into {} (for [k2 (range 10)] | |
[k2 (into {} (for [k3 (range 10)] | |
[k3 k3]))]))])) | |
(clj->js))) | |
OlderNewer