Skip to content

Instantly share code, notes, and snippets.

@Deraen
Deraen / build-package.json
Last active January 16, 2024 19:25
Grunt build script for CI (Jenkins)
View build-package.json
# Create build-directory in project and place this package.json in that dir
{
"name": "build",
"version": "0.0.0",
"private": true,
"description": "Grunt-cli & Bower",
"dependencies": {
"grunt-cli": "0.1.11",
"bower": "1.2.8"
},
@Deraen
Deraen / spread_props.clj
Created December 13, 2023 09:48
UIx spread props
View spread_props.clj
(ns common.util
(:require [clojure.string :as str]
[uix.compiler.attributes :as attr]
[uix.compiler.js :as js]))
;; Could also just emit Object.assign, a bit simpler and doesn't need js*.
;; Spread operator might be a bit faster in some cases, but depends on
;; the browser and many variables probably.
;; https://clojurians.slack.com/archives/CNMR41NKB/p1701179422380989
;; We might not want to keep this optimized version in the repo and
@Deraen
Deraen / linters.clj
Created December 13, 2023 09:40
UIx MUI linter
View linters.clj
(ns dev.linters
(:require [cljs.analyzer :as ana]
[clojure.string :as str]
[uix.linter :as linter])
(:import (cljs.tagged_literals
JSValue)))
(defn mui-component? [tag]
;; TODO: Could check better if it looks like a MUI component
(symbol? tag))
@Deraen
Deraen / edn.cljx
Last active August 6, 2023 06:51
Transit / edn date/datetime serialisers
View edn.cljx
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging
@Deraen
Deraen / shadow.clj
Created May 4, 2022 12:13
Shadow CLJS and Dart Sass
View shadow.clj
(ns app.dev.shadow
(:require [shadow.cljs.devtools.api :as shadow]
[clojure.edn :as edn]))
;; Run this with:
;; npx shadow-cljs clj-run app.dev.shadow/watch
(set! *warn-on-reflection* true)
(defn watch
@Deraen
Deraen / reagent-latency.cljs
Created November 10, 2022 18:45
Testing React vs Reagent update latency
View reagent-latency.cljs
(def start (atom nil))
(def log (atom []))
(defn latency-test []
(let [a (r/atom 0)]
(fn []
(let [[b update-b] (react/useState 0)]
(react/useEffect
(fn []
View TV lights.yml
alias: TV valot
description: ""
trigger:
- platform: state
entity_id:
- media_player.tv
not_to:
- unknown
for:
seconds: 5
@Deraen
Deraen / test.js
Last active April 25, 2021 13:02
react-use-context-test.js
View test.js
var vm = require("vm");
var fs = require("fs");
function nodeGlobalRequire(file) {
var _module = global.module,
_exports = global.exports,
exportedRequire = false;
// to circumvent Node.js environment detection in bundled libraries
global.module = undefined;
@Deraen
Deraen / editor.cljs
Last active March 27, 2021 15:34
ClojureScript goog.editor
View editor.cljs
(ns frontend.view.editor
(:require [reagent.core :as reagent]
[goog.dom :as dom])
(:import [goog.editor Field ContentEditableField Command]
[goog.ui.editor DefaultToolbar ToolbarController ToolbarFactory]
[goog.editor.plugins BasicTextFormatter RemoveFormatting ListTabHandler
SpacesTabHandler EnterHandler HeaderFormatter TableEditor]))
(defn editor-view []
(let [field-name (gensym)
@Deraen
Deraen / components.clj
Last active December 15, 2019 08:03
Compojure-api with Component
View components.clj
(ns foobar.components
(:require [com.stuartsierra.component :as component]
[compojure.api.sweet :refer :all]))
(defmethod compojure.api.meta/restructure-param :components
[_ components acc]
(update-in acc [:letks] into [components `(::components ~'+compojure-api-request+)]))
(defn wrap-components [handler components]
(fn [req]