Skip to content

Instantly share code, notes, and snippets.

@akovantsev
akovantsev / core.cljs
Last active June 9, 2017 06:35
basic drag/drop in rum/react
(ns ui.core
(:require
[rum.core :as rum]
[ui.styles :as styles]
[ui.drag :as drag]))
(rum/defcs item-modal < (drag/draggable-mx styles/item-modal) [state item]
(let [*position (get state drag/k)
drag! #(drag/start-drag! *position (:id item))
let pad = " ".repeat(10);
for (i=0; i<20; i++) {
let c = "#" + Math.floor(Math.random()*16777215).toString(16);
console.log("%c" + pad + c + pad, "font-size:20px; background-color:" + c);
}
@akovantsev
akovantsev / xpath.js
Last active September 23, 2019 14:18
// path needs tail tweaks
var tagname = function (node) {
return node.tagName || "#text";
};
var xpath = function (node, idx, tag, path) {
idx = idx || 0;
tag = tag || tagname(node);
path = path || "";
@akovantsev
akovantsev / rum-debug-mixin.cljc
Created October 17, 2019 11:24
rum-debug-mixin
(defn rum-debug-mixin [component-name]
(let [p (partial prn component-name)]
{:init (fn [state props] (p :init props) state)
:will-mount (fn [state] (p :will-mount) state)
:before-render (fn [state] (p :before-render) state)
:wrap-render (fn [render-fn] (p :wrap-render) render-fn)
;:render (fn [state] (p :render) [[:div#pseudo-dom {} "pseudodom"] state])
:did-catch (fn [state, err, info] (p :did-catch err info) state)
:did-mount (fn [state] (p :did-mount) state)
:after-render (fn [state] (p :after-render) state)
@akovantsev
akovantsev / chaos-game.html
Created November 10, 2019 02:43
May 7th, 2017 at 12:22 AM
<html>
<head>
<title>chaos</title>
</head>
<body>
<canvas id="chaos" width="0" height="0" style="border:1px solid #000000;">
</canvas>
<script type="text/javascript">
function getRandomInt(min, max) {
min = Math.ceil(min);
<canvas id="canvas"></canvas>
<script>
var num = 20000;
var canvas = document.getElementById("canvas");
var width = canvas.width = 960;
var height = canvas.height = 500;
var ctx = canvas.getContext("2d");
var numbers = [...Array(num).keys()];
var particles = numbers.map(function(i) {
return [Math.round(width*Math.random()), Math.round(height*Math.random())];
(ns foo
(:import
[java.io File]
[java.nio.file Files]
[org.apache.commons.codec.binary Base64]))
(def s
(->> "/path/to/image.png"
(new File)
(.toPath)
(defmacro locals-map [& [env]]
;; https://gist.github.com/noisesmith/3490f2d3ed98e294e033b002bc2de178
(let [ks (->> (or env &env)
keys
(remove #{'_})
(remove #(-> % name (str/includes? "__"))))]
(zipmap (map name ks) ks)))
(defmacro pp-locals []
`(clojure.pprint/pprint
@akovantsev
akovantsev / cursive-shadow-cljs-repl-setup.md
Last active June 3, 2025 10:15
Setting up shadow-cljs cljs REPL in Cursive
<body>
<style type="text/css">
body {
width: 600px;
margin-left: auto;
margin-right: auto;
}
pre {
white-space: pre-line;
}