Skip to content

Instantly share code, notes, and snippets.

View ertugrulcetin's full-sized avatar

Ertuğrul Çetin ertugrulcetin

View GitHub Profile
@ertugrulcetin
ertugrulcetin / alet_macro.cljs
Created May 24, 2025 20:53
ClojureScript macro alet that enables async/await-like syntax for JavaScript Promises and core.async channels. It supports sequential binding with optional (await ...) expressions and body steps, and includes an optional (catch err ...) clause for error handling.
;; ClojureScript macro alet that enables async/await-like syntax for JavaScript Promises and core.async channels.
;; It supports sequential binding with optional (await ...) expressions and body steps, and includes an optional (catch err ...) clause for error handling.
(defmacro alet [bindings & body]
(let [last-expr (last body)
[body catch]
(if (and (seq? last-expr) (= 'catch (first last-expr)))
[(butlast body) last-expr]
[body nil])
;; Parse bindings into pairs like let does
@ertugrulcetin
ertugrulcetin / make_animation_in_place.py
Created May 18, 2025 15:13
Blender Script: Convert Character Animation to In-Place (Zero Root Bone Translation)
import bpy
def make_animation_in_place(anim_name="rotate"):
"""
Modifies the given animation to be in-place by setting
X, Y, and Z location keyframe values to 0.
"""
action = bpy.data.actions.get(anim_name)
if not action:
@ertugrulcetin
ertugrulcetin / js-interop.cljs
Last active May 31, 2025 14:36
ClojureScript Patch: assoc, dissoc, update-in for JS Objects
;; ClojureScript Patch: assoc, dissoc, update-in for JS Objects
;; Extends assoc, dissoc, and update-in to work seamlessly with native JavaScript objects in ClojureScript.
;; This namespace bridges the gap between idiomatic ClojureScript data manipulation and JavaScript interop, enabling structural updates on #js objects using familiar Clojure semantics.
(ns preload
(:refer-clojure :exclude [dissoc update-in assoc-in])
(:require
[applied-science.js-interop :as j]
[clojure.string :as str]))
(def kw->str
@ertugrulcetin
ertugrulcetin / app.core.cljs
Created November 18, 2023 13:13
Streamline UIx Development with a Hiccup-Style Components
(ns app.core
(:require
[cljs.spec.alpha :as s]
[clojure.edn :as edn]
[uix.core :as uix :refer [defui $]]
[uix.dom])
(:require-macros
[app.macros :as m]))
(m/defui header []
var Terrain = pc.createScript('terrain');
Terrain.attributes.add('heightMap', {
type: 'asset',
assetType: 'texture'
});
Terrain.attributes.add('minHeight', {
type: 'number',
default: 0
@ertugrulcetin
ertugrulcetin / heightmap-in-the-editor.js
Last active October 31, 2022 16:53
Generate terrain from heightmap in the editor for PlayCanvas
// Download Violentmonkey -> https://chrome.google.com/webstore/detail/violentmonkey/jinjaccalgkegednnccohejagnlnfdag/related
// Paste the code for https://playcanvas.com
// Sample project: https://playcanvas.com/project/1002857/overview/render-heightmap-in-the-editor
// ==UserScript==
// @name PlayCanvas
// @namespace Violentmonkey Scripts
// @match https://playcanvas.com/editor/scene/*
// @grant none
// @version 1.0
@ertugrulcetin
ertugrulcetin / download-game.clj
Last active October 22, 2022 13:00
Download PlayCanvas project via shell/babashka in Clojure
#!/usr/bin/env bb
;; To install babashka -> https://github.com/babashka/babashka#quickstart
(require '[babashka.curl :as curl])
(require '[babashka.tasks :as tasks])
(require '[cheshire.core :as json])
(require '[clojure.java.io :as io])
(def project-id 1111)
@ertugrulcetin
ertugrulcetin / by-sorting.clj
Last active June 14, 2022 11:39
Clojure: sort by multiple keys with different orderings
;; https://www.reddit.com/r/Clojure/comments/ufa8e0/clojure_sort_by_multiple_keys_with_different/
(let [sort-fns-map {:asc (fn [a b] (. clojure.lang.Util compare a b))
:desc (fn [a b] (. clojure.lang.Util compare b a))}]
(defn by [& keys-orderings]
(fn [a b]
(loop [[key ordering & keys-orderings] keys-orderings]
(let [order ((get sort-fns-map ordering ordering) (key a) (key b))]
(if (and (zero? order) keys-orderings)
(recur keys-orderings)
@ertugrulcetin
ertugrulcetin / multiplayer-network.js
Created March 17, 2022 18:08
Fast-Paced Multiplayer: Sample Code and Live Demo - Gabriel Gambetta
// https://www.gabrielgambetta.com/client-side-prediction-live-demo.html
// =============================================================================
// An Entity in the world.
// =============================================================================
var Entity = function() {
this.x = 0;
this.speed = 2; // units/s
this.position_buffer = [];
}
@ertugrulcetin
ertugrulcetin / fast-re-frame-schema-check.cljs
Last active June 1, 2022 07:26
Optimized Re-frame schema validation/check - ClojureScript, malli
(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 event]