Skip to content

Instantly share code, notes, and snippets.

View ertugrulcetin's full-sized avatar

Ertuğrul Çetin ertugrulcetin

View GitHub Profile
@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]
@ertugrulcetin
ertugrulcetin / ticks-scheduler.clj
Last active March 30, 2021 17:58
Ticks scheduler - Clojure core.async
(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 March 15, 2021 08:28
GitHub Clojure code search with unified repository results - Clojure, Babashka
#!/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 January 15, 2021 12:44
jme-clj - Hello Collision Example
;; 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)))