Skip to content

Instantly share code, notes, and snippets.

@philjackson
philjackson / drag-drop-reagent.cljs
Created Oct 30, 2018
Drag and drop with Reagent and Interact.js
View drag-drop-reagent.cljs
(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]
View cider-config.el
(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 / compojure.clj
Last active Jul 17, 2018
Sensible compojure/ring defaults for an API
View compojure.clj
(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
View emacs-config.el
(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 / attach.el
Last active Aug 30, 2021
From an mu4e view, without prompt, save all attachments to a directory and open dired.
View attach.el
;; 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)))
View condev.clj
(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 / alarm.bash
Created Sep 1, 2015
Simple alarm for linux
View alarm.bash
#!/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}
View export-emacs
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
}