Skip to content

Instantly share code, notes, and snippets.

Avatar

Ertuğrul Çetin ertugrulcetin

View GitHub Profile
@ertugrulcetin
ertugrulcetin / fast-re-frame-schema-check.cljs
Last active Apr 21, 2021
Optimized Re-frame schema validation/check - ClojureScript, malli
View fast-re-frame-schema-check.cljs
(ns interceptors
(:require
[clojure.data :as d]
[malli.core :as m]
[malli.error :as me]))
(def prev-state (atom nil))
;; Applies schema only changed parts (diff) of the app-db (state)
(defn check-and-throw [schema state]
@ertugrulcetin
ertugrulcetin / ticks-scheduler.clj
Last active Mar 30, 2021
Ticks scheduler - Clojure core.async
View ticks-scheduler.clj
(defmacro deftickscheduler [name ticks-per-sec & body]
`(when-not *compile-files*
(def ~name (let [ticks-per-sec# (/ 1000 ~ticks-per-sec)
running?# (volatile! true)]
{:var (var ~name)
:channel (a/go-loop []
(when @running?#
(let [start# (System/currentTimeMillis)
_# (do ~@body)
elapsed# (- (+ start# ticks-per-sec#) (System/currentTimeMillis))]
@ertugrulcetin
ertugrulcetin / repo-search.clj
Last active Mar 15, 2021
GitHub Clojure code search with unified repository results - Clojure, Babashka
View repo-search.clj
#!/usr/bin/env bb
(require '[babashka.curl :as curl])
(require '[clojure.java.io :as io])
(require '[cheshire.core :as json])
(defn- call [q page]
(-> (curl/get "https://api.github.com/search/code"
{:headers {"Accept" "application/vnd.github.previe"}
:query-params {"q" (str q " language:Clojure")
@ertugrulcetin
ertugrulcetin / hello-collision.clj
Last active Jan 15, 2021
jme-clj - Hello Collision Example
View hello-collision.clj
;; Please have a look https://github.com/ertugrulcetin/jme-clj for more.
;; Demo video used this gist: https://www.youtube.com/watch?v=IOPz9I49snM
(ns examples.beginner-tutorials.hello-collision
"Clojure version of https://wiki.jmonkeyengine.org/docs/3.3/tutorials/beginner/hello_collision.html"
(:require [jme-clj.core :refer :all])
(:import
(com.jme3.asset.plugins ZipLocator)
(com.jme3.input KeyInput)
(com.jme3.math ColorRGBA)))
@ertugrulcetin
ertugrulcetin / hello-physics.clj
Last active Dec 22, 2020
jme-clj - Hello Physics Example
View hello-physics.clj
;; Please have a look https://github.com/ertugrulcetin/jme-clj for more.
;; Demo video used this gist: https://www.youtube.com/watch?v=IOPz9I49snM
(ns examples.beginner-tutorials.hello-physics
"Clojure version of https://wiki.jmonkeyengine.org/docs/3.3/tutorials/beginner/hello_physics.html"
(:require [jme-clj.core :refer :all])
(:import
(com.jme3.input MouseInput)
(com.jme3.math Vector3f)
(com.jme3.scene.shape Sphere$TextureMode)
(com.jme3.texture Texture$WrapMode)))
@ertugrulcetin
ertugrulcetin / jmonkey-engine.clj
Last active Nov 30, 2020
jMonkeyEngine Clojure example with hot reload in REPL
View jmonkey-engine.clj
(ns jm-clj.core
(:import (com.jme3.app SimpleApplication)
(com.jme3.scene.shape Box)
(com.jme3.scene Geometry)
(com.jme3.material Material)
(com.jme3.math ColorRGBA)))
(defn my-logic [^SimpleApplication this]
(let [b (Box. 1 1 1)
geom (Geometry. "Box" b)
View jmonkey.clj
(ns jm-clj.core
(:import (com.jme3.app SimpleApplication)
(com.jme3.scene.shape Box)
(com.jme3.scene Geometry)
(com.jme3.material Material)
(com.jme3.math ColorRGBA)))
;(def ^:dynamic *app-settings* (doto (AppSettings. true)
; (.setFullscreen false)
; (.setTitle "jme_clj")))
@ertugrulcetin
ertugrulcetin / nested-macro.clj
Created Nov 21, 2020
Clojure nested macro sample
View nested-macro.clj
(defmacro component
([name tag]
`(component ~name ~tag nil))
([name tag docs]
(if docs
`(defmacro ~(with-meta name {:tag tag}) ~docs
[object# k# & options#]
`(u/call! ~object# ~k# ~@options#))
`(defmacro ~(with-meta name {:tag tag})
[object# k# & options#]
@ertugrulcetin
ertugrulcetin / update-xmind.clj
Created Oct 16, 2020
Manipulate Xmind file in Clojure
View update-xmind.clj
(defn update-xmind
"Manipulates Xmind data and saves as a binary format. Usage:
This example updates all \"Report\" titles with \"HEY!\"
(update-xmind \"~/xmind-files/report.xmind\"
\"~/xmind-files/report-new.xmind\"
(fn [data]
(o/transform data
(o/and
(d/query data ?path :title ?title)
@ertugrulcetin
ertugrulcetin / reveal-bindings.clj
Last active Sep 30, 2020
Revealing variables final values based on substitution map by using logic programming in Clojure.
View reveal-bindings.clj
(require '[clojure.core.logic :refer [== run fresh]]
'[clojure.walk :as walk])
(defn function-call->form [form]
(walk/prewalk (fn [node]
(cond
(and (list? node)
(or (-> node first resolve nil?)
(-> node first resolve meta :special-form)
(-> node first resolve meta :macro)))