Skip to content

Instantly share code, notes, and snippets.

@timothypratley
timothypratley / constrained.cljs
Last active February 23, 2019 16:57
Rectangle collision
;; load this example in a browser from this link:
;; http://app.klipse.tech/?container=1&cljs_in.gist=timothypratley/f55596fa4c39e9e8326b2cfec0ec4551
(ns constrained.core
(:require [reagent.core :as reagent]
[goog.dom :as dom]))
(set! *warn-on-infer* true)
(defn collision? [x y w h other-rectangles]
(some

canvas: html

Hi!

Today we will build a rogue like game...


First we need to draw something on the "screen". We do this by calling html.

@timothypratley
timothypratley / forshame.md
Last active June 11, 2021 05:06
Error reporting in Clojure are the worst, no error reporting in ClojureScript is the worst.

For Shame!

Clojure error reporting is a problem. This gist contains examples of missed opportunities for a clear error message. Let's discuss how common scenarios can be improved, and get some "patch welcome" tickets out there with clearly defined expectations.

The problem

@timothypratley
timothypratley / gist:8157438
Last active January 1, 2016 14:19
Why functions + data is worth an extra argument in preference to classes
; starting with the example you had https://gist.github.com/Engelberg/8141352
(def rows 3)
(def cols 4)
(def cells (for [row (range rows), col (range cols)] [row col]))
(defn select-cells-by-row [row]
(filter (fn [[r c]] (= row r)) cells))
@timothypratley
timothypratley / GraphPeer
Created April 13, 2012 21:00
simple world server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;
using System.ComponentModel;
namespace PhotonGraphServer
@timothypratley
timothypratley / gist:2380150
Created April 13, 2012 20:57
simple world server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DigitalIdeaSolutions.Collections.Generic;
using Newtonsoft.Json;
using ExitGames.Client.Photon.Lite;
using ExitGames.Client.Photon;
using System.Collections;
using System.Threading;
@timothypratley
timothypratley / PolyhedronGeometry.js
Created January 1, 2012 05:33
polyhedrons for three.js
/**
* Polyhedrons which support subdivision.
*
* Vertices have 'smooth' normals,
* to make a sharp edge choose a material that uses face normals instead.
*
* @author [email protected]
* @author [email protected]
* @param radius
* @param detail Final number of triangles = 4^detail * X
;; This is intended to be entered interactively one part at a time
;; Try to keep state manipulation separate from logic functions
;; deal can just take a current game and return a new game.
;; thanks to persistent data structures, we aren't penalized for doing so.
(defn deal
[game n hand]
(update-in
(update-in game [hand] concat (take n (:deck game)))
[:deck]
;; Mike Erickson
(def cards (ref nil))
(defn build-test-deck
[]
[[8 \S] [2 \C] [6 \C] [8 \D] [6 \H] [\A \H] [8 \C] [7 \H] [\A
\C] [2 \D] [\K \H] [10 \D] [4 \H] [6 \S] [2 \H] [\Q \H] [3 \D] [10 \S]
[3 \S] [1 \S] [\A \D] [9 \H] [\J \S] [4 \D] [1 \C] [\K \D] [2 \S] [1
\H] [5 \C] [\K \C] [10 \H] [9 \D] [9 \C] [\J \D] [\Q \C] [7 \S] [7 \D]