Skip to content

Instantly share code, notes, and snippets.

(ns cljsplayground.core
(:require [reagent.core :as reagent :refer [atom]]
[goog.dom :as dom]
[goog.events :as events]
[cljs.tools.reader :as r]
[cljs.analyzer :as ana]
[cljs.compiler :as c]
[cljs.core.async :refer [put! chan <! >! timeout close!]]
[cljsplayground.console :as console])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
@piecyk
piecyk / core.cljs
Last active October 13, 2015 14:08
Example of jqconsole in clojurescript reagent core-async
(ns cljsplayground.core
(:require [reagent.core :as reagent :refer [atom]]
[cljs.core.async :refer [put! chan <! >! timeout close!]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
;; jquery and jqconsole are included into index.html with <script> tag for this example
(defn jqconsole-prompt [jqconsole chan]
(.Prompt jqconsole true #(put! chan %) (fn [str] (.log js/console str) false)))
function JQConsole(outer_container, header, prompt_label, prompt_continue_label) {};
JQConsole.prototype.ResetHistory = function() {};
JQConsole.prototype.ResetShortcuts = function() {};
JQConsole.prototype.ResetMatchings = function() {};
JQConsole.prototype.Reset = function() {};
@piecyk
piecyk / react-0.14.0.js
Last active October 9, 2015 13:28
Log render function of ReactJS
// replace the _renderValidatedComponent in react-0.14.0.js with this function
_renderValidatedComponent: function () {
// orginal function
function renderValidatedComponent() {
var renderedComponent;
ReactCurrentOwner.current = this;
try {
renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
} finally {
ReactCurrentOwner.current = null;
@piecyk
piecyk / postgis.clj
Created October 6, 2015 10:21 — forked from attentive/postgis.clj
PostGIS and Korma
(ns postgis
(:require [clj-json.core :as json])
(:use korma.core korma.db korma.sql.engine))
(defn intersects [first-geom second-geom]
"An extended Korma predicate that uses the PostGIS function ST_Intersects."
(sql-func "ST_Intersects" first-geom second-geom))
(defn from-wkt [wkt]
"Create a PostGIS geometry with geographic SRID from WKT using ST_GeomFromText."
@piecyk
piecyk / bloop.js
Last active September 22, 2015 11:19 — forked from jlongster/bloop.js
bloop
(function() {
// Do not use this library. This is just a fun example to prove a
// point.
var Bloop = window.Bloop = {};
var mountId = 0;
function newMountId() {
return mountId++;
}
@piecyk
piecyk / core.cljs
Last active September 17, 2015 19:24
(def m-chan (chan (sliding-buffer 100)))
(def map-state (r/atom {:pressed? false ; if mouse down is pressed?
:transform-map [1 0 0 1 0 0] ; transform map position ;TODO: add zoooming
:start-point {:x 0 :y 0} ; start point for move the map
:end-point {:x 0 :y 0} ; last point for map move
:move-point {:x 0 :y 0}})) ; current point of map move
(defn pan [x y]
(swap! map-state update-in [:transform-map] assoc 4 x 5 y))
@piecyk
piecyk / core.cljs
Last active September 13, 2015 18:20
clojurescript reagent svg map
(def transform-state (reagent/atom [1 0 0 1 0 0]))
(def start-point (reagent/atom nil))
(def mouse-down? (reagent/atom false))
(def mouse-chan (chan))
(defn pan [x y]
(swap! transform-state assoc 4 x 5 y))
(defn drag-map []
(go (while true
@piecyk
piecyk / ScalaEnum.scala
Last active August 29, 2015 14:27 — forked from viktorklang/ScalaEnum.scala
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@piecyk
piecyk / core.clj
Last active September 14, 2019 07:34
clojurescript google maps API
(declare *map*)
(def user-events (atom []))
(defn handler-events [res]
;; clear markers from the map
(doseq [e @user-events]
(.setMap (:marker e) nil))
(let [m (map #(assoc % :marker (event-marker %)) res)]
(reset! user-events m)))