Skip to content

Instantly share code, notes, and snippets.

View thegeez's full-sized avatar

Gijs Stuurman thegeez

View GitHub Profile
(ns crepl.svg.smiley
(:require [reagent.core :as r]
crepl.atom-sync))
(def happiness (crepl.atom-sync/atom-sync 30))
(defn smiley []
[:svg {:x 0 :y 0 :width 100 :height 100}
[:rect {:x 50 :y 50 :width 10 :height 10}]
[:circle {:cx 50 :cy 50 :r 40 :fill
@thegeez
thegeez / crepl_tic-tac-toe.clj
Created February 11, 2017 16:07
crepl Tic Tac Toe example with atom sync
(ns crepl.tic-tac-toe
(:require [reagent.core :as r]
crepl.atom-sync))
;; use this instead of reagent.core/atom to keep the state in sync
(def data (crepl.atom-sync/atom-sync {:turn :X}))
(def win-lines (-> #{}
(into (for [i (range 3)]
(for [j (range 3)]
@thegeez
thegeez / crepl_reagent_example.cljs
Created February 5, 2017 16:51
An example with Reagent for crepl.thegeez.net
(ns crepl.reagent.example
(:require [reagent.core :as r]))
(def temp-data (r/atom {:celsius 20 :fahrenheit 68}))
(defn calc-temperature []
(let [{:keys [celsius fahrenheit] :as data} @temp-data]
(if (nil? celsius)
(assoc data :celsius (* (- fahrenheit 32) 5/9))
(assoc data :fahrenheit (+ (* celsius 9/5) 32)))))
@thegeez
thegeez / spec_parsing.clj
Last active December 30, 2023 18:17
Parsing with clojure.spec for the Advent of Code challenge
(ns net.thegeez.advent.spec-parsing
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.test.check.generators :as tgen]))
;; Dependencies:
;; [org.clojure/clojure "1.9.0-alpha14"]
;; [org.clojure/test.check "0.9.0"]
;; Advent of Code is a series of code challenges in the form of an advent
@thegeez
thegeez / adt.clj
Created July 19, 2016 18:39
match for spec
(ns adt
(:require [clojure.spec :as s]))
(defmacro match [spec x & cases]
(let [fr (s/form spec)
[ffr & frcases] fr
_ (assert (= `s/or ffr)
"match only works on clojure.spec/or specs")
expected-cases (set (take-nth 2 frcases))
found-cases (set (map first cases))
@thegeez
thegeez / 4clojure-editor
Created January 10, 2014 14:06
4clojure in an editor
;; 1. Common test utility
(require '[clojure.walk :as walk])
(defmacro to-test [name & source]
`(defn ~(symbol (str name "-test")) [] ~@(for [case (filter list? source)]
`(assert ~(walk/postwalk-replace {'__ name} case)))))
;; 2. for each problem I write:
(def pNN
(fn ...solution here...))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
;; bin/repl with datomic-free-0.8.3664
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://future")
(d/create-database uri)
(def conn (d/connect uri))
;; balance attr
@thegeez
thegeez / clj15
Created May 22, 2012 19:13
Clojure snapshot usage
(defproject clj15 "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]
:repositories {"sonatype-oss-public" "https://oss.sonatype.org/content/groups/public/"}
)
(ns scratch.clomian
(:require clojure.java.io)
(:use [incanter core charts]))
;(set! *warn-on-reflection* true)
(def files (filter (fn [^java.io.File f]
(let [^String n (.getName f)]
(and
(.endsWith n ".dat")