Skip to content

Instantly share code, notes, and snippets.

function export-emacs {
if [ "$(emacsclient -e t)" != 't' ]; then
return 1
fi
for name in "${@}"; do
value=$(eval echo \"\$${name}\")
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}
@philjackson
philjackson / alarm.bash
Created September 1, 2015 11:21
Simple alarm for linux
#!/usr/bin/env bash
time="${1}"
if [[ -z ${time} ]]; then
echo "Need a time to ring!" >&2
exit 1
fi
echo "DISPLAY=:0 xmessage alarm" | at ${time}
(defmacro condev
"Takes clauses in the same style as `cond` but, if the left side is
truthy, will execute the right side of the expressions as a function
which gets the result of evaluation of the left side."
[& clauses]
(assert (even? (count clauses)))
(let [pstep (fn [[test step]] `(when-let [r# ~test] (~step r#)))]
`(list ~@(map pstep (partition 2 clauses)))))
@philjackson
philjackson / attach.el
Last active August 30, 2021 19:13
From an mu4e view, without prompt, save all attachments to a directory and open dired.
;; DEPRECATED - see https://pitch-io.slack.com/archives/CBKNRBRHA/p1630054796006400
(defvar bulk-saved-attachments-dir (expand-file-name "~/Documents/mu4e"))
(defun cleanse-subject (sub)
(replace-regexp-in-string
"[^A-Z0-9]+"
"-"
(downcase sub)))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
;; minimally, install use-package
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(blink-cursor-mode -1)
(tool-bar-mode -1)
@philjackson
philjackson / compojure.clj
Last active July 27, 2023 13:17
Sensible compojure/ring defaults for an API
(ns my-api.handler
(:require [compojure.core :refer :all]
[ring.util.response :refer [response status content-type]]
[ring.middleware.params :refer [wrap-params]]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.json :refer [wrap-json-response wrap-json-body]]))
(defroutes app-routes
(context "/v1" []
(GET "/" req
(defmacro evil-helper-cider-make-debug-command (&rest cider-commands)
"Make functions that wrap `cider-debug' commands.
Cider debug commands are sent through
`cider-debug-mode-send-reply'. ex. \(cider-debug-mode-send-reply
\":next\"\)"
(let ((commands (if (consp cider-commands)
cider-commands
(list cider-commands))))
`(progn
,@(cl-loop
@philjackson
philjackson / drag-drop-reagent.cljs
Created October 30, 2018 18:08
Drag and drop with Reagent and Interact.js
(defn draggable []
(let [pos (atom [0 0])]
(reagent/create-class
{:render
#(let [[x y] @pos]
[:div.d {:style {:transform (str "translate(" x "px," y "px)")}}
"I can be dragged"])
:component-did-mount
(fn [this]