Skip to content

Instantly share code, notes, and snippets.

ioRekz / hiccup-dom-spec.clj
Created Jan 22, 2018
Specing valid hiccup dom
View hiccup-dom-spec.clj
(ns hiccup-html-spec.core
(:require [clojure.spec.alpha :as s]
[phrase.alpha :refer [defphraser phrase-first phrase]]))
;;- spec a valid dom hiccup
;;- have errors like React for
;; . invalid descendant -> "<div> cannot appear as a descendant of <p>"
;; . unknown tag -> "The tag <divv> is unrecognized in this browser"
;; . void element -> "img is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`"
View url-spec.clj
'[cemerick.url :as url]
'[clojure.spec.alpha :as s]
'[clojure.spec.gen.alpha :as sgen])
(defn non-empty-string-alphanumeric
(sgen/such-that #(not= "" %)
View todos.cljs
(require '[reagent.core :as reagent])
(require '[cljs.core.async :as async :refer [<! >!]])
(require-macros '[cljs.core.async.macros :refer [go go-loop]])
(def state
{:todos [{:text "Learn Clojure" :done true}
{:text "Try Clojurescript" :done true}
{:text "Make an App"}]
:todo-input ""}))
View async.cljs
(require '[reagent.core :as reagent])
(require '[cljs.core.async :as async :refer [<! >!]])
(require-macros '[cljs.core.async.macros :refer [go go-loop]])
(def increment-chan (async/chan))
(def counter
(reagent/atom 1))
(defn increment []
View websocket.cljs
(require '[reagent.core :as reagent])
(require '[goog.object :as gobject])
(def socket (js/WebSocket. "wss://"))
(gobject/set socket "onopen" #(prn "Socket Open"))
(gobject/set socket "onmessage" #(prn "New Message Received" (.-data %)))
(defn send-message [msg]
(.send socket msg))
View colors.cljs
(require '[reagent.core :as reagent])
(def color
(reagent/atom "black"))
(def styles
{:inputs {:padding "15px"}
:inputs-label {:margin-left "5px"}
:text {:fontSize "20px"}})
View hello.cljs
(defn hello [name]
(str "Hello " name " !"))
(.-innerHTML js/klipse-container)
(str "<div>" (hello "World") "</div>"))
View project.clj
(defproject clr "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"]
[org.clojure/core.async "0.2.371"]
[cljs-http "0.1.37"]
ioRekz / EventNameExtractor.scala
Last active Jan 2, 2016
Play Scala SSE EventEtractor from json
View EventNameExtractor.scala
import play.api.libs.EventSource._
implicit def pair[E]: EventNameExtractor[JsValue] = EventNameExtractor[JsValue](p => Some((p \ "event").as[String]))
View StackableTrait.scala
//every power got specific points
trait Power {
def points: Int
trait Speed extends Power {
//abstract override is the special identifier for stackable feature
//super is now referencing the previous trait in the linearization that is, the previous in the declaration
abstract override def points = super.points + 10