Skip to content

Instantly share code, notes, and snippets.

@Frozenlock
Frozenlock / insert-in-last-ielm-eval
Created June 16, 2012 15:57
Insert a string in the last return value in ielm
(defun insert-in-last-ielm-eval (string)
(when (search-backward "ELISP>" nil t)
(backward-char 1)
(newline)
(insert string)
(goto-char (point-max))))
@Frozenlock
Frozenlock / gist:3026701
Created July 1, 2012 03:37
Export org document for Noir webserver
(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 "./" "/"))))
@Frozenlock
Frozenlock / gist:3140372
Created July 19, 2012 02:28
Uppercase word in emacs (with save-excursion)
(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!"))))
@Frozenlock
Frozenlock / gist:3194922
Created July 28, 2012 21:44
Open command shows a list of recent file
;----------------------------------------------------
;;;==== 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 ()
(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))
(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
(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]))
(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)))
;; 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)))
@Frozenlock
Frozenlock / test.cljs
Last active June 16, 2017 13:15 — forked from skrat/test.cljs
;; 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)))