Skip to content

Instantly share code, notes, and snippets.

Yehonathan Sharvit viebel

Block or report user

Report or block viebel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View klipse-re-frame.cljs
(ns simple.core
(:require [reagent.core :as r]
[re-frame.core :as rf]))
(rf/reg-event-db
:initialize
(fn [_ _]
{:loading? true}))
(rf/reg-event-db
View clojure_spec_missing_piece.clj
(require
'[clojure.spec :as s]
'[clojure.spec.test :as test])
(defn naive-english-explain
"Copy and paste this into your app. Figure out what it does by
trying it in production."
([] (naive-english-explain (ex-data *e)))
([spec-explain-data]
(let [p1 (-> spec-explain-data ::s/problems first)]
@viebel
viebel / set-game.clj
Last active Feb 22, 2017 — forked from cgrand/set-game.clj
the SET game in clojure.spec
View set-game.clj
; the SET game in clojure.spec
;; inspired by https://github.com/jgrodziski/set-game
(require '[clojure.spec :as s])
(require 'clojure.test.check.generators)
(require '[clojure.spec.impl.gen :as gen])
(s/def ::shape #{:oval :diamond :squiggle})
(s/def ::color #{:red :purple :green})
(s/def ::value #{1 2 3})
@viebel
viebel / spectest.cljs
Created Feb 11, 2017 — forked from Risto-Stevcev/spectest.cljs
Some functions to help integrate clojure.spec.test/check with cljs.test/deftest
View spectest.cljs
(ns foo-test
(:require [cljs.spec :as s]
[cljs.spec.test :as stest]
[clojure.pprint :as pprint]
[cljs.test :refer [run-tests deftest is]]))
;; Sample function and a function spec
(defn fooo [i] (+ i 20))
(s/fdef fooo
View tictactoe.cljs
(ns tic.tac.toe
(:require [reagent.core :as r]))
(enable-console-print!)
(defn vanilla-state []
(r/atom {:squares (vec (repeat 9 nil))
:x-is-next true
:winner nil}))
@viebel
viebel / core.clj
Last active Jan 5, 2017 — forked from Engelberg/core.clj
Twenty four using partitions
View core.clj
;; Live demo with klipse - http://app.klipse.tech/?cljs_in.gist=viebel/54a9699398205a3ed41fc881a4232e08&eval_only=1
(ns twentyfour.core
(:require [clojure.math.combinatorics :refer [partitions]]))
(def ops ['+ '- '* '/])
(def commutative #{'+ '*})
;; We can generate all the possible expressions efficiently with combinatorics' partitions
;; partitions automatically handles duplicates for us, which keeps the process efficient
@viebel
viebel / limitEval.js
Created Nov 1, 2016 — forked from westc/limitEval.js
Use web workers to limit the amount of time that an eval can run.
View limitEval.js
function limitEval(code, fnOnStop, opt_timeoutInMS) {
var id = Math.random() + 1,
blob = new Blob(
['onmessage=function(a){a=a.data;postMessage({i:a.i+1});postMessage({r:eval.call(this,a.c),i:a.i})};'],
{ type:'text/javascript' }
),
myWorker = new Worker(URL.createObjectURL(blob));
function onDone() {
URL.revokeObjectURL(blob);
@viebel
viebel / sets.clj
Last active Oct 27, 2016 — forked from cemerick/sets.clj
Name that set operation!
View sets.clj
; I'm hoping to find a common name for a particular operation over sets that I've
; been thinking of as a "join" of sorts.
;
; It's _not_ a relational join -- the values involved aren't relations (for me
; at the moment, they're actually graphs essentially representing
; disjoint recursive sets, but I think that's probably irrelevant
; detail) -- but it feels like it's in the spirit of a full outer join
;
; Given N sets, recursively produce all unions of those sets that are disjoint.
@viebel
viebel / spec.cljs
Last active Jun 8, 2016 — forked from swannodette/spec.cljs
om.next query spec
View spec.cljs
(ns om.next.spec
(:require [cljs.spec :as s]))
(s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
(s/def ::join-key (s/or :prop keyword? :ident ::ident))
(s/def ::join (s/and (s/map-of ::join-key ::query) #(= (count %) 1)))
(s/def ::union (s/and (s/map-of keyword? ::query) #(> (count %) 1)))
(s/def ::param-expr
(s/cat :query-expr ::query-expr
@viebel
viebel / spec_example.cljs
Last active Apr 27, 2017 — forked from bhb/spec-example.clj
Recursive spec with clojure.spec
View spec_example.cljs
(ns viebel.gist-57d9ebad3381e727c2f0a373e1bd4eec.raw.spec-example
(:require [cljs.spec :as s]))
(s/def ::tag (s/cat :type #{:div}
:attrs map?
:children (s/spec (s/* ::tag))))
(s/explain ::tag [:div {} [[:div {} []]]])
;; In: [2 0] val: [:div {} []] fails spec: _ at: [:children :type] predicate: #{:div}
You can’t perform that action at this time.