Skip to content

Instantly share code, notes, and snippets.

View danprince's full-sized avatar

Dan Prince danprince

View GitHub Profile
@danprince
danprince / lein.log
Created January 6, 2016 08:50
CLJS Analysis Error
Figwheel: Starting server at http://localhost:3449
Figwheel: Watching build - dev
Compiling "resources/public/js/compiled/app.js" from ["src"]...
{:file #object[java.net.URL 0x60648aad "file:/home/dan/dev/org/danjoe/game/src/game/procedural/hero.cljs"], :line 1, :column 1, :tag :cljs/analysis-error}
ANALYSIS ERROR: at line 1 file:/home/dan/dev/org/danjoe/game/src/game/procedural/hero.cljs on file file:/home/dan/dev/org/danjoe/game/src/game/procedural/hero.cljs, line 1, column 1
Subprocess failed
clojure.lang.ExceptionInfo: Error in component :figwheel-system in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :figwheel-system, :component #figwheel_sidecar.system.FigwheelSystem{:system #object[clojure.lang.Atom 0x3191ba8b {:status :ready, :val #<SystemMap>}]}, :system #<SystemMap>}
at clojure.core$ex_info.invoke(core.clj:4593)
at com.st
@danprince
danprince / game.cljs
Created December 27, 2015 16:22
Game Loop Concept
(defn make-canvas [width height]
(let [canvas (.createElement js/document "canvas")
context (.getContext canvas "2d")]
(set! (.-width canvas) width)
(set! (.-height canvas) height)
{:canvas canvas
:context context}))
(defn set-key [key-state pressed? event]
(swap! key-state (.-which event) pressed?))
@danprince
danprince / counter.cljs
Last active December 27, 2015 04:28
Clojurescript Atomic Counter
(def counter (atom 0))
(def btn-inc (.createElement js/document "button"))
(def btn-dec (.createElement js/document "button"))
(def count-now (.createElement js/document "span"))
(set! (.-innerText btn-inc) "+"))
(set! (.-innerText btn-dec) "-"))
(defn init! []
@danprince
danprince / sandbox.js
Last active April 3, 2024 19:35
Sandbox for Code Evaluation
var app = {};
// go through the application and find every single instance of a div
// with the class of 'sandbox'
app.bootstrap = function() {
var sandboxes = document.getElementsByClassName('sandbox');
// for each sandbox, run the createSandbox function
[].forEach.call(sandboxes, app.createSandbox);
};
@danprince
danprince / fib.js
Created September 1, 2015 10:15
Memoized Fibonnaci
function fib(x) {
fib.memo = fib.memo || {};
if(x <= 0) return 1;
return fib.memo[x] ||
(fix.memo[x] = fib(x - 1) + fib(x - 2);
}
@danprince
danprince / index.html
Last active August 29, 2015 14:25
Tile Memory Test
<!DOCTYPE html>
<html>
<head>
<!-- Object Format Tests -->
<script src='tiles.js'></script>
<!-- Binary Format Tests -->
<!--<script src='tiles-binary.js'></script>-->
</head>
<body>
</body>
@danprince
danprince / highlight.js
Created July 10, 2015 23:48
File for testing out syntax highlighting
import Component from './component';
import { curry, compose } from 'functional';
const map = (collection, func) => {
let mappedCollection = new Array(collection.length);
collection.forEach((item, index) => {
mappedCollection[index] = func.apply(null, arguments);
});
@danprince
danprince / mapshift.js
Last active August 29, 2015 14:21
MapShift Pipes
// javascript has no special syntax for value pipes or function composition.
var input = 250;
halve(triple(double(input)));
// :(
// you can often do it with a functional utility library.
// it'll look something like this:
[
{
"name": "Top Level Category Name",
"icon": "Top level icon",
"children": [
{
"name": "Sub category name",
"icon": "sub category icon",
"cards": [
// ... cards for this category here
#1 > #2
< @A > @B +A,B,C
> #C